mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
137 lines
3.8 KiB
C++
137 lines
3.8 KiB
C++
#ifndef SPROUT_LIBS_ALGORITHM_TEST_NEXT_PERMUTATION_CPP
|
|
#define SPROUT_LIBS_ALGORITHM_TEST_NEXT_PERMUTATION_CPP
|
|
|
|
#include <sprout/algorithm/next_permutation.hpp>
|
|
#include <sprout/array.hpp>
|
|
#include <sprout/sub_array.hpp>
|
|
#include <sprout/container.hpp>
|
|
#include <testspr/tools.hpp>
|
|
|
|
namespace testspr {
|
|
static void algorithm_next_permutation_test() {
|
|
using namespace sprout;
|
|
{
|
|
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{1, 2, 3, 4, 5}};
|
|
|
|
// 順列
|
|
{
|
|
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
|
arr1
|
|
);
|
|
TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
permutation.first,
|
|
array<int, 5>{{1, 2, 3, 5, 4}}
|
|
));
|
|
TESTSPR_BOTH_ASSERT(permutation.second);
|
|
}
|
|
{
|
|
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
|
arr1
|
|
);
|
|
TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
permutation.first,
|
|
array<int, 5>{{1, 2, 3, 5, 4}}
|
|
));
|
|
TESTSPR_BOTH_ASSERT(permutation.second);
|
|
}
|
|
// 順列
|
|
// 範囲の切り出し
|
|
// !!!
|
|
// {
|
|
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
|
// sprout::sub(arr1, 2, 4)
|
|
// );
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// permutation.first,
|
|
// array<int, 3>{{2, 4, 3}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// sprout::get_internal(permutation.first),
|
|
// array<int, 5>{{1, 2, 4, 3, 5}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(permutation.second);
|
|
// }
|
|
// {
|
|
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
|
// sprout::sub(arr1, 2, 4)
|
|
// );
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// permutation.first,
|
|
// array<int, 3>{{2, 4, 3}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// sprout::get_internal(permutation.first),
|
|
// array<int, 5>{{1, 2, 4, 3, 5}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(permutation.second);
|
|
// }
|
|
}
|
|
{
|
|
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{1, 2, 3, 4, 5}};
|
|
|
|
// 順列
|
|
{
|
|
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
|
arr1,
|
|
testspr::less<int>()
|
|
);
|
|
TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
permutation.first,
|
|
array<int, 5>{{1, 2, 3, 5, 4}}
|
|
));
|
|
TESTSPR_BOTH_ASSERT(permutation.second);
|
|
}
|
|
{
|
|
SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
|
arr1,
|
|
testspr::less<int>()
|
|
);
|
|
TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
permutation.first,
|
|
array<int, 5>{{1, 2, 3, 5, 4}}
|
|
));
|
|
TESTSPR_BOTH_ASSERT(permutation.second);
|
|
}
|
|
// 順列
|
|
// 範囲の切り出し
|
|
// !!!
|
|
// {
|
|
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::next_permutation(
|
|
// sprout::sub(arr1, 2, 4),
|
|
// testspr::less<int>()
|
|
// );
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// permutation.first,
|
|
// array<int, 3>{{2, 4, 3}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// sprout::get_internal(permutation.first),
|
|
// array<int, 5>{{1, 2, 4, 3, 5}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(permutation.second);
|
|
// }
|
|
// {
|
|
// SPROUT_STATIC_CONSTEXPR auto permutation = sprout::fit::next_permutation(
|
|
// sprout::sub(arr1, 2, 4),
|
|
// testspr::less<int>()
|
|
// );
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// permutation.first,
|
|
// array<int, 3>{{2, 4, 3}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(testspr::equal(
|
|
// sprout::get_internal(permutation.first),
|
|
// array<int, 5>{{1, 2, 4, 3, 5}}
|
|
// ));
|
|
// TESTSPR_BOTH_ASSERT(permutation.second);
|
|
// }
|
|
}
|
|
}
|
|
} // namespace testspr
|
|
|
|
#ifndef TESTSPR_CPP_INCLUDE
|
|
# define TESTSPR_TEST_FUNCTION testspr::algorithm_next_permutation_test
|
|
# include <testspr/include_main.hpp>
|
|
#endif
|
|
|
|
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_NEXT_PERMUTATION_CPP
|