diff --git a/testspr/print.hpp b/testspr/print.hpp new file mode 100644 index 00000000..998f3f3a --- /dev/null +++ b/testspr/print.hpp @@ -0,0 +1,31 @@ +#ifndef TESTSPR_PRINT_HPP +#define TESTSPR_PRINT_HPP + +#include +#include +#include +#include + +namespace testspr { + // + // print + // + template + void print(Iterator first, Iterator last) { + std::for_each(first, last, [](typename std::iterator_traits::value_type const& e){ std::cout << e << ' '; }); + std::cout << std::endl; + } + template + void print(Range const& range) { + print(sprout::begin(range), sprout::end(range)); + } + + // + // print_hl + // + void print_hl() { + std::cout << "--------------------------------------------------------------------------------" << std::endl; + } +} // namespace testspr + +#endif // #ifndef TESTSPR_PRINT_HPP diff --git a/testspr/sprout.cpp b/testspr/sprout.cpp new file mode 100644 index 00000000..548c006e --- /dev/null +++ b/testspr/sprout.cpp @@ -0,0 +1,9 @@ +#define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION + +#include +#include + +int main() { + testspr::sprout_test(); + std::cout << "testspr succeeded." << std::endl; +} diff --git a/testspr/sprout.hpp b/testspr/sprout.hpp new file mode 100644 index 00000000..db83393a --- /dev/null +++ b/testspr/sprout.hpp @@ -0,0 +1,18 @@ +#ifndef TESTSPR_SPROUT_HPP +#define TESTSPR_SPROUT_HPP + +#include +#include +#include +#include + +namespace testspr { + static void sprout_test() { + testspr::array_test(); + testspr::string_test(); + testspr::algorithm_test(); + testspr::random_test(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_HPP diff --git a/testspr/sprout/algorithm.hpp b/testspr/sprout/algorithm.hpp new file mode 100644 index 00000000..56e48d34 --- /dev/null +++ b/testspr/sprout/algorithm.hpp @@ -0,0 +1,107 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_HPP +#define TESTSPR_SPROUT_ALGORITHM_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_test() { + testspr::algorithm_copy_test(); + testspr::algorithm_copy_n_test(); + testspr::algorithm_copy_if_test(); + testspr::algorithm_copy_backward_test(); + testspr::algorithm_transform_test(); + testspr::algorithm_replace_test(); + testspr::algorithm_replace_if_test(); + testspr::algorithm_replace_copy_test(); + testspr::algorithm_replace_copy_if_test(); + testspr::algorithm_fill_test(); + testspr::algorithm_fill_n_test(); + testspr::algorithm_generate_test(); + testspr::algorithm_generate_n_test(); + testspr::algorithm_remove_test(); + testspr::algorithm_remove_if_test(); + testspr::algorithm_remove_copy_test(); + testspr::algorithm_remove_copy_if_test(); + testspr::algorithm_unique_test(); + testspr::algorithm_unique_copy_test(); + testspr::algorithm_reverse_test(); + testspr::algorithm_reverse_copy_test(); + testspr::algorithm_rotate_test(); + testspr::algorithm_rotate_copy_test(); + testspr::algorithm_shuffle_test(); + testspr::algorithm_shuffle_result_test(); + testspr::algorithm_partition_test(); + testspr::algorithm_partition_copy_test(); + testspr::algorithm_stable_partition_test(); + testspr::algorithm_stable_partition_copy_test(); + testspr::algorithm_sort_test(); + testspr::algorithm_stable_sort_test(); + testspr::algorithm_partial_sort_test(); + testspr::algorithm_nth_element_test(); + testspr::algorithm_merge_test(); + testspr::algorithm_inplace_merge_test(); + testspr::algorithm_set_union_test(); + testspr::algorithm_set_intersection_test(); + testspr::algorithm_set_difference_test(); + testspr::algorithm_set_symmetric_difference_test(); + testspr::algorithm_push_heap_test(); + testspr::algorithm_pop_heap_test(); + testspr::algorithm_make_heap_test(); + testspr::algorithm_make_partial_heap_test(); + testspr::algorithm_sort_heap_test(); + testspr::algorithm_swap_element_test(); + testspr::algorithm_swap_element_copy_test(); + testspr::algorithm_bogo_sort_test(); + testspr::algorithm_bogo_sort_result_test(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_HPP + diff --git a/testspr/sprout/algorithm/bogo_sort.hpp b/testspr/sprout/algorithm/bogo_sort.hpp new file mode 100644 index 00000000..2b754744 --- /dev/null +++ b/testspr/sprout/algorithm/bogo_sort.hpp @@ -0,0 +1,133 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_HPP +#define TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_bogo_sort_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 4, 2, 3}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort( + arr1, + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort( + arr1, + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort( + sprout::sub(arr1, 1, 4), + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 4, 3}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort( + sprout::sub(arr1, 1, 4), + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 4, 3}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 4, 2, 3}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort( + arr1, + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort( + arr1, + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort( + sprout::sub(arr1, 1, 4), + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 4, 3}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort( + sprout::sub(arr1, 1, 4), + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 4, 3}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_HPP + diff --git a/testspr/sprout/algorithm/bogo_sort_result.hpp b/testspr/sprout/algorithm/bogo_sort_result.hpp new file mode 100644 index 00000000..4a00de7b --- /dev/null +++ b/testspr/sprout/algorithm/bogo_sort_result.hpp @@ -0,0 +1,175 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_RESULT_HPP +#define TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_RESULT_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_bogo_sort_result_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 4, 2, 3}}; + SPROUT_STATIC_CONSTEXPR auto g = sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED); + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort_result( + arr1, + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 3, 4, 5}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort_result( + arr1, + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 3, 4, 5}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort_result( + sprout::sub(arr1, 1, 4), + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sprout::get<0>(sorted)), + array{{5, 1, 2, 4, 3}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort_result( + sprout::sub(arr1, 1, 4), + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sprout::get<0>(sorted)), + array{{5, 1, 2, 4, 3}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 4, 2, 3}}; + SPROUT_STATIC_CONSTEXPR auto g = sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED); + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort_result( + arr1, + g, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 3, 4, 5}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort_result( + arr1, + g, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 3, 4, 5}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort_result( + sprout::sub(arr1, 1, 4), + g, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sprout::get<0>(sorted)), + array{{5, 1, 2, 4, 3}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort_result( + sprout::sub(arr1, 1, 4), + g, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get<0>(sorted), + array{{1, 2, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sprout::get<0>(sorted)), + array{{5, 1, 2, 4, 3}} + )); + SPROUT_STATIC_CONSTEXPR auto sorted2 = sprout::bogo_sort_result( + sprout::get<0>(sorted), + sprout::get<1>(sorted) + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(sorted) == sprout::get<1>(sorted2)); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_RESULT_HPP + diff --git a/testspr/sprout/algorithm/copy.hpp b/testspr/sprout/algorithm/copy.hpp new file mode 100644 index 00000000..2693b877 --- /dev/null +++ b/testspr/sprout/algorithm/copy.hpp @@ -0,0 +1,102 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲をコピー + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + } + // [2 .. 8) の範囲をコピー + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6}} + )); + } + // [2 .. 8) の範囲をコピー + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_HPP + diff --git a/testspr/sprout/algorithm/copy_backward.hpp b/testspr/sprout/algorithm/copy_backward.hpp new file mode 100644 index 00000000..cdaf2bef --- /dev/null +++ b/testspr/sprout/algorithm/copy_backward.hpp @@ -0,0 +1,102 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_BACKWARD_HPP +#define TESTSPR_SPROUT_ALGORITHM_COPY_BACKWARD_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_copy_backward_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲をコピー + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_backward( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{0, 0, 0, 0, 3, 4, 5, 6, 7, 8}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_backward( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + } + // [2 .. 8) の範囲をコピー + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_backward( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{5, 6, 7, 8}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_backward( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{5, 6, 7, 8}} + )); + } + // [2 .. 8) の範囲をコピー + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_backward( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_backward( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_BACKWARD_HPP + diff --git a/testspr/sprout/algorithm/copy_if.hpp b/testspr/sprout/algorithm/copy_if.hpp new file mode 100644 index 00000000..08fad8fd --- /dev/null +++ b/testspr/sprout/algorithm/copy_if.hpp @@ -0,0 +1,108 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_IF_HPP +#define TESTSPR_SPROUT_ALGORITHM_COPY_IF_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_copy_if_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 奇数をコピー + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_if( + sprout::begin(arr1), + sprout::end(arr1), + arr2, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{1, 3, 5, 7, 9, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_if( + sprout::begin(arr1), + sprout::end(arr1), + arr2, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{1, 3, 5, 7, 9}} + )); + } + // 奇数をコピー + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_if( + sprout::begin(arr1), + sprout::end(arr1), + arr3, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{1, 3, 5, 7}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_if( + sprout::begin(arr1), + sprout::end(arr1), + arr3, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{1, 3, 5, 7}} + )); + } + // 奇数をコピー + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_if( + sprout::begin(arr1), + sprout::end(arr1), + sprout::sub(arr2, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{1, 3, 5, 7, 9, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 1, 3, 5, 7, 9, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_if( + sprout::begin(arr1), + sprout::end(arr1), + sprout::sub(arr2, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{1, 3, 5, 7, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 1, 3, 5, 7, 9, 0, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_IF_HPP + diff --git a/testspr/sprout/algorithm/copy_n.hpp b/testspr/sprout/algorithm/copy_n.hpp new file mode 100644 index 00000000..54047c52 --- /dev/null +++ b/testspr/sprout/algorithm/copy_n.hpp @@ -0,0 +1,102 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_N_HPP +#define TESTSPR_SPROUT_ALGORITHM_COPY_N_HPP + +#include +#include +#include +#include + +namespace testspr { + static void algorithm_copy_n_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 6 要素をコピー + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_n( + sprout::begin(arr1) + 2, + 6, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_n( + sprout::begin(arr1) + 2, + 6, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + } + + // 6 要素をコピー + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_n( + sprout::begin(arr1) + 2, + 6, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_n( + sprout::begin(arr1) + 2, + 6, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6}} + )); + } + // 6 要素をコピー + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_n( + sprout::begin(arr1) + 2, + 6, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_n( + sprout::begin(arr1) + 2, + 6, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + copied, + array{{3, 4, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(copied), + array{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_N_HPP + diff --git a/testspr/sprout/algorithm/fill.hpp b/testspr/sprout/algorithm/fill.hpp new file mode 100644 index 00000000..bd2dda25 --- /dev/null +++ b/testspr/sprout/algorithm/fill.hpp @@ -0,0 +1,72 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_FILL_HPP +#define TESTSPR_SPROUT_ALGORITHM_FILL_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_fill_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // 充填 (-1) + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fill( + arr1, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fit::fill( + arr1, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}} + )); + } + // 充填 (-1) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fill( + sprout::sub(arr1, 2, 8), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1, -1, -1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(filled), + array{{1, 2, -1, -1, -1, -1, -1, -1, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fit::fill( + sprout::sub(arr1, 2, 8), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1, -1, -1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(filled), + array{{1, 2, -1, -1, -1, -1, -1, -1, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_FILL_HPP + diff --git a/testspr/sprout/algorithm/fill_n.hpp b/testspr/sprout/algorithm/fill_n.hpp new file mode 100644 index 00000000..12b1c1c1 --- /dev/null +++ b/testspr/sprout/algorithm/fill_n.hpp @@ -0,0 +1,76 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_FILL_N_HPP +#define TESTSPR_SPROUT_ALGORITHM_FILL_N_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_fill_n_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // 充填 (-1) + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fill_n( + arr1, + 4, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fit::fill_n( + arr1, + 4, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1}} + )); + } + // 充填 (-1) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fill_n( + sprout::sub(arr1, 2, 8), + 4, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(filled), + array{{1, 2, -1, -1, -1, -1, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto filled = sprout::fit::fill_n( + sprout::sub(arr1, 2, 8), + 4, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + filled, + array{{-1, -1, -1, -1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(filled), + array{{1, 2, -1, -1, -1, -1, 7, 8, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_FILL_N_HPP + diff --git a/testspr/sprout/algorithm/generate.hpp b/testspr/sprout/algorithm/generate.hpp new file mode 100644 index 00000000..645a0248 --- /dev/null +++ b/testspr/sprout/algorithm/generate.hpp @@ -0,0 +1,76 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_HPP +#define TESTSPR_SPROUT_ALGORITHM_GENERATE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_generate_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // 生成 + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate( + arr1, + testspr::x2(), + 2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate( + arr1, + testspr::x2(), + 2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}} + )); + } + // 生成 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate( + sprout::sub(arr1, 2, 8), + testspr::x2(), + 2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{2, 4, 8, 16, 32, 64}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(generated), + array{{1, 2, 2, 4, 8, 16, 32, 64, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate( + sprout::sub(arr1, 2, 8), + testspr::x2(), + 2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{2, 4, 8, 16, 32, 64}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(generated), + array{{1, 2, 2, 4, 8, 16, 32, 64, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_HPP + diff --git a/testspr/sprout/algorithm/generate_n.hpp b/testspr/sprout/algorithm/generate_n.hpp new file mode 100644 index 00000000..178e4dbe --- /dev/null +++ b/testspr/sprout/algorithm/generate_n.hpp @@ -0,0 +1,80 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_N_HPP +#define TESTSPR_SPROUT_ALGORITHM_GENERATE_N_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_generate_n_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // 生成 + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate_n( + arr1, + 4, + testspr::x2(), + 1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{1, 2, 4, 8, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate_n( + arr1, + 4, + testspr::x2(), + 1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{1, 2, 4, 8}} + )); + } + // 生成 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate_n( + sprout::sub(arr1, 2, 8), + 4, + testspr::x2(), + 1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{1, 2, 4, 8, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(generated), + array{{1, 2, 1, 2, 4, 8, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate_n( + sprout::sub(arr1, 2, 8), + 4, + testspr::x2(), + 1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + generated, + array{{1, 2, 4, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(generated), + array{{1, 2, 1, 2, 4, 8, 7, 8, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_N_HPP + diff --git a/testspr/sprout/algorithm/inplace_merge.hpp b/testspr/sprout/algorithm/inplace_merge.hpp new file mode 100644 index 00000000..1e2af89a --- /dev/null +++ b/testspr/sprout/algorithm/inplace_merge.hpp @@ -0,0 +1,131 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_INPLACE_MERGE_HPP +#define TESTSPR_SPROUT_ALGORITHM_INPLACE_MERGE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_inplace_merge_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 3, 5, 7, 9, 2, 4, 6, 8, 10}}; + + // マージ + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::inplace_merge( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::inplace_merge( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + // マージ + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::inplace_merge( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 4, 5, 6, 7, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{1, 3, 2, 4, 5, 6, 7, 9, 8, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::inplace_merge( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 4, 5, 6, 7, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{1, 3, 2, 4, 5, 6, 7, 9, 8, 10}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 3, 5, 7, 9, 2, 4, 6, 8, 10}}; + + // マージ + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::inplace_merge( + arr1, + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::inplace_merge( + arr1, + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + // マージ + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::inplace_merge( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 4, 5, 6, 7, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{1, 3, 2, 4, 5, 6, 7, 9, 8, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::inplace_merge( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 4, 5, 6, 7, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{1, 3, 2, 4, 5, 6, 7, 9, 8, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_INPLACE_MERGE_HPP + diff --git a/testspr/sprout/algorithm/make_heap.hpp b/testspr/sprout/algorithm/make_heap.hpp new file mode 100644 index 00000000..79f91785 --- /dev/null +++ b/testspr/sprout/algorithm/make_heap.hpp @@ -0,0 +1,123 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_HEAP_HPP +#define TESTSPR_SPROUT_ALGORITHM_MAKE_HEAP_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_make_heap_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; + + // ヒープ作成 + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}} + )); + } + // ヒープ作成 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_heap( + sprout::sub(arr1, 2, 10) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 6, 8, 2, 5, 3, 4, 1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 9, 6, 8, 2, 5, 3, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_heap( + sprout::sub(arr1, 2, 10) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 6, 8, 2, 5, 3, 4, 1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 9, 6, 8, 2, 5, 3, 4, 1}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; + + // ヒープ作成 + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_heap( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_heap( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}} + )); + } + // ヒープ作成 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_heap( + sprout::sub(arr1, 2, 10), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 6, 8, 2, 5, 3, 4, 1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 9, 6, 8, 2, 5, 3, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_heap( + sprout::sub(arr1, 2, 10), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 6, 8, 2, 5, 3, 4, 1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 9, 6, 8, 2, 5, 3, 4, 1}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_HEAP_HPP + diff --git a/testspr/sprout/algorithm/make_partial_heap.hpp b/testspr/sprout/algorithm/make_partial_heap.hpp new file mode 100644 index 00000000..0f3ee4b3 --- /dev/null +++ b/testspr/sprout/algorithm/make_partial_heap.hpp @@ -0,0 +1,131 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_PARTIAL_HEAP_HPP +#define TESTSPR_SPROUT_ALGORITHM_MAKE_PARTIAL_HEAP_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_make_partial_heap_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; + + // ヒープ作成 + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_partial_heap( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{5, 4, 1, 3, 2, 10, 9, 8, 7, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_partial_heap( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{5, 4, 1, 3, 2}} + )); + } + // ヒープ作成 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_partial_heap( + sprout::sub(arr1, 2, 10), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{3, 1, 2, 9, 8, 6, 5, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 3, 1, 2, 9, 8, 6, 5, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_partial_heap( + sprout::sub(arr1, 2, 10), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{3, 1, 2}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 3, 1, 2, 9, 8, 6, 5, 4}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; + + // ヒープ作成 + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_partial_heap( + arr1, + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{5, 4, 1, 3, 2, 10, 9, 8, 7, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_partial_heap( + arr1, + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{5, 4, 1, 3, 2}} + )); + } + // ヒープ作成 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_partial_heap( + sprout::sub(arr1, 2, 10), + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{3, 1, 2, 9, 8, 6, 5, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 3, 1, 2, 9, 8, 6, 5, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_partial_heap( + sprout::sub(arr1, 2, 10), + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{3, 1, 2}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 7, 3, 1, 2, 9, 8, 6, 5, 4}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_PARTIAL_HEAP_HPP + diff --git a/testspr/sprout/algorithm/merge.hpp b/testspr/sprout/algorithm/merge.hpp new file mode 100644 index 00000000..c176cccb --- /dev/null +++ b/testspr/sprout/algorithm/merge.hpp @@ -0,0 +1,219 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_MERGE_HPP +#define TESTSPR_SPROUT_ALGORITHM_MERGE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_merge_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{3, 5, 7, 9}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{2, 4, 6, 8}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // マージ + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7, 8, 9, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7, 8, 9}} + )); + } + // マージ + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5}} + )); + } + // マージ + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 2, 3, 4, 5, 6, 7, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 2, 3, 4, 5, 6, 7, 0, 0}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{3, 5, 7, 9}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{2, 4, 6, 8}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // マージ + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7, 8, 9, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7, 8, 9}} + )); + } + // マージ + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5}} + )); + } + // マージ + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 2, 3, 4, 5, 6, 7, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::merge( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{2, 3, 4, 5, 6, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 2, 3, 4, 5, 6, 7, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MERGE_HPP + diff --git a/testspr/sprout/algorithm/nth_element.hpp b/testspr/sprout/algorithm/nth_element.hpp new file mode 100644 index 00000000..e35185e8 --- /dev/null +++ b/testspr/sprout/algorithm/nth_element.hpp @@ -0,0 +1,131 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP +#define TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_nth_element_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( + arr1, + sprout::begin(arr1) + 4 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 4, 1, 3, 5, 10, 9, 8, 7, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( + arr1, + sprout::begin(arr1) + 4 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 4, 1, 3, 5}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 4 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 3, 5, 9, 8, 6}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(nth), + array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 4 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 3, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(nth), + array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( + arr1, + sprout::begin(arr1) + 4, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 4, 1, 3, 5, 10, 9, 8, 7, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( + arr1, + sprout::begin(arr1) + 4, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 4, 1, 3, 5}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 4, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 3, 5, 9, 8, 6}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(nth), + array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 4, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + nth, + array{{2, 3, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(nth), + array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP + diff --git a/testspr/sprout/algorithm/partial_sort.hpp b/testspr/sprout/algorithm/partial_sort.hpp new file mode 100644 index 00000000..d5cffcf5 --- /dev/null +++ b/testspr/sprout/algorithm/partial_sort.hpp @@ -0,0 +1,131 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_PARTIAL_SORT_HPP +#define TESTSPR_SPROUT_ALGORITHM_PARTIAL_SORT_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_partial_sort_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::partial_sort( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 9, 8, 7, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::partial_sort( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::partial_sort( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 9, 8, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 9, 8, 7, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::partial_sort( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 9, 8, 7, 10, 6}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::partial_sort( + arr1, + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 9, 8, 7, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::partial_sort( + arr1, + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::partial_sort( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 9, 8, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 9, 8, 7, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::partial_sort( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 9, 8, 7, 10, 6}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PARTIAL_SORT_HPP + diff --git a/testspr/sprout/algorithm/partition.hpp b/testspr/sprout/algorithm/partition.hpp new file mode 100644 index 00000000..aecca9bd --- /dev/null +++ b/testspr/sprout/algorithm/partition.hpp @@ -0,0 +1,72 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_HPP +#define TESTSPR_SPROUT_ALGORITHM_PARTITION_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_partition_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // パーティション (is_odd) + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition( + arr1, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{9, 7, 5, 3, 1, 2, 4, 6, 8, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::partition( + arr1, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{9, 7, 5, 3, 1}} + )); + } + // パーティション (is_odd) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition( + sprout::sub(arr1, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{7, 5, 3, 4, 6, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{1, 2, 7, 5, 3, 4, 6, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::partition( + sprout::sub(arr1, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{7, 5, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{1, 2, 7, 5, 3, 4, 6, 8, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_HPP + diff --git a/testspr/sprout/algorithm/partition_copy.hpp b/testspr/sprout/algorithm/partition_copy.hpp new file mode 100644 index 00000000..0d53946f --- /dev/null +++ b/testspr/sprout/algorithm/partition_copy.hpp @@ -0,0 +1,108 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_PARTITION_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_partition_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲をパーティション (is_odd) + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{7, 5, 3, 4, 6, 8, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{7, 5, 3}} + )); + } + // [2 .. 8) の範囲をパーティション (is_odd) + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{5, 3, 4, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{5, 3}} + )); + } + // [2 .. 8) の範囲をパーティション (is_odd) + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{7, 5, 3, 4, 6, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{0, 0, 7, 5, 3, 4, 6, 8, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{7, 5, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{0, 0, 7, 5, 3, 4, 6, 8, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_COPY_HPP + diff --git a/testspr/sprout/algorithm/pop_heap.hpp b/testspr/sprout/algorithm/pop_heap.hpp new file mode 100644 index 00000000..a01739b8 --- /dev/null +++ b/testspr/sprout/algorithm/pop_heap.hpp @@ -0,0 +1,68 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_POP_HEAP_HPP +#define TESTSPR_SPROUT_ALGORITHM_POP_HEAP_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_pop_heap_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 8, 9, 6, 7, 5, 3, 1, 2, 4}}; + + // ヒープからポップ + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::pop_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 8, 5, 6, 7, 4, 3, 1, 2, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::pop_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 8, 5, 6, 7, 4, 3, 1, 2}} + )); + } + // ヒープからポップ + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::pop_heap( + sprout::sub(arr1, 2, 10) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{7, 6, 4, 5, 3, 1, 2, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 8, 7, 6, 4, 5, 3, 1, 2, 9}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::pop_heap( + sprout::sub(arr1, 2, 10) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{7, 6, 4, 5, 3, 1, 2}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 8, 7, 6, 4, 5, 3, 1, 2, 9}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_POP_HEAP_HPP + diff --git a/testspr/sprout/algorithm/push_heap.hpp b/testspr/sprout/algorithm/push_heap.hpp new file mode 100644 index 00000000..5d20b257 --- /dev/null +++ b/testspr/sprout/algorithm/push_heap.hpp @@ -0,0 +1,123 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_PUSH_HEAP_HPP +#define TESTSPR_SPROUT_ALGORITHM_PUSH_HEAP_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_push_heap_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 8, 9, 6, 4, 5, 3, 1, 2, 7}}; + + // ヒープにプッシュ + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::push_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 8, 9, 6, 7, 5, 3, 1, 2, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::push_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 8, 9, 6, 7, 5, 3, 1, 2, 4}} + )); + } + // ヒープにプッシュ + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::push_heap( + sprout::sub(arr1, 2, 10) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 7, 4, 6, 3, 1, 2, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 8, 9, 7, 4, 6, 3, 1, 2, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::push_heap( + sprout::sub(arr1, 2, 10) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 7, 4, 6, 3, 1, 2, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 8, 9, 7, 4, 6, 3, 1, 2, 5}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 8, 9, 6, 4, 5, 3, 1, 2, 7}}; + + // ヒープにプッシュ + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::push_heap( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 8, 9, 6, 7, 5, 3, 1, 2, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::push_heap( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{10, 8, 9, 6, 7, 5, 3, 1, 2, 4}} + )); + } + // ヒープにプッシュ + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::push_heap( + sprout::sub(arr1, 2, 10), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 7, 4, 6, 3, 1, 2, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 8, 9, 7, 4, 6, 3, 1, 2, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::push_heap( + sprout::sub(arr1, 2, 10), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + heap, + array{{9, 7, 4, 6, 3, 1, 2, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(heap), + array{{10, 8, 9, 7, 4, 6, 3, 1, 2, 5}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PUSH_HEAP_HPP + diff --git a/testspr/sprout/algorithm/remove.hpp b/testspr/sprout/algorithm/remove.hpp new file mode 100644 index 00000000..4e97210c --- /dev/null +++ b/testspr/sprout/algorithm/remove.hpp @@ -0,0 +1,72 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_HPP +#define TESTSPR_SPROUT_ALGORITHM_REMOVE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_remove_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + + // 削除 (0) + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove( + arr1, + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{1, 3, 5, 7, 9, 0, 7, 0, 9, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove( + arr1, + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{1, 3, 5, 7, 9}} + )); + } + // 削除 (0) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove( + sprout::sub(arr1, 2, 8), + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5, 7, 0, 7, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{1, 0, 3, 5, 7, 0, 7, 0, 9, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove( + sprout::sub(arr1, 2, 8), + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{1, 0, 3, 5, 7, 0, 7, 0, 9, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_HPP + diff --git a/testspr/sprout/algorithm/remove_copy.hpp b/testspr/sprout/algorithm/remove_copy.hpp new file mode 100644 index 00000000..de73e969 --- /dev/null +++ b/testspr/sprout/algorithm/remove_copy.hpp @@ -0,0 +1,108 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_remove_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を削除 (0) + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5, 7, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5, 7}} + )); + } + // [2 .. 8) の範囲を削除 (0) + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5}} + )); + } + // [2 .. 8) の範囲を削除 (0) + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5, 7, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + 0 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_HPP + diff --git a/testspr/sprout/algorithm/remove_copy_if.hpp b/testspr/sprout/algorithm/remove_copy_if.hpp new file mode 100644 index 00000000..bdcec26e --- /dev/null +++ b/testspr/sprout/algorithm/remove_copy_if.hpp @@ -0,0 +1,108 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_IF_HPP +#define TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_IF_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_remove_copy_if_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を削除 (is_odd) + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0}} + )); + } + // [2 .. 8) の範囲を削除 (is_odd) + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0}} + )); + } + // [2 .. 8) の範囲を削除 (is_odd) + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_IF_HPP + diff --git a/testspr/sprout/algorithm/remove_if.hpp b/testspr/sprout/algorithm/remove_if.hpp new file mode 100644 index 00000000..0a736ac2 --- /dev/null +++ b/testspr/sprout/algorithm/remove_if.hpp @@ -0,0 +1,72 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_IF_HPP +#define TESTSPR_SPROUT_ALGORITHM_REMOVE_IF_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_remove_if_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + + // 削除 (is_odd) + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_if( + arr1, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0, 0, 0, 0, 7, 0, 9, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_if( + arr1, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0, 0, 0}} + )); + } + // 削除 (is_odd) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_if( + sprout::sub(arr1, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0, 0, 7, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{1, 0, 0, 0, 0, 0, 7, 0, 9, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_if( + sprout::sub(arr1, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + removed, + array{{0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(removed), + array{{1, 0, 0, 0, 0, 0, 7, 0, 9, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_IF_HPP + diff --git a/testspr/sprout/algorithm/replace.hpp b/testspr/sprout/algorithm/replace.hpp new file mode 100644 index 00000000..1935b10b --- /dev/null +++ b/testspr/sprout/algorithm/replace.hpp @@ -0,0 +1,76 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_HPP +#define TESTSPR_SPROUT_ALGORITHM_REPLACE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_replace_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + + // 置換 (0 -> -1) + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace( + arr1, + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{1, -1, 3, -1, 5, -1, 7, -1, 9, -1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace( + arr1, + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{1, -1, 3, -1, 5, -1, 7, -1, 9, -1}} + )); + } + // 置換 (0 -> -1) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace( + sprout::sub(arr1, 2, 8), + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1, 7, -1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{1, 0, 3, -1, 5, -1, 7, -1, 9, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace( + sprout::sub(arr1, 2, 8), + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1, 7, -1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{1, 0, 3, -1, 5, -1, 7, -1, 9, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_HPP + diff --git a/testspr/sprout/algorithm/replace_copy.hpp b/testspr/sprout/algorithm/replace_copy.hpp new file mode 100644 index 00000000..58f97e87 --- /dev/null +++ b/testspr/sprout/algorithm/replace_copy.hpp @@ -0,0 +1,114 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_replace_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を置換 (0 -> -1) + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1, 7, -1, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1, 7, -1}} + )); + } + // [2 .. 8) の範囲を置換 (0 -> -1) + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1}} + )); + } + // [2 .. 8) の範囲を置換 (0 -> -1) + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1, 7, -1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{0, 0, 3, -1, 5, -1, 7, -1, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + 0, + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{3, -1, 5, -1, 7, -1}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{0, 0, 3, -1, 5, -1, 7, -1, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_HPP + diff --git a/testspr/sprout/algorithm/replace_copy_if.hpp b/testspr/sprout/algorithm/replace_copy_if.hpp new file mode 100644 index 00000000..ec7350f3 --- /dev/null +++ b/testspr/sprout/algorithm/replace_copy_if.hpp @@ -0,0 +1,114 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_IF_HPP +#define TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_IF_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_replace_copy_if_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を置換 (is_odd -> -1) + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0}} + )); + } + // [2 .. 8) の範囲を置換 (is_odd -> -1) + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0}} + )); + } + // [2 .. 8) の範囲を置換 (is_odd -> -1) + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{0, 0, -1, 0, -1, 0, -1, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_copy_if( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{0, 0, -1, 0, -1, 0, -1, 0, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_IF_HPP + diff --git a/testspr/sprout/algorithm/replace_if.hpp b/testspr/sprout/algorithm/replace_if.hpp new file mode 100644 index 00000000..33685921 --- /dev/null +++ b/testspr/sprout/algorithm/replace_if.hpp @@ -0,0 +1,76 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_IF_HPP +#define TESTSPR_SPROUT_ALGORITHM_REPLACE_IF_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_replace_if_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}}; + + // 置換 (is_odd -> -1) + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_if( + arr1, + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0, -1, 0, -1, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_if( + arr1, + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0, -1, 0, -1, 0}} + )); + } + // 置換 (is_odd -> -1) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_if( + sprout::sub(arr1, 2, 8), + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{1, 0, -1, 0, -1, 0, -1, 0, 9, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_if( + sprout::sub(arr1, 2, 8), + is_odd(), + -1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + replaced, + array{{-1, 0, -1, 0, -1, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(replaced), + array{{1, 0, -1, 0, -1, 0, -1, 0, 9, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_IF_HPP + diff --git a/testspr/sprout/algorithm/reverse.hpp b/testspr/sprout/algorithm/reverse.hpp new file mode 100644 index 00000000..549eddbf --- /dev/null +++ b/testspr/sprout/algorithm/reverse.hpp @@ -0,0 +1,68 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_HPP +#define TESTSPR_SPROUT_ALGORITHM_REBERSE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_reverse_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // 反転 + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::reverse( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::fit::reverse( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}} + )); + } + // 反転 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::reverse( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5, 4, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(reversed), + array{{1, 2, 8, 7, 6, 5, 4, 3, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::fit::reverse( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5, 4, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(reversed), + array{{1, 2, 8, 7, 6, 5, 4, 3, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_HPP + diff --git a/testspr/sprout/algorithm/reverse_copy.hpp b/testspr/sprout/algorithm/reverse_copy.hpp new file mode 100644 index 00000000..ea5ff12d --- /dev/null +++ b/testspr/sprout/algorithm/reverse_copy.hpp @@ -0,0 +1,102 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_REBERSE_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_reverse_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を反転 + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::reverse_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5, 4, 3, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::fit::reverse_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5, 4, 3}} + )); + } + // [2 .. 8) の範囲を反転 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::reverse_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::fit::reverse_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5}} + )); + } + // [2 .. 8) の範囲を反転 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::reverse_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5, 4, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(reversed), + array{{0, 0, 8, 7, 6, 5, 4, 3, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto reversed = sprout::fit::reverse_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + reversed, + array{{8, 7, 6, 5, 4, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(reversed), + array{{0, 0, 8, 7, 6, 5, 4, 3, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_COPY_HPP + diff --git a/testspr/sprout/algorithm/rotate.hpp b/testspr/sprout/algorithm/rotate.hpp new file mode 100644 index 00000000..7e8f8b0a --- /dev/null +++ b/testspr/sprout/algorithm/rotate.hpp @@ -0,0 +1,72 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_HPP +#define TESTSPR_SPROUT_ALGORITHM_ROTATE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_rotate_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // 回転 + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate( + arr1, + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 9, 10, 1, 2, 3, 4, 5}} + )); + } + // 回転 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3, 4, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(rotated), + array{{1, 2, 6, 7, 8, 3, 4, 5, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 5 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3, 4, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(rotated), + array{{1, 2, 6, 7, 8, 3, 4, 5, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_HPP + diff --git a/testspr/sprout/algorithm/rotate_copy.hpp b/testspr/sprout/algorithm/rotate_copy.hpp new file mode 100644 index 00000000..ef502184 --- /dev/null +++ b/testspr/sprout/algorithm/rotate_copy.hpp @@ -0,0 +1,108 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_ROTATE_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_rotate_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を回転 + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 5, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3, 4, 5, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 5, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3, 4, 5}} + )); + } + // [2 .. 8) の範囲を回転 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 5, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 5, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3}} + )); + } + // [2 .. 8) の範囲を回転 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::rotate_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 5, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3, 4, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(rotated), + array{{0, 0, 6, 7, 8, 3, 4, 5, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto rotated = sprout::fit::rotate_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 5, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + rotated, + array{{6, 7, 8, 3, 4, 5}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(rotated), + array{{0, 0, 6, 7, 8, 3, 4, 5, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_COPY_HPP + diff --git a/testspr/sprout/algorithm/set_difference.hpp b/testspr/sprout/algorithm/set_difference.hpp new file mode 100644 index 00000000..fc4533e6 --- /dev/null +++ b/testspr/sprout/algorithm/set_difference.hpp @@ -0,0 +1,219 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SET_DIFFERENCE_HPP +#define TESTSPR_SPROUT_ALGORITHM_SET_DIFFERENCE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_set_difference_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 10, 15, 20, 25}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 論理差 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25}} + )); + } + // 論理差 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15}} + )); + } + // 論理差 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 0, 0, 0, 0, 0}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 10, 15, 20, 25}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 論理差 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25}} + )); + } + // 論理差 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15}} + )); + } + // 論理差 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 0, 0, 0, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_DIFFERENCE_HPP + diff --git a/testspr/sprout/algorithm/set_intersection.hpp b/testspr/sprout/algorithm/set_intersection.hpp new file mode 100644 index 00000000..72527700 --- /dev/null +++ b/testspr/sprout/algorithm/set_intersection.hpp @@ -0,0 +1,219 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SET_INTERSECTION_HPP +#define TESTSPR_SPROUT_ALGORITHM_SET_INTERSECTION_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_set_intersection_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{20, 25, 30, 35, 40}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 論理積 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40}} + )); + } + // 論理積 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30}} + )); + } + // 論理積 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 20, 30, 40, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 20, 30, 40, 0, 0, 0, 0, 0}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{20, 25, 30, 35, 40}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 論理積 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40}} + )); + } + // 論理積 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30}} + )); + } + // 論理積 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 20, 30, 40, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_intersection( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{20, 30, 40}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 20, 30, 40, 0, 0, 0, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_INTERSECTION_HPP + diff --git a/testspr/sprout/algorithm/set_symmetric_difference.hpp b/testspr/sprout/algorithm/set_symmetric_difference.hpp new file mode 100644 index 00000000..eefef3c4 --- /dev/null +++ b/testspr/sprout/algorithm/set_symmetric_difference.hpp @@ -0,0 +1,219 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP +#define TESTSPR_SPROUT_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_set_symmetric_difference_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 10, 15, 20, 25}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 排他的論理和 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50}} + )); + } + // 排他的論理和 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30}} + )); + } + // 排他的論理和 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 30, 40, 50, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 30, 40, 50, 0, 0}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 10, 15, 20, 25}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 排他的論理和 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50}} + )); + } + // 排他的論理和 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30}} + )); + } + // 排他的論理和 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 30, 40, 50, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_symmetric_difference( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 15, 25, 30, 40, 50}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 15, 25, 30, 40, 50, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP + diff --git a/testspr/sprout/algorithm/set_union.hpp b/testspr/sprout/algorithm/set_union.hpp new file mode 100644 index 00000000..bde7ce93 --- /dev/null +++ b/testspr/sprout/algorithm/set_union.hpp @@ -0,0 +1,219 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SET_UNION_HPP +#define TESTSPR_SPROUT_ALGORITHM_SET_UNION_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_set_union_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 10, 15, 20, 25}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 論理和 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30, 40, 50, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30, 40, 50}} + )); + } + // 論理和 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20}} + )); + } + // 論理和 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 10, 15, 20, 25, 30, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 10, 15, 20, 25, 30, 0, 0}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 10, 15, 20, 25}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{10, 20, 30, 40, 50}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // 論理和 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30, 40, 50, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr2, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30, 40, 50}} + )); + } + // 論理和 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + arr3, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20}} + )); + } + // 論理和 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 10, 15, 20, 25, 30, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto merged = sprout::fit::set_union( + sprout::begin(arr1), + sprout::end(arr1), + sprout::begin(arr1_2), + sprout::end(arr1_2), + sprout::sub(arr2, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + merged, + array{{5, 10, 15, 20, 25, 30}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(merged), + array{{0, 0, 5, 10, 15, 20, 25, 30, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_UNION_HPP + diff --git a/testspr/sprout/algorithm/shuffle.hpp b/testspr/sprout/algorithm/shuffle.hpp new file mode 100644 index 00000000..dca0028f --- /dev/null +++ b/testspr/sprout/algorithm/shuffle.hpp @@ -0,0 +1,74 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SHUFFLE_HPP +#define TESTSPR_SPROUT_ALGORITHM_SHUFFLE_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_shuffle_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // シャッフル + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::shuffle( + arr1, + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + shuffled, + arr1 + )); + } + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::fit::shuffle( + arr1, + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + shuffled, + arr1 + )); + } + // シャッフル + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::shuffle( + sprout::sub(arr1, 2, 8), + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + shuffled, + sprout::sub(arr1, 2, 8) + )); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get_fixed(shuffled), + arr1 + )); + } + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::fit::shuffle( + sprout::sub(arr1, 2, 8), + sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED) + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + shuffled, + sprout::sub(arr1, 2, 8) + )); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get_fixed(shuffled), + arr1 + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SHUFFLE_HPP + diff --git a/testspr/sprout/algorithm/shuffle_result.hpp b/testspr/sprout/algorithm/shuffle_result.hpp new file mode 100644 index 00000000..af03af64 --- /dev/null +++ b/testspr/sprout/algorithm/shuffle_result.hpp @@ -0,0 +1,95 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SHUFFLE_RESULT_HPP +#define TESTSPR_SPROUT_ALGORITHM_SHUFFLE_RESULT_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_shuffle_result_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto g = sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED); + + // シャッフル + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::shuffle_result( + arr1, + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get<0>(shuffled), + arr1 + )); + SPROUT_STATIC_CONSTEXPR auto shuffled2 = sprout::shuffle_result( + sprout::get<0>(shuffled), + g + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(shuffled) == sprout::get<1>(shuffled2)); + } + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::fit::shuffle_result( + arr1, + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get<0>(shuffled), + arr1 + )); + SPROUT_STATIC_CONSTEXPR auto shuffled2 = sprout::shuffle_result( + sprout::get<0>(shuffled), + g + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(shuffled) == sprout::get<1>(shuffled2)); + } + // シャッフル + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::shuffle_result( + sprout::sub(arr1, 2, 8), + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get<0>(shuffled), + sprout::sub(arr1, 2, 8) + )); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get_fixed(sprout::get<0>(shuffled)), + arr1 + )); + SPROUT_STATIC_CONSTEXPR auto shuffled2 = sprout::shuffle_result( + sprout::get<0>(shuffled), + g + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(shuffled) == sprout::get<1>(shuffled2)); + } + { + SPROUT_STATIC_CONSTEXPR auto shuffled = sprout::fit::shuffle_result( + sprout::sub(arr1, 2, 8), + g + ); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get<0>(shuffled), + sprout::sub(arr1, 2, 8) + )); + TESTSPR_DOUBLE_ASSERT(testspr::is_permutation( + sprout::get_fixed(sprout::get<0>(shuffled)), + arr1 + )); + SPROUT_STATIC_CONSTEXPR auto shuffled2 = sprout::shuffle_result( + sprout::get<0>(shuffled), + g + ); + TESTSPR_DOUBLE_ASSERT(sprout::get<1>(shuffled) == sprout::get<1>(shuffled2)); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SHUFFLE_RESULT_HPP + diff --git a/testspr/sprout/algorithm/sort.hpp b/testspr/sprout/algorithm/sort.hpp new file mode 100644 index 00000000..afcfd635 --- /dev/null +++ b/testspr/sprout/algorithm/sort.hpp @@ -0,0 +1,123 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HPP +#define TESTSPR_SPROUT_ALGORITHM_SORT_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_sort_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 7, 8, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 7, 8, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort( + sprout::sub(arr1, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 7, 8, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort( + sprout::sub(arr1, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 7, 8, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HPP + diff --git a/testspr/sprout/algorithm/sort_heap.hpp b/testspr/sprout/algorithm/sort_heap.hpp new file mode 100644 index 00000000..01b5baaa --- /dev/null +++ b/testspr/sprout/algorithm/sort_heap.hpp @@ -0,0 +1,123 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HEAP_HPP +#define TESTSPR_SPROUT_ALGORITHM_SORT_HEAP_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_sort_heap_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort_heap( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort_heap( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{10, 9, 2, 3, 5, 6, 7, 8, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort_heap( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{10, 9, 2, 3, 5, 6, 7, 8, 4, 1}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort_heap( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort_heap( + arr1, + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort_heap( + sprout::sub(arr1, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{10, 9, 2, 3, 5, 6, 7, 8, 4, 1}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort_heap( + sprout::sub(arr1, 2, 8), + testspr::less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 5, 6, 7, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{10, 9, 2, 3, 5, 6, 7, 8, 4, 1}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HEAP_HPP + diff --git a/testspr/sprout/algorithm/stable_partition.hpp b/testspr/sprout/algorithm/stable_partition.hpp new file mode 100644 index 00000000..f0533004 --- /dev/null +++ b/testspr/sprout/algorithm/stable_partition.hpp @@ -0,0 +1,72 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_HPP +#define TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_stable_partition_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // パーティション (is_odd) + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition( + arr1, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{1, 3, 5, 7, 9, 2, 4, 6, 8, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::stable_partition( + arr1, + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{1, 3, 5, 7, 9}} + )); + } + // パーティション (is_odd) + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition( + sprout::sub(arr1, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7, 4, 6, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{1, 2, 3, 5, 7, 4, 6, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::stable_partition( + sprout::sub(arr1, 2, 8), + testspr::is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{1, 2, 3, 5, 7, 4, 6, 8, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_HPP + diff --git a/testspr/sprout/algorithm/stable_partition_copy.hpp b/testspr/sprout/algorithm/stable_partition_copy.hpp new file mode 100644 index 00000000..f7830111 --- /dev/null +++ b/testspr/sprout/algorithm/stable_partition_copy.hpp @@ -0,0 +1,108 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_stable_partition_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲をパーティション (is_odd) + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7, 4, 6, 8, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::stable_partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7}} + )); + } + // [2 .. 8) の範囲をパーティション (is_odd) + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::stable_partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7}} + )); + } + // [2 .. 8) の範囲をパーティション (is_odd) + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7, 4, 6, 8}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{0, 0, 3, 5, 7, 4, 6, 8, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::stable_partition_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + is_odd() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + partitioned, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(partitioned), + array{{0, 0, 3, 5, 7, 4, 6, 8, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_COPY_HPP + diff --git a/testspr/sprout/algorithm/stable_sort.hpp b/testspr/sprout/algorithm/stable_sort.hpp new file mode 100644 index 00000000..49530fdc --- /dev/null +++ b/testspr/sprout/algorithm/stable_sort.hpp @@ -0,0 +1,123 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_SORT_HPP +#define TESTSPR_SPROUT_ALGORITHM_STABLE_SORT_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_stable_sort_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::stable_sort( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::stable_sort( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::stable_sort( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 7, 8, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::stable_sort( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 3, 4, 7, 8, 9}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}}; + + // ソート + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::stable_sort( + arr1, + testspr::mod_less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{5, 10, 1, 6, 2, 7, 8, 3, 9, 4}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::stable_sort( + arr1, + testspr::mod_less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{5, 10, 1, 6, 2, 7, 8, 3, 9, 4}} + )); + } + // ソート + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::stable_sort( + sprout::sub(arr1, 2, 8), + testspr::mod_less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 7, 8, 3, 9, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 7, 8, 3, 9, 4, 10, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::stable_sort( + sprout::sub(arr1, 2, 8), + testspr::mod_less() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sorted, + array{{2, 7, 8, 3, 9, 4}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(sorted), + array{{5, 1, 2, 7, 8, 3, 9, 4, 10, 6}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_SORT_HPP + diff --git a/testspr/sprout/algorithm/swap_element.hpp b/testspr/sprout/algorithm/swap_element.hpp new file mode 100644 index 00000000..f13be2f1 --- /dev/null +++ b/testspr/sprout/algorithm/swap_element.hpp @@ -0,0 +1,76 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_HPP +#define TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_swap_element_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + + // スワップ + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::swap_element( + arr1, + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{1, 2, 8, 4, 5, 6, 7, 3, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::fit::swap_element( + arr1, + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{1, 2, 8, 4, 5, 6, 7, 3, 9, 10}} + )); + } + // スワップ + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::swap_element( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6, 7, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(swapped), + array{{1, 2, 8, 4, 5, 6, 7, 3, 9, 10}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::fit::swap_element( + sprout::sub(arr1, 2, 8), + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6, 7, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(swapped), + array{{1, 2, 8, 4, 5, 6, 7, 3, 9, 10}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_HPP + diff --git a/testspr/sprout/algorithm/swap_element_copy.hpp b/testspr/sprout/algorithm/swap_element_copy.hpp new file mode 100644 index 00000000..74731e42 --- /dev/null +++ b/testspr/sprout/algorithm/swap_element_copy.hpp @@ -0,0 +1,114 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_swap_element_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲をスワップ + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::swap_element_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6, 7, 3, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::fit::swap_element_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6, 7, 3}} + )); + } + // [2 .. 8) の範囲をスワップ + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::swap_element_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::fit::swap_element_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6}} + )); + } + // [2 .. 8) の範囲をスワップ + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::swap_element_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6, 7, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(swapped), + array{{0, 0, 8, 4, 5, 6, 7, 3, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto swapped = sprout::fit::swap_element_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 7 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + swapped, + array{{8, 4, 5, 6, 7, 3}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(swapped), + array{{0, 0, 8, 4, 5, 6, 7, 3, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_COPY_HPP + diff --git a/testspr/sprout/algorithm/transform.hpp b/testspr/sprout/algorithm/transform.hpp new file mode 100644 index 00000000..93b89382 --- /dev/null +++ b/testspr/sprout/algorithm/transform.hpp @@ -0,0 +1,206 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_TRANSFORM_HPP +#define TESTSPR_SPROUT_ALGORITHM_TRANSFORM_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_transform_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を変換 + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + testspr::x2() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::fit::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + testspr::x2() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16}} + )); + } + // [2 .. 8) の範囲を変換 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + testspr::x2() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::fit::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + testspr::x2() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12}} + )); + } + // [2 .. 8) の範囲を変換 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + testspr::x2() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(transformed), + array{{0, 0, 6, 8, 10, 12, 14, 16, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::fit::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + testspr::x2() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(transformed), + array{{0, 0, 6, 8, 10, 12, 14, 16, 0, 0}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr1_2 = array{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲を変換 + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::begin(arr1_2) + 2, + arr2, + testspr::plus() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::fit::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::begin(arr1_2) + 2, + arr2, + testspr::plus() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16}} + )); + } + // [2 .. 8) の範囲を変換 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::begin(arr1_2) + 2, + arr3, + testspr::plus() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::fit::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::begin(arr1_2) + 2, + arr3, + testspr::plus() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12}} + )); + } + // [2 .. 8) の範囲を変換 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::begin(arr1_2) + 2, + sprout::sub(arr2, 2, 8), + testspr::plus() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(transformed), + array{{0, 0, 6, 8, 10, 12, 14, 16, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto transformed = sprout::fit::transform( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::begin(arr1_2) + 2, + sprout::sub(arr2, 2, 8), + testspr::plus() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + transformed, + array{{6, 8, 10, 12, 14, 16}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(transformed), + array{{0, 0, 6, 8, 10, 12, 14, 16, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_TRANSFORM_HPP + diff --git a/testspr/sprout/algorithm/unique.hpp b/testspr/sprout/algorithm/unique.hpp new file mode 100644 index 00000000..ce0eb1b8 --- /dev/null +++ b/testspr/sprout/algorithm/unique.hpp @@ -0,0 +1,123 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_HPP +#define TESTSPR_SPROUT_ALGORITHM_UNIQUE_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_unique_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 1, 3, 3, 5, 5, 7, 7, 9, 9}}; + + // 「……ユニーク」 + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{1, 3, 5, 7, 9, 5, 7, 7, 9, 9}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique( + arr1 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{1, 3, 5, 7, 9}} + )); + } + // 「……ユニーク」 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7, 5, 7, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{1, 1, 3, 5, 7, 5, 7, 7, 9, 9}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique( + sprout::sub(arr1, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{1, 1, 3, 5, 7, 5, 7, 7, 9, 9}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 1, 3, 3, 5, 5, 7, 7, 9, 9}}; + + // 「……ユニーク」 + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique( + arr1, + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{1, 3, 5, 7, 9, 5, 7, 7, 9, 9}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique( + arr1, + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{1, 3, 5, 7, 9}} + )); + } + // 「……ユニーク」 + // 範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique( + sprout::sub(arr1, 2, 8), + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7, 5, 7, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{1, 1, 3, 5, 7, 5, 7, 7, 9, 9}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique( + sprout::sub(arr1, 2, 8), + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{1, 1, 3, 5, 7, 5, 7, 7, 9, 9}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_HPP + diff --git a/testspr/sprout/algorithm/unique_copy.hpp b/testspr/sprout/algorithm/unique_copy.hpp new file mode 100644 index 00000000..b51f058e --- /dev/null +++ b/testspr/sprout/algorithm/unique_copy.hpp @@ -0,0 +1,193 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_COPY_HPP +#define TESTSPR_SPROUT_ALGORITHM_UNIQUE_COPY_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_unique_copy_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 1, 3, 3, 5, 5, 7, 7, 9, 9}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲「……ユニーク」 + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7}} + )); + } + // [2 .. 8) の範囲「……ユニーク」 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3 + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5}} + )); + } + // [2 .. 8) の範囲「……ユニーク」 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8) + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}} + )); + } + } + { + SPROUT_STATIC_CONSTEXPR auto arr1 = array{{1, 1, 3, 3, 5, 5, 7, 7, 9, 9}}; + SPROUT_STATIC_CONSTEXPR auto arr2 = array{}; + SPROUT_STATIC_CONSTEXPR auto arr3 = array{}; + + // [2 .. 8) の範囲「……ユニーク」 + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7, 0, 0, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr2, + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7}} + )); + } + // [2 .. 8) の範囲「……ユニーク」 + // 出力範囲をオーバーする場合 + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + arr3, + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5}} + )); + } + // [2 .. 8) の範囲「……ユニーク」 + // 出力範囲の切り出し + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7, 0, 0, 0}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}} + )); + } + { + SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique_copy( + sprout::begin(arr1) + 2, + sprout::begin(arr1) + 8, + sprout::sub(arr2, 2, 8), + testspr::equal_to() + ); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + uniqued, + array{{3, 5, 7}} + )); + TESTSPR_DOUBLE_ASSERT(testspr::equal( + sprout::get_fixed(uniqued), + array{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}} + )); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_COPY_HPP + diff --git a/testspr/sprout/array.hpp b/testspr/sprout/array.hpp new file mode 100644 index 00000000..81451246 --- /dev/null +++ b/testspr/sprout/array.hpp @@ -0,0 +1,143 @@ +#ifndef TESTSPR_SPROUT_ARRAY_HPP +#define TESTSPR_SPROUT_ARRAY_HPP + +#include +#include +#include + +namespace testspr { + static void array_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR int carr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + SPROUT_STATIC_CONSTEXPR auto arr1 = sprout::to_array(carr); + SPROUT_STATIC_CONSTEXPR auto arr2 = sprout::make_array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + SPROUT_STATIC_CONSTEXPR auto arr3 = sprout::make_common_array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + + TESTSPR_DOUBLE_ASSERT(testspr::equal(carr, arr1)); + TESTSPR_DOUBLE_ASSERT(testspr::equal(carr, arr2)); + TESTSPR_DOUBLE_ASSERT(testspr::equal(carr, arr3)); + + // begin + TESTSPR_DOUBLE_ASSERT(carr[0] == *arr1.begin()); + TESTSPR_DOUBLE_ASSERT(carr[0] == *arr2.begin()); + + // cbegin + TESTSPR_DOUBLE_ASSERT(carr[0] == *arr1.cbegin()); + TESTSPR_DOUBLE_ASSERT(carr[0] == *arr2.cbegin()); + + // end + TESTSPR_DOUBLE_ASSERT(carr[9] == *(arr1.end() - 1)); + TESTSPR_DOUBLE_ASSERT(carr[9] == *(arr2.end() - 1)); + + // cend + TESTSPR_DOUBLE_ASSERT(carr[9] == *(arr1.cend() - 1)); + TESTSPR_DOUBLE_ASSERT(carr[9] == *(arr2.cend() - 1)); + + // rbegin + TESTSPR_DOUBLE_ASSERT(carr[9] == *arr1.rbegin()); + TESTSPR_DOUBLE_ASSERT(carr[9] == *arr2.rbegin()); + + // crbegin + TESTSPR_DOUBLE_ASSERT(carr[9] == *arr1.crbegin()); + TESTSPR_DOUBLE_ASSERT(carr[9] == *arr2.crbegin()); + + // rend + TESTSPR_DOUBLE_ASSERT(carr[0] == *(arr1.rend() - 1)); + TESTSPR_DOUBLE_ASSERT(carr[0] == *(arr2.rend() - 1)); + + // crend + TESTSPR_DOUBLE_ASSERT(carr[0] == *(arr1.crend() - 1)); + TESTSPR_DOUBLE_ASSERT(carr[0] == *(arr2.crend() - 1)); + + // size + TESTSPR_DOUBLE_ASSERT(arr1.size() == 10); + TESTSPR_DOUBLE_ASSERT(arr2.size() == 10); + + // empty + TESTSPR_DOUBLE_ASSERT(!arr1.empty()); + TESTSPR_DOUBLE_ASSERT(!arr2.empty()); + TESTSPR_DOUBLE_ASSERT((array{{}}.empty())); + + // max_size + TESTSPR_DOUBLE_ASSERT(arr1.max_size() == 10); + TESTSPR_DOUBLE_ASSERT(arr2.max_size() == 10); + + // operator[] + TESTSPR_DOUBLE_ASSERT(carr[0] == arr1[0]); + TESTSPR_DOUBLE_ASSERT(carr[0] == arr2[0]); + + // at + TESTSPR_DOUBLE_ASSERT(carr[0] == arr1.at(0)); + TESTSPR_DOUBLE_ASSERT(carr[0] == arr2.at(0)); + + // front + TESTSPR_DOUBLE_ASSERT(carr[0] == arr1.front()); + TESTSPR_DOUBLE_ASSERT(carr[0] == arr2.front()); + + // back + TESTSPR_DOUBLE_ASSERT(carr[9] == arr1.back()); + TESTSPR_DOUBLE_ASSERT(carr[9] == arr2.back()); + + // data + TESTSPR_DOUBLE_ASSERT(carr[0] == *arr1.data()); + TESTSPR_DOUBLE_ASSERT(carr[0] == *arr2.data()); + + // c_array + { + auto arr = arr1; + TESTSPR_ASSERT(carr[0] == *arr.c_array()); + } + + // assign + { + auto arr = arr1; + arr.assign(-1); + TESTSPR_ASSERT(arr[0] == -1); + } + + // fill + { + auto arr = arr1; + arr.fill(-1); + TESTSPR_ASSERT(arr[0] == -1); + } + + // swap + { + auto arr1 = array{{1, 2}}; + auto arr2 = array{{-1, -2}}; + arr1.swap(arr2); + TESTSPR_ASSERT(arr1[0] == -1); + } + + // operator= + { + auto arr1 = array{{1, 2}}; + arr1 = array{{-1, -2}}; + TESTSPR_ASSERT(arr1[0] == -1); + } + + // operator== + TESTSPR_DOUBLE_ASSERT(arr1 == arr2); + + // operator!= + TESTSPR_DOUBLE_ASSERT(!(arr1 != arr2)); + + // operator< + TESTSPR_DOUBLE_ASSERT(!(arr1 < arr2)); + + // operator> + TESTSPR_DOUBLE_ASSERT(!(arr1 > arr2)); + + // operator<= + TESTSPR_DOUBLE_ASSERT(arr1 <= arr2); + + // operator>= + TESTSPR_DOUBLE_ASSERT(arr1 >= arr2); + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ARRAY_HPP + diff --git a/testspr/sprout/random.hpp b/testspr/sprout/random.hpp new file mode 100644 index 00000000..710582d9 --- /dev/null +++ b/testspr/sprout/random.hpp @@ -0,0 +1,41 @@ +#ifndef TESTSPR_SPROUT_RANDOM_HPP +#define TESTSPR_SPROUT_RANDOM_HPP + +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace testspr { + void random_test() { + using namespace sprout; + + testspr::random_linear_congruential_test(); + testspr::random_additive_combine_test(); + testspr::random_shuffle_order_test(); + testspr::random_inversive_congruential_test(); + testspr::random_taus88_test(); + //testspr::random_mersenne_twister_test(); + testspr::random_uniform_smallint_test(); + testspr::random_uniform_int_distribution_test(); + testspr::random_uniform_01_test(); + testspr::random_uniform_real_distribution_test(); + testspr::random_bernoulli_distribution_test(); + testspr::random_binomial_distribution_test(); + testspr::random_geometric_distribution_test(); + testspr::random_normal_distribution_test(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_HPP diff --git a/testspr/sprout/random/additive_combine.hpp b/testspr/sprout/random/additive_combine.hpp new file mode 100644 index 00000000..52d23ce9 --- /dev/null +++ b/testspr/sprout/random/additive_combine.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_ADDITIVE_COMBINE_HPP +#define TESTSPR_SPROUT_RANDOM_ADDITIVE_COMBINE_HPP + +#include +#include +#include + +namespace testspr { + void random_additive_combine_test() { + using namespace sprout; + + testspr::random_engine_test_generic(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_ADDITIVE_COMBINE_HPP diff --git a/testspr/sprout/random/bernoulli_distribution.hpp b/testspr/sprout/random/bernoulli_distribution.hpp new file mode 100644 index 00000000..7665bf5c --- /dev/null +++ b/testspr/sprout/random/bernoulli_distribution.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP +#define TESTSPR_SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP + +#include +#include +#include + +namespace testspr { + void random_bernoulli_distribution_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP diff --git a/testspr/sprout/random/binomial_distribution.hpp b/testspr/sprout/random/binomial_distribution.hpp new file mode 100644 index 00000000..83ac47be --- /dev/null +++ b/testspr/sprout/random/binomial_distribution.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_BINOMIAL_DISTRIBUTION_HPP +#define TESTSPR_SPROUT_RANDOM_BINOMIAL_DISTRIBUTION_HPP + +#include +#include +#include + +namespace testspr { + void random_binomial_distribution_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_BINOMIAL_DISTRIBUTION_HPP diff --git a/testspr/sprout/random/distribution_generic.hpp b/testspr/sprout/random/distribution_generic.hpp new file mode 100644 index 00000000..c25a5d17 --- /dev/null +++ b/testspr/sprout/random/distribution_generic.hpp @@ -0,0 +1,82 @@ +#ifndef TESTSPR_SPROUT_RANDOM_DISTRIBUTION_GENERIC_HPP +#define TESTSPR_SPROUT_RANDOM_DISTRIBUTION_GENERIC_HPP + +#include +#include +#include +#include +#include + +namespace testspr { + template + void random_distribution_test_generic() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto parm = typename Distribution::param_type(); + + SPROUT_STATIC_CONSTEXPR auto dist1 = Distribution(parm); + SPROUT_STATIC_CONSTEXPR auto dist2 = Distribution(parm); + + // min + // max + TESTSPR_DOUBLE_ASSERT(dist1.min() <= dist1.max()); + + // param + TESTSPR_DOUBLE_ASSERT(parm == dist1.param()); + { + auto dist_temp = Distribution(); + dist_temp.param(parm); + TESTSPR_ASSERT(dist_temp == dist1); + } + + // operator== + // operator!= + TESTSPR_DOUBLE_ASSERT(dist1 == dist2); + TESTSPR_DOUBLE_ASSERT(!(dist1 != dist2)); + + { + std::string s; + + // operator<< + { + std::ostringstream os; + os << dist1; + TESTSPR_ASSERT(os); + + s = os.str(); + } + + auto dist_temp = Distribution(); + + // operator>> + { + std::istringstream is(s); + is >> dist_temp; + TESTSPR_ASSERT(is); + } + + TESTSPR_ASSERT(dist_temp == dist1); + } + + // operator() + { + SPROUT_STATIC_CONSTEXPR auto eng = Engine(SPROUT_UNIQUE_SEED); + { + SPROUT_STATIC_CONSTEXPR auto rnd = dist1(eng); + + // result + TESTSPR_DOUBLE_ASSERT(dist1.min() <= rnd.result()); + TESTSPR_DOUBLE_ASSERT(rnd.result() <= dist1.max()); + + // engine + TESTSPR_DOUBLE_ASSERT(rnd.engine().min() <= rnd.engine().max()); + + // distribution + TESTSPR_DOUBLE_ASSERT(rnd.distribution().min() <= rnd.distribution().max()); + } + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_DISTRIBUTION_GENERIC_HPP diff --git a/testspr/sprout/random/engine_generic.hpp b/testspr/sprout/random/engine_generic.hpp new file mode 100644 index 00000000..1685bde2 --- /dev/null +++ b/testspr/sprout/random/engine_generic.hpp @@ -0,0 +1,71 @@ +#ifndef TESTSPR_SPROUT_RANDOM_ENGINE_GENERIC_HPP +#define TESTSPR_SPROUT_RANDOM_ENGINE_GENERIC_HPP + +#include +#include +#include +#include + +namespace testspr { + template + void random_engine_test_generic() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR auto eng1 = Engine(SPROUT_UNIQUE_SEED); + SPROUT_STATIC_CONSTEXPR auto eng2 = Engine(SPROUT_UNIQUE_SEED); + + // min + // max + TESTSPR_DOUBLE_ASSERT(eng1.min() <= eng1.max()); + + // operator== + // operator!= +// TESTSPR_DOUBLE_ASSERT(eng1 == eng1); +// TESTSPR_DOUBLE_ASSERT(!(eng1 == eng2)); +// TESTSPR_DOUBLE_ASSERT(eng1 != eng2); +// TESTSPR_DOUBLE_ASSERT(!(eng1 != eng1)); + TESTSPR_ASSERT(eng1 == eng1); + TESTSPR_ASSERT(!(eng1 == eng2)); + TESTSPR_ASSERT(eng1 != eng2); + TESTSPR_ASSERT(!(eng1 != eng1)); + + { + std::string s; + + // operator<< + { + std::ostringstream os; + os << eng1; + TESTSPR_ASSERT(os); + + s = os.str(); + } + + auto eng_temp = Engine(); + + // operator>> + { + std::istringstream is(s); + is >> eng_temp; + TESTSPR_ASSERT(is); + } + + //TESTSPR_ASSERT(eng_temp == eng1); + } + + // operator() + { + SPROUT_STATIC_CONSTEXPR auto rnd = eng1(); + + // result + TESTSPR_DOUBLE_ASSERT(eng1.min() <= rnd.result()); + TESTSPR_DOUBLE_ASSERT(rnd.result() <= eng1.max()); + + // engine + TESTSPR_DOUBLE_ASSERT(rnd.engine().min() <= rnd.engine().max()); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_ENGINE_GENERIC_HPP diff --git a/testspr/sprout/random/geometric_distribution.hpp b/testspr/sprout/random/geometric_distribution.hpp new file mode 100644 index 00000000..8e3e2f92 --- /dev/null +++ b/testspr/sprout/random/geometric_distribution.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP +#define TESTSPR_SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP + +#include +#include +#include + +namespace testspr { + void random_geometric_distribution_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP diff --git a/testspr/sprout/random/inversive_congruential.hpp b/testspr/sprout/random/inversive_congruential.hpp new file mode 100644 index 00000000..1e134202 --- /dev/null +++ b/testspr/sprout/random/inversive_congruential.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP +#define TESTSPR_SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP + +#include +#include +#include + +namespace testspr { + void random_inversive_congruential_test() { + using namespace sprout; + + testspr::random_engine_test_generic(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP diff --git a/testspr/sprout/random/linear_congruential.hpp b/testspr/sprout/random/linear_congruential.hpp new file mode 100644 index 00000000..84f2e8da --- /dev/null +++ b/testspr/sprout/random/linear_congruential.hpp @@ -0,0 +1,18 @@ +#ifndef TESTSPR_SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP +#define TESTSPR_SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP + +#include +#include +#include + +namespace testspr { + void random_linear_congruential_test() { + using namespace sprout; + + testspr::random_engine_test_generic(); + testspr::random_engine_test_generic(); + testspr::random_engine_test_generic(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP diff --git a/testspr/sprout/random/mersenne_twister.hpp b/testspr/sprout/random/mersenne_twister.hpp new file mode 100644 index 00000000..e4511bc1 --- /dev/null +++ b/testspr/sprout/random/mersenne_twister.hpp @@ -0,0 +1,18 @@ +#ifndef TESTSPR_SPROUT_RANDOM_MERSENNE_TWISTER_HPP +#define TESTSPR_SPROUT_RANDOM_MERSENNE_TWISTER_HPP + +#include +#include +#include + +namespace testspr { + void random_mersenne_twister_test() { + using namespace sprout; + + testspr::random_engine_test_generic(); + //testspr::random_engine_test_generic(); + //testspr::random_engine_test_generic(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_MERSENNE_TWISTER_HPP diff --git a/testspr/sprout/random/normal_distribution.hpp b/testspr/sprout/random/normal_distribution.hpp new file mode 100644 index 00000000..56a0f4d5 --- /dev/null +++ b/testspr/sprout/random/normal_distribution.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP +#define TESTSPR_SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP + +#include +#include +#include + +namespace testspr { + void random_normal_distribution_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP diff --git a/testspr/sprout/random/shuffle_order.hpp b/testspr/sprout/random/shuffle_order.hpp new file mode 100644 index 00000000..609bfd53 --- /dev/null +++ b/testspr/sprout/random/shuffle_order.hpp @@ -0,0 +1,17 @@ +#ifndef TESTSPR_SPROUT_RANDOM_SHUFFLE_ORDER_HPP +#define TESTSPR_SPROUT_RANDOM_SHUFFLE_ORDER_HPP + +#include +#include +#include + +namespace testspr { + void random_shuffle_order_test() { + using namespace sprout; + + testspr::random_engine_test_generic(); + testspr::random_engine_test_generic(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_SHUFFLE_ORDER_HPP diff --git a/testspr/sprout/random/taus88.hpp b/testspr/sprout/random/taus88.hpp new file mode 100644 index 00000000..ada28b0c --- /dev/null +++ b/testspr/sprout/random/taus88.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_TAUS88_HPP +#define TESTSPR_SPROUT_RANDOM_TAUS88_HPP + +#include +#include +#include + +namespace testspr { + void random_taus88_test() { + using namespace sprout; + + testspr::random_engine_test_generic(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_TAUS88_HPP diff --git a/testspr/sprout/random/uniform_01.hpp b/testspr/sprout/random/uniform_01.hpp new file mode 100644 index 00000000..e1c1d1aa --- /dev/null +++ b/testspr/sprout/random/uniform_01.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_01_HPP +#define TESTSPR_SPROUT_RANDOM_UNIFORM_01_HPP + +#include +#include +#include + +namespace testspr { + void random_uniform_01_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_01_HPP diff --git a/testspr/sprout/random/uniform_int_distribution.hpp b/testspr/sprout/random/uniform_int_distribution.hpp new file mode 100644 index 00000000..14dbc793 --- /dev/null +++ b/testspr/sprout/random/uniform_int_distribution.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP +#define TESTSPR_SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP + +#include +#include +#include + +namespace testspr { + void random_uniform_int_distribution_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP diff --git a/testspr/sprout/random/uniform_real_distribution.hpp b/testspr/sprout/random/uniform_real_distribution.hpp new file mode 100644 index 00000000..472ce838 --- /dev/null +++ b/testspr/sprout/random/uniform_real_distribution.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP +#define TESTSPR_SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP + +#include +#include +#include + +namespace testspr { + void random_uniform_real_distribution_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP diff --git a/testspr/sprout/random/uniform_smallint.hpp b/testspr/sprout/random/uniform_smallint.hpp new file mode 100644 index 00000000..086541b9 --- /dev/null +++ b/testspr/sprout/random/uniform_smallint.hpp @@ -0,0 +1,16 @@ +#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_SMALLINT_HPP +#define TESTSPR_SPROUT_RANDOM_UNIFORM_SMALLINT_HPP + +#include +#include +#include + +namespace testspr { + void random_uniform_smallint_test() { + using namespace sprout; + + testspr::random_distribution_test_generic >(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_SMALLINT_HPP diff --git a/testspr/sprout/string.hpp b/testspr/sprout/string.hpp new file mode 100644 index 00000000..bdfd165c --- /dev/null +++ b/testspr/sprout/string.hpp @@ -0,0 +1,226 @@ +#ifndef TESTSPR_SPROUT_STRING_HPP +#define TESTSPR_SPROUT_STRING_HPP + +#include +#include +#include +#include +#include +#include + +namespace testspr { + static void string_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char cstr[] = "foobar1234"; + SPROUT_STATIC_CONSTEXPR auto str1 = to_string(cstr); + SPROUT_STATIC_CONSTEXPR auto str2 = to_string("hogehoge"); + + TESTSPR_DOUBLE_ASSERT((std::is_same const>::value)); + TESTSPR_DOUBLE_ASSERT((std::is_same const>::value)); + + // begin + TESTSPR_DOUBLE_ASSERT(cstr[0] == *str1.begin()); + + // cbegin + TESTSPR_DOUBLE_ASSERT(cstr[0] == *str1.cbegin()); + + // end + TESTSPR_DOUBLE_ASSERT(cstr[9] == *(str1.end() - 1)); + + // cend + TESTSPR_DOUBLE_ASSERT(cstr[9] == *(str1.cend() - 1)); + + // rbegin + TESTSPR_DOUBLE_ASSERT(cstr[9] == *str1.rbegin()); + + // crbegin + TESTSPR_DOUBLE_ASSERT(cstr[9] == *str1.crbegin()); + + // rend + TESTSPR_DOUBLE_ASSERT(cstr[0] == *(str1.rend() - 1)); + + // crend + TESTSPR_DOUBLE_ASSERT(cstr[0] == *(str1.crend() - 1)); + + // size + TESTSPR_DOUBLE_ASSERT(str1.size() == 10); + + // empty + TESTSPR_DOUBLE_ASSERT(!str1.empty()); + TESTSPR_DOUBLE_ASSERT((string_t<0>::type().empty())); + + // max_size + TESTSPR_DOUBLE_ASSERT(str1.max_size() == 10); + + // operator[] + TESTSPR_DOUBLE_ASSERT(cstr[0] == str1[0]); + + // at + TESTSPR_DOUBLE_ASSERT(cstr[0] == str1.at(0)); + + // front + TESTSPR_DOUBLE_ASSERT(cstr[0] == str1.front()); + + // back + TESTSPR_DOUBLE_ASSERT(cstr[9] == str1.back()); + + // data + TESTSPR_DOUBLE_ASSERT(cstr[0] == *str1.data()); + + // c_str + TESTSPR_DOUBLE_ASSERT(cstr[0] == *str1.c_str()); + + // swap + { + auto s1 = to_string("abc"); + auto s2 = to_string("ABC"); + s1.swap(s2); + TESTSPR_ASSERT(s1[0] == 'A'); + } + + // assign + { + auto s = to_string("abc"); + s.assign(to_string("ABC")); + TESTSPR_ASSERT(s.size() == 3); + TESTSPR_ASSERT(s[0] == 'A'); + } + { + auto s = to_string("abc"); + s.assign(to_string("ABC"), 0, 2); + TESTSPR_ASSERT(s.size() == 2); + TESTSPR_ASSERT(s[0] == 'A'); + } + { + auto s = to_string("abc"); + s.assign("ABC", 2); + TESTSPR_ASSERT(s.size() == 2); + TESTSPR_ASSERT(s[0] == 'A'); + } + { + auto s = to_string("abc"); + s.assign("ABC"); + TESTSPR_ASSERT(s.size() == 3); + TESTSPR_ASSERT(s[0] == 'A'); + } + { + auto s = to_string("abc"); + s.assign(1, 'A'); + TESTSPR_ASSERT(s.size() == 1); + TESTSPR_ASSERT(s[0] == 'A'); + } + + // operator= + { + auto s = to_string("abc"); + s = to_string("ABC"); + TESTSPR_ASSERT(s.size() == 3); + TESTSPR_ASSERT(s[0] == 'A'); + } + { + auto s = to_string("abc"); + s = "ABC"; + TESTSPR_ASSERT(s.size() == 3); + TESTSPR_ASSERT(s[0] == 'A'); + } + { + auto s = to_string("abc"); + s = 'A'; + TESTSPR_ASSERT(s.size() == 1); + TESTSPR_ASSERT(s[0] == 'A'); + } + + // compare + TESTSPR_DOUBLE_ASSERT(str1.compare(cstr) == 0); + TESTSPR_DOUBLE_ASSERT(str1.compare("zzzz") < 0); + TESTSPR_DOUBLE_ASSERT(str1.compare("aaaa") > 0); + + // substr + { + SPROUT_STATIC_CONSTEXPR auto str3 = str1.substr(); + TESTSPR_DOUBLE_ASSERT(str3 == "foobar1234"); + } + { + SPROUT_STATIC_CONSTEXPR auto str3 = str1.substr(6); + TESTSPR_DOUBLE_ASSERT(str3 == "1234"); + } + { + SPROUT_STATIC_CONSTEXPR auto str3 = str1.substr(0, 6); + TESTSPR_DOUBLE_ASSERT(str3 == "foobar"); + } + + // operator== + TESTSPR_DOUBLE_ASSERT(!(str1 == str2)); + + // operator!= + TESTSPR_DOUBLE_ASSERT(str1 != str2); + + // operator< + TESTSPR_DOUBLE_ASSERT(str1 < str2); + + // operator> + TESTSPR_DOUBLE_ASSERT(!(str1 > str2)); + + // operator<= + TESTSPR_DOUBLE_ASSERT(str1 <= str2); + + // operator>= + TESTSPR_DOUBLE_ASSERT(!(str1 >= str2)); + + // operator+ + { +#ifdef SPROUT_CONFIG_USE_INDEX_ITERATOR_IMPLEMENTATION + // ! Error in GCC4.7 + SPROUT_STATIC_CONSTEXPR auto str3 = str1 + to_string("hogehoge"); + TESTSPR_DOUBLE_ASSERT(str3 == "foobar1234hogehoge"); +#endif + + SPROUT_STATIC_CONSTEXPR auto str4 = str1 + str2; + TESTSPR_DOUBLE_ASSERT(str4 == "foobar1234hogehoge"); + } + + // operator<< + { + std::ostringstream os; + os << str1; + TESTSPR_ASSERT(os.str() == cstr); + } + + // operator>> + { + std::istringstream is("hogehoge piyopiyo"); + auto str3 = str1; + is >> str3; + TESTSPR_ASSERT(str3 == "hogehoge"); + } + + // string_from_c_str + { + SPROUT_STATIC_CONSTEXPR auto str3 = string_from_c_str<10>(cstr); + TESTSPR_DOUBLE_ASSERT(str3 == "foobar1234"); + } + { + SPROUT_STATIC_CONSTEXPR auto str3 = string_from_c_str<10>(cstr, 6); + TESTSPR_DOUBLE_ASSERT(str3 == "foobar"); + } + + // make_string + { + SPROUT_STATIC_CONSTEXPR auto str3 = make_string('f', 'o', 'o', 'b', 'a', 'r'); + TESTSPR_DOUBLE_ASSERT(str3 == "foobar"); + TESTSPR_DOUBLE_ASSERT(str3.size() == 6); + } + + // operator basic_string + { + SPROUT_STATIC_CONSTEXPR string_t<10>::type str3 = to_string("foobar"); + TESTSPR_DOUBLE_ASSERT(str3 == "foobar"); + TESTSPR_DOUBLE_ASSERT(str3.size() == 6); + } + } + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_STRING_HPP + diff --git a/testspr/tools.hpp b/testspr/tools.hpp new file mode 100644 index 00000000..1b3b6014 --- /dev/null +++ b/testspr/tools.hpp @@ -0,0 +1,194 @@ +#ifndef TESTSPR_TOOLS_HPP +#define TESTSPR_TOOLS_HPP + +#include +#include +#include +#include +#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING +# include +#endif + +// +// TESTSPR_PP_CAT +// +#define TESTSPR_PP_CAT(a, b) TESTSPR_PP_CAT_I(a, b) +#define TESTSPR_PP_CAT_I(a, b) a ## b + +// +// TESTSPR_STATIC_ASSERT +// +#define TESTSPR_STATIC_ASSERT(expr) static_assert(expr, #expr) +// +// TESTSPR_ASSERT +// +#define TESTSPR_ASSERT(expr) assert(expr) +// +// TESTSPR_DOUBLE_ASSERT +// +#define TESTSPR_DOUBLE_ASSERT(expr) TESTSPR_STATIC_ASSERT(expr); TESTSPR_ASSERT(expr) + +// +// TESTSPR_STATIC_WARNING +// +#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING +# define TESTSPR_STATIC_WARNING(expr) BOOST_STATIC_WARNING(expr) +#else +# define TESTSPR_STATIC_WARNING(expr) +#endif + +// +// TESTSPR_STATIC_UNCHECKED +// +#define TESTSPR_STATIC_UNCHECKED(expr) TESTSPR_STATIC_WARNING(expr) +// +// TESTSPR_UNCHECKED +// +#define TESTSPR_UNCHECKED(expr) (expr) +// +// TESTSPR_DOUBLE_UNCHECKED +// +#define TESTSPR_DOUBLE_UNCHECKED(expr) TESTSPR_STATIC_UNCHECKED(expr); TESTSPR_UNCHECKED(expr) + +namespace testspr { + // + // is_even + // + template + struct is_even { + SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 == 0; } + }; + // + // is_odd + // + template + struct is_odd { + SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 != 0; } + }; + + // + // less + // + template + struct less { + SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs < rhs; } + }; + // + // greater + // + template + struct greater { + SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs > rhs; } + }; + // + // equal_to + // + template + struct equal_to { + SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs == rhs; } + }; + // + // mod_less + // + template + struct mod_less { + SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs % mod < rhs % mod; } + }; + + // + // x2 + // + template + struct x2 { + SPROUT_CONSTEXPR T operator()(T const& t) const { return t + t; } + }; + // + // plus + // + template + struct plus { + SPROUT_CONSTEXPR T operator()(T const& lhs, T const& rhs) const { return lhs + rhs; } + }; + + // + // distance + // + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + distance(Iterator first, Iterator last) { + return first == last ? 0 + : 1 + testspr::distance(first + 1, last) + ; + } + + // + // equal + // + template + SPROUT_CONSTEXPR bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) { + return first1 == last1 ? first2 == last2 + : first2 == last2 ? false + : !(*first1 == *first2) ? false + : testspr::equal(first1 + 1, last1, first2 + 1, last2) + ; + } + template + SPROUT_CONSTEXPR bool equal(Range1 const& range1, Range2 const& range2) { + return testspr::equal(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2)); + } + + // + // is_found + // + template + SPROUT_CONSTEXPR bool is_found(Iterator first, Iterator last, T const& value) { + return first == last ? false + : *first == value ? true + : testspr::is_found(first + 1, last, value) + ; + } + template + SPROUT_CONSTEXPR bool is_found(Range const& range, T const& value) { + return testspr::is_found(sprout::begin(range), sprout::end(range), value); + } + + // + // count + // + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + count(Iterator first, Iterator last, T const& value) { + return first == last ? 0 + : (*first == value ? 1 : 0) + testspr::count(first + 1, last, value) + ; + } + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + count(Range const& range, T const& value) { + return testspr::count(sprout::begin(range), sprout::end(range), value); + } + + namespace detail { + template + SPROUT_CONSTEXPR bool is_permutation_impl(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Iterator1 first1_, Iterator2 first2_) + { + return first1_ == last1 && first2_ == last2 ? true + : testspr::count(first1, last1, *first1_) != testspr::count(first2, first2 + testspr::distance(first1, last1), *first1_) ? false + : testspr::detail::is_permutation_impl(first1, last1, first2, last2, first1_ + 1, first2_ + 1) + ; + } + } // namespace detail + // + // is_permutation + // + template + SPROUT_CONSTEXPR bool is_permutation(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) { + return testspr::detail::is_permutation_impl(first1, last1, first2, last2, first1, first2); + } + template + SPROUT_CONSTEXPR bool is_permutation(Range1 const& range1, Range2 const& range2) { + return testspr::is_permutation(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2)); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_TOOLS_HPP