testspr テスト追加

This commit is contained in:
bolero-MURAKAMI 2011-12-23 20:59:33 +09:00
parent 240c2bee1d
commit 7479f20c46
72 changed files with 6810 additions and 0 deletions

31
testspr/print.hpp Normal file
View file

@ -0,0 +1,31 @@
#ifndef TESTSPR_PRINT_HPP
#define TESTSPR_PRINT_HPP
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sprout/fixed_container.hpp>
namespace testspr {
//
// print
//
template<typename Iterator>
void print(Iterator first, Iterator last) {
std::for_each(first, last, [](typename std::iterator_traits<Iterator>::value_type const& e){ std::cout << e << ' '; });
std::cout << std::endl;
}
template<typename Range>
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

9
testspr/sprout.cpp Normal file
View file

@ -0,0 +1,9 @@
#define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION
#include <iostream>
#include <testspr/sprout.hpp>
int main() {
testspr::sprout_test();
std::cout << "testspr succeeded." << std::endl;
}

18
testspr/sprout.hpp Normal file
View file

@ -0,0 +1,18 @@
#ifndef TESTSPR_SPROUT_HPP
#define TESTSPR_SPROUT_HPP
#include <testspr/sprout/array.hpp>
#include <testspr/sprout/string.hpp>
#include <testspr/sprout/algorithm.hpp>
#include <testspr/sprout/random.hpp>
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

View file

@ -0,0 +1,107 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_HPP
#define TESTSPR_SPROUT_ALGORITHM_HPP
#include <testspr/sprout/algorithm/copy.hpp>
#include <testspr/sprout/algorithm/copy_n.hpp>
#include <testspr/sprout/algorithm/copy_if.hpp>
#include <testspr/sprout/algorithm/copy_backward.hpp>
#include <testspr/sprout/algorithm/transform.hpp>
#include <testspr/sprout/algorithm/replace.hpp>
#include <testspr/sprout/algorithm/replace_if.hpp>
#include <testspr/sprout/algorithm/replace_copy.hpp>
#include <testspr/sprout/algorithm/replace_copy_if.hpp>
#include <testspr/sprout/algorithm/fill.hpp>
#include <testspr/sprout/algorithm/fill_n.hpp>
#include <testspr/sprout/algorithm/generate.hpp>
#include <testspr/sprout/algorithm/generate_n.hpp>
#include <testspr/sprout/algorithm/remove.hpp>
#include <testspr/sprout/algorithm/remove_if.hpp>
#include <testspr/sprout/algorithm/remove_copy.hpp>
#include <testspr/sprout/algorithm/remove_copy_if.hpp>
#include <testspr/sprout/algorithm/unique.hpp>
#include <testspr/sprout/algorithm/unique_copy.hpp>
#include <testspr/sprout/algorithm/reverse.hpp>
#include <testspr/sprout/algorithm/reverse_copy.hpp>
#include <testspr/sprout/algorithm/rotate.hpp>
#include <testspr/sprout/algorithm/rotate_copy.hpp>
#include <testspr/sprout/algorithm/shuffle.hpp>
#include <testspr/sprout/algorithm/shuffle_result.hpp>
#include <testspr/sprout/algorithm/partition.hpp>
#include <testspr/sprout/algorithm/partition_copy.hpp>
#include <testspr/sprout/algorithm/stable_partition.hpp>
#include <testspr/sprout/algorithm/stable_partition_copy.hpp>
#include <testspr/sprout/algorithm/sort.hpp>
#include <testspr/sprout/algorithm/stable_sort.hpp>
#include <testspr/sprout/algorithm/partial_sort.hpp>
#include <testspr/sprout/algorithm/nth_element.hpp>
#include <testspr/sprout/algorithm/merge.hpp>
#include <testspr/sprout/algorithm/inplace_merge.hpp>
#include <testspr/sprout/algorithm/set_union.hpp>
#include <testspr/sprout/algorithm/set_intersection.hpp>
#include <testspr/sprout/algorithm/set_difference.hpp>
#include <testspr/sprout/algorithm/set_symmetric_difference.hpp>
#include <testspr/sprout/algorithm/push_heap.hpp>
#include <testspr/sprout/algorithm/pop_heap.hpp>
#include <testspr/sprout/algorithm/make_heap.hpp>
#include <testspr/sprout/algorithm/make_partial_heap.hpp>
#include <testspr/sprout/algorithm/sort_heap.hpp>
#include <testspr/sprout/algorithm/swap_element.hpp>
#include <testspr/sprout/algorithm/swap_element_copy.hpp>
#include <testspr/sprout/algorithm/bogo_sort.hpp>
#include <testspr/sprout/algorithm/bogo_sort_result.hpp>
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

View file

@ -0,0 +1,133 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_HPP
#define TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_HPP
#include <sprout/algorithm/sort.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_bogo_sort_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{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<int, 5>{{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<int, 5>{{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<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 5>{{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<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 5>{{5, 1, 2, 4, 3}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 1, 4, 2, 3}};
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::bogo_sort(
arr1,
sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED),
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 5>{{1, 2, 3, 4, 5}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::bogo_sort(
arr1,
sprout::random::hellekalek1995(SPROUT_UNIQUE_SEED),
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 5>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 5>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 5>{{5, 1, 2, 4, 3}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_HPP

View file

@ -0,0 +1,175 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_RESULT_HPP
#define TESTSPR_SPROUT_ALGORITHM_BOGO_SORT_RESULT_HPP
#include <sprout/algorithm/sort.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_bogo_sort_result_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{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<int, 5>{{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<int, 5>{{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<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sprout::get<0>(sorted)),
array<int, 5>{{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<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sprout::get<0>(sorted)),
array<int, 5>{{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<int, 5>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 5>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 5>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sprout::get<0>(sorted)),
array<int, 5>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get<0>(sorted),
array<int, 3>{{1, 2, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sprout::get<0>(sorted)),
array<int, 5>{{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

View file

@ -0,0 +1,102 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_COPY_HPP
#include <sprout/algorithm/copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{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<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_HPP

View file

@ -0,0 +1,102 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_BACKWARD_HPP
#define TESTSPR_SPROUT_ALGORITHM_COPY_BACKWARD_HPP
#include <sprout/algorithm/copy_backward.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_copy_backward_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{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<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_BACKWARD_HPP

View file

@ -0,0 +1,108 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_IF_HPP
#define TESTSPR_SPROUT_ALGORITHM_COPY_IF_HPP
#include <sprout/algorithm/copy_if.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_copy_if_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// 奇数をコピー
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_if(
sprout::begin(arr1),
sprout::end(arr1),
arr2,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
copied,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
copied,
array<int, 5>{{1, 3, 5, 7, 9}}
));
}
// 奇数をコピー
// 出力範囲をオーバーする場合
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_if(
sprout::begin(arr1),
sprout::end(arr1),
arr3,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
copied,
array<int, 4>{{1, 3, 5, 7}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::fit::copy_if(
sprout::begin(arr1),
sprout::end(arr1),
arr3,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
copied,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
copied,
array<int, 6>{{1, 3, 5, 7, 9, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
copied,
array<int, 5>{{1, 3, 5, 7, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{0, 0, 1, 3, 5, 7, 9, 0, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_IF_HPP

View file

@ -0,0 +1,102 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_COPY_N_HPP
#define TESTSPR_SPROUT_ALGORITHM_COPY_N_HPP
#include <sprout/algorithm/copy_n.hpp>
#include <sprout/array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_copy_n_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// 6 要素をコピー
{
SPROUT_STATIC_CONSTEXPR auto copied = sprout::copy_n(
sprout::begin(arr1) + 2,
6,
arr2
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
copied,
array<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{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<int, 6>{{3, 4, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(copied),
array<int, 10>{{0, 0, 3, 4, 5, 6, 7, 8, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_COPY_N_HPP

View file

@ -0,0 +1,72 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_FILL_HPP
#define TESTSPR_SPROUT_ALGORITHM_FILL_HPP
#include <sprout/algorithm/fill.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_fill_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{-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<int, 10>{{-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<int, 6>{{-1, -1, -1, -1, -1, -1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(filled),
array<int, 10>{{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<int, 6>{{-1, -1, -1, -1, -1, -1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(filled),
array<int, 10>{{1, 2, -1, -1, -1, -1, -1, -1, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_FILL_HPP

View file

@ -0,0 +1,76 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_FILL_N_HPP
#define TESTSPR_SPROUT_ALGORITHM_FILL_N_HPP
#include <sprout/algorithm/fill_n.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_fill_n_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{-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<int, 4>{{-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<int, 6>{{-1, -1, -1, -1, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(filled),
array<int, 10>{{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<int, 4>{{-1, -1, -1, -1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(filled),
array<int, 10>{{1, 2, -1, -1, -1, -1, 7, 8, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_FILL_N_HPP

View file

@ -0,0 +1,76 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_HPP
#define TESTSPR_SPROUT_ALGORITHM_GENERATE_HPP
#include <sprout/algorithm/generate.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_generate_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
// 生成
{
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate(
arr1,
testspr::x2<int>(),
2
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 10>{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate(
arr1,
testspr::x2<int>(),
2
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 10>{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}}
));
}
// 生成
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate(
sprout::sub(arr1, 2, 8),
testspr::x2<int>(),
2
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 6>{{2, 4, 8, 16, 32, 64}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(generated),
array<int, 10>{{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<int>(),
2
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 6>{{2, 4, 8, 16, 32, 64}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(generated),
array<int, 10>{{1, 2, 2, 4, 8, 16, 32, 64, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_HPP

View file

@ -0,0 +1,80 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_N_HPP
#define TESTSPR_SPROUT_ALGORITHM_GENERATE_N_HPP
#include <sprout/algorithm/generate_n.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_generate_n_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
// 生成
{
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate_n(
arr1,
4,
testspr::x2<int>(),
1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 10>{{1, 2, 4, 8, 5, 6, 7, 8, 9, 10}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate_n(
arr1,
4,
testspr::x2<int>(),
1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 4>{{1, 2, 4, 8}}
));
}
// 生成
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate_n(
sprout::sub(arr1, 2, 8),
4,
testspr::x2<int>(),
1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 6>{{1, 2, 4, 8, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(generated),
array<int, 10>{{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<int>(),
1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
generated,
array<int, 4>{{1, 2, 4, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(generated),
array<int, 10>{{1, 2, 1, 2, 4, 8, 7, 8, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_GENERATE_N_HPP

View file

@ -0,0 +1,131 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_INPLACE_MERGE_HPP
#define TESTSPR_SPROUT_ALGORITHM_INPLACE_MERGE_HPP
#include <sprout/algorithm/inplace_merge.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_inplace_merge_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{2, 4, 5, 6, 7, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int, 6>{{2, 4, 5, 6, 7, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{1, 3, 2, 4, 5, 6, 7, 9, 8, 10}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{2, 4, 5, 6, 7, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{2, 4, 5, 6, 7, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{1, 3, 2, 4, 5, 6, 7, 9, 8, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_INPLACE_MERGE_HPP

View file

@ -0,0 +1,123 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_HEAP_HPP
#define TESTSPR_SPROUT_ALGORITHM_MAKE_HEAP_HPP
#include <sprout/algorithm/make_heap.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_make_heap_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 8>{{9, 6, 8, 2, 5, 3, 4, 1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{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<int, 8>{{9, 6, 8, 2, 5, 3, 4, 1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{10, 7, 9, 6, 8, 2, 5, 3, 4, 1}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}};
// ヒープ作成
{
SPROUT_STATIC_CONSTEXPR auto heap = sprout::make_heap(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 10>{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::make_heap(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 8>{{9, 6, 8, 2, 5, 3, 4, 1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 8>{{9, 6, 8, 2, 5, 3, 4, 1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{10, 7, 9, 6, 8, 2, 5, 3, 4, 1}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_HEAP_HPP

View file

@ -0,0 +1,131 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_PARTIAL_HEAP_HPP
#define TESTSPR_SPROUT_ALGORITHM_MAKE_PARTIAL_HEAP_HPP
#include <sprout/algorithm/make_partial_heap.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_make_partial_heap_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 5>{{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<int, 8>{{3, 1, 2, 9, 8, 6, 5, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{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<int, 3>{{3, 1, 2}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{10, 7, 3, 1, 2, 9, 8, 6, 5, 4}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 5>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 8>{{3, 1, 2, 9, 8, 6, 5, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 3>{{3, 1, 2}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{10, 7, 3, 1, 2, 9, 8, 6, 5, 4}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MAKE_PARTIAL_HEAP_HPP

View file

@ -0,0 +1,219 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_MERGE_HPP
#define TESTSPR_SPROUT_ALGORITHM_MERGE_HPP
#include <sprout/algorithm/merge.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_merge_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 4>{{3, 5, 7, 9}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 4>{{2, 4, 6, 8}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// マージ
{
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<int, 10>{{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<int, 8>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{2, 3, 4, 5, 6, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int, 6>{{2, 3, 4, 5, 6, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 2, 3, 4, 5, 6, 7, 0, 0}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 4>{{3, 5, 7, 9}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 4>{{2, 4, 6, 8}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// マージ
{
SPROUT_STATIC_CONSTEXPR auto merged = sprout::merge(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr1_2),
sprout::end(arr1_2),
arr2,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 8>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{2, 3, 4, 5, 6, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{2, 3, 4, 5, 6, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 2, 3, 4, 5, 6, 7, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MERGE_HPP

View file

@ -0,0 +1,131 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP
#define TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP
#include <sprout/algorithm/nth_element.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_nth_element_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 5>{{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<int, 6>{{2, 3, 5, 9, 8, 6}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(nth),
array<int, 10>{{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<int, 3>{{2, 3, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(nth),
array<int, 10>{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
nth,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
nth,
array<int, 5>{{2, 4, 1, 3, 5}}
));
}
// ソート
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element(
sprout::sub(arr1, 2, 8),
sprout::begin(arr1) + 4,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
nth,
array<int, 6>{{2, 3, 5, 9, 8, 6}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(nth),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
nth,
array<int, 3>{{2, 3, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(nth),
array<int, 10>{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP

View file

@ -0,0 +1,131 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_PARTIAL_SORT_HPP
#define TESTSPR_SPROUT_ALGORITHM_PARTIAL_SORT_HPP
#include <sprout/algorithm/partial_sort.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_partial_sort_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 5>{{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<int, 6>{{2, 3, 4, 9, 8, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int, 3>{{2, 3, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{5, 1, 2, 3, 4, 9, 8, 7, 10, 6}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 5>{{1, 2, 3, 4, 5}}
));
}
// ソート
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::partial_sort(
sprout::sub(arr1, 2, 8),
sprout::begin(arr1) + 5,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 6>{{2, 3, 4, 9, 8, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 3>{{2, 3, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{5, 1, 2, 3, 4, 9, 8, 7, 10, 6}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PARTIAL_SORT_HPP

View file

@ -0,0 +1,72 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_HPP
#define TESTSPR_SPROUT_ALGORITHM_PARTITION_HPP
#include <sprout/algorithm/partition.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_partition_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
// パーティション (is_odd)
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition(
arr1,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 10>{{9, 7, 5, 3, 1, 2, 4, 6, 8, 10}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::partition(
arr1,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 5>{{9, 7, 5, 3, 1}}
));
}
// パーティション (is_odd)
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition(
sprout::sub(arr1, 2, 8),
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 6>{{7, 5, 3, 4, 6, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 3>{{7, 5, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{1, 2, 7, 5, 3, 4, 6, 8, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_HPP

View file

@ -0,0 +1,108 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_PARTITION_COPY_HPP
#include <sprout/algorithm/partition_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_partition_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [2 .. 8) の範囲をパーティション (is_odd)
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::partition_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr2,
is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 3>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 4>{{5, 3, 4, 6}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::partition_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr3,
is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 2>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 6>{{7, 5, 3, 4, 6, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 3>{{7, 5, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{0, 0, 7, 5, 3, 4, 6, 8, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PARTITION_COPY_HPP

View file

@ -0,0 +1,68 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_POP_HEAP_HPP
#define TESTSPR_SPROUT_ALGORITHM_POP_HEAP_HPP
#include <sprout/algorithm/pop_heap.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_pop_heap_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 9>{{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<int, 8>{{7, 6, 4, 5, 3, 1, 2, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{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<int, 7>{{7, 6, 4, 5, 3, 1, 2}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{10, 8, 7, 6, 4, 5, 3, 1, 2, 9}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_POP_HEAP_HPP

View file

@ -0,0 +1,123 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_PUSH_HEAP_HPP
#define TESTSPR_SPROUT_ALGORITHM_PUSH_HEAP_HPP
#include <sprout/algorithm/push_heap.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_push_heap_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 8>{{9, 7, 4, 6, 3, 1, 2, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{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<int, 8>{{9, 7, 4, 6, 3, 1, 2, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{10, 8, 9, 7, 4, 6, 3, 1, 2, 5}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{10, 8, 9, 6, 4, 5, 3, 1, 2, 7}};
// ヒープにプッシュ
{
SPROUT_STATIC_CONSTEXPR auto heap = sprout::push_heap(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 10>{{10, 8, 9, 6, 7, 5, 3, 1, 2, 4}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto heap = sprout::fit::push_heap(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 8>{{9, 7, 4, 6, 3, 1, 2, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
heap,
array<int, 8>{{9, 7, 4, 6, 3, 1, 2, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(heap),
array<int, 10>{{10, 8, 9, 7, 4, 6, 3, 1, 2, 5}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_PUSH_HEAP_HPP

View file

@ -0,0 +1,72 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_HPP
#define TESTSPR_SPROUT_ALGORITHM_REMOVE_HPP
#include <sprout/algorithm/remove.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_remove_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 5>{{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<int, 6>{{3, 5, 7, 0, 7, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{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<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{1, 0, 3, 5, 7, 0, 7, 0, 9, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_HPP

View file

@ -0,0 +1,108 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_HPP
#include <sprout/algorithm/remove_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_remove_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// [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<int, 10>{{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<int, 3>{{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<int, 2>{{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<int, 2>{{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<int, 6>{{3, 5, 7, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{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<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_HPP

View file

@ -0,0 +1,108 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_IF_HPP
#define TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_IF_HPP
#include <sprout/algorithm/remove_copy_if.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_remove_copy_if_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// [2 .. 8) の範囲を削除 (is_odd)
{
SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_copy_if(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr2,
is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 3>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 2>{{0, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_copy_if(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr3,
is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 2>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 6>{{0, 0, 0, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 3>{{0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_COPY_IF_HPP

View file

@ -0,0 +1,72 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_IF_HPP
#define TESTSPR_SPROUT_ALGORITHM_REMOVE_IF_HPP
#include <sprout/algorithm/remove_if.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_remove_if_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}};
// 削除 (is_odd)
{
SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_if(
arr1,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 10>{{0, 0, 0, 0, 0, 0, 7, 0, 9, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto removed = sprout::fit::remove_if(
arr1,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 5>{{0, 0, 0, 0, 0}}
));
}
// 削除 (is_odd)
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto removed = sprout::remove_if(
sprout::sub(arr1, 2, 8),
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 6>{{0, 0, 0, 0, 7, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
removed,
array<int, 3>{{0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(removed),
array<int, 10>{{1, 0, 0, 0, 0, 0, 7, 0, 9, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REMOVE_IF_HPP

View file

@ -0,0 +1,76 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_HPP
#define TESTSPR_SPROUT_ALGORITHM_REPLACE_HPP
#include <sprout/algorithm/replace.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_replace_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{3, -1, 5, -1, 7, -1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{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<int, 6>{{3, -1, 5, -1, 7, -1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{1, 0, 3, -1, 5, -1, 7, -1, 9, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_HPP

View file

@ -0,0 +1,114 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_HPP
#include <sprout/algorithm/replace_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_replace_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{3, -1, 5, -1, 7, -1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{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<int, 6>{{3, -1, 5, -1, 7, -1}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{0, 0, 3, -1, 5, -1, 7, -1, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_HPP

View file

@ -0,0 +1,114 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_IF_HPP
#define TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_IF_HPP
#include <sprout/algorithm/replace_copy_if.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_replace_copy_if_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 10>{{-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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 6>{{-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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 4>{{-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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 4>{{-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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 6>{{-1, 0, -1, 0, -1, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 6>{{-1, 0, -1, 0, -1, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{0, 0, -1, 0, -1, 0, -1, 0, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_COPY_IF_HPP

View file

@ -0,0 +1,76 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_IF_HPP
#define TESTSPR_SPROUT_ALGORITHM_REPLACE_IF_HPP
#include <sprout/algorithm/replace_if.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_replace_if_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 0, 3, 0, 5, 0, 7, 0, 9, 0}};
// 置換 (is_odd -> -1)
{
SPROUT_STATIC_CONSTEXPR auto replaced = sprout::replace_if(
arr1,
is_odd<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 10>{{-1, 0, -1, 0, -1, 0, -1, 0, -1, 0}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto replaced = sprout::fit::replace_if(
arr1,
is_odd<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 10>{{-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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 6>{{-1, 0, -1, 0, -1, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{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<int>(),
-1
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
replaced,
array<int, 6>{{-1, 0, -1, 0, -1, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(replaced),
array<int, 10>{{1, 0, -1, 0, -1, 0, -1, 0, 9, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REPLACE_IF_HPP

View file

@ -0,0 +1,68 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_HPP
#define TESTSPR_SPROUT_ALGORITHM_REBERSE_HPP
#include <sprout/algorithm/reverse.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_reverse_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{8, 7, 6, 5, 4, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(reversed),
array<int, 10>{{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<int, 6>{{8, 7, 6, 5, 4, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(reversed),
array<int, 10>{{1, 2, 8, 7, 6, 5, 4, 3, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_HPP

View file

@ -0,0 +1,102 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_REBERSE_COPY_HPP
#include <sprout/algorithm/reverse_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_reverse_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{8, 7, 6, 5, 4, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(reversed),
array<int, 10>{{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<int, 6>{{8, 7, 6, 5, 4, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(reversed),
array<int, 10>{{0, 0, 8, 7, 6, 5, 4, 3, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_REBERSE_COPY_HPP

View file

@ -0,0 +1,72 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_HPP
#define TESTSPR_SPROUT_ALGORITHM_ROTATE_HPP
#include <sprout/algorithm/rotate.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_rotate_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{6, 7, 8, 3, 4, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(rotated),
array<int, 10>{{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<int, 6>{{6, 7, 8, 3, 4, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(rotated),
array<int, 10>{{1, 2, 6, 7, 8, 3, 4, 5, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_HPP

View file

@ -0,0 +1,108 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_ROTATE_COPY_HPP
#include <sprout/algorithm/rotate_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_rotate_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{6, 7, 8, 3, 4, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(rotated),
array<int, 10>{{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<int, 6>{{6, 7, 8, 3, 4, 5}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(rotated),
array<int, 10>{{0, 0, 6, 7, 8, 3, 4, 5, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_ROTATE_COPY_HPP

View file

@ -0,0 +1,219 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SET_DIFFERENCE_HPP
#define TESTSPR_SPROUT_ALGORITHM_SET_DIFFERENCE_HPP
#include <sprout/algorithm/set_difference.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_set_difference_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 10, 15, 20, 25}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// 論理差
{
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<int, 10>{{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<int, 3>{{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<int, 2>{{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<int, 2>{{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<int, 6>{{5, 15, 25, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int, 3>{{5, 15, 25}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 5, 15, 25, 0, 0, 0, 0, 0}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 10, 15, 20, 25}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// 論理差
{
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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 3>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 2>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 2>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{5, 15, 25, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 3>{{5, 15, 25}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 5, 15, 25, 0, 0, 0, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_DIFFERENCE_HPP

View file

@ -0,0 +1,219 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SET_INTERSECTION_HPP
#define TESTSPR_SPROUT_ALGORITHM_SET_INTERSECTION_HPP
#include <sprout/algorithm/set_intersection.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_set_intersection_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{20, 25, 30, 35, 40}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// 論理積
{
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<int, 10>{{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<int, 3>{{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<int, 2>{{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<int, 2>{{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<int, 6>{{20, 30, 40, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int, 3>{{20, 30, 40}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 20, 30, 40, 0, 0, 0, 0, 0}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{20, 25, 30, 35, 40}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// 論理積
{
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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 3>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 2>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 2>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{20, 30, 40, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 3>{{20, 30, 40}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 20, 30, 40, 0, 0, 0, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_INTERSECTION_HPP

View file

@ -0,0 +1,219 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP
#define TESTSPR_SPROUT_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP
#include <sprout/algorithm/set_symmetric_difference.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_set_symmetric_difference_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 10, 15, 20, 25}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// 排他的論理和
{
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<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{5, 15, 25, 30, 40, 50}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int, 6>{{5, 15, 25, 30, 40, 50}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 5, 15, 25, 30, 40, 50, 0, 0}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 10, 15, 20, 25}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// 排他的論理和
{
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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{5, 15, 25, 30, 40, 50}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{5, 15, 25, 30, 40, 50}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 5, 15, 25, 30, 40, 50, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP

View file

@ -0,0 +1,219 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SET_UNION_HPP
#define TESTSPR_SPROUT_ALGORITHM_SET_UNION_HPP
#include <sprout/algorithm/set_union.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_set_union_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 10, 15, 20, 25}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// 論理和
{
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<int, 10>{{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<int, 8>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{5, 10, 15, 20, 25, 30}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int, 6>{{5, 10, 15, 20, 25, 30}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 5, 10, 15, 20, 25, 30, 0, 0}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 5>{{5, 10, 15, 20, 25}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 5>{{10, 20, 30, 40, 50}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// 論理和
{
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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 8>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{5, 10, 15, 20, 25, 30}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
merged,
array<int, 6>{{5, 10, 15, 20, 25, 30}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(merged),
array<int, 10>{{0, 0, 5, 10, 15, 20, 25, 30, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SET_UNION_HPP

View file

@ -0,0 +1,74 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SHUFFLE_HPP
#define TESTSPR_SPROUT_ALGORITHM_SHUFFLE_HPP
#include <sprout/algorithm/shuffle.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_shuffle_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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

View file

@ -0,0 +1,95 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SHUFFLE_RESULT_HPP
#define TESTSPR_SPROUT_ALGORITHM_SHUFFLE_RESULT_HPP
#include <sprout/algorithm/shuffle_result.hpp>
#include <sprout/random.hpp>
#include <sprout/random/unique_seed.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_shuffle_result_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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

View file

@ -0,0 +1,123 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HPP
#define TESTSPR_SPROUT_ALGORITHM_SORT_HPP
#include <sprout/algorithm/sort.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_sort_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{2, 3, 4, 7, 8, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int, 6>{{2, 3, 4, 7, 8, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}};
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
));
}
// ソート
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort(
sprout::sub(arr1, 2, 8),
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 6>{{2, 3, 4, 7, 8, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 6>{{2, 3, 4, 7, 8, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HPP

View file

@ -0,0 +1,123 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HEAP_HPP
#define TESTSPR_SPROUT_ALGORITHM_SORT_HEAP_HPP
#include <sprout/algorithm/sort_heap.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_sort_heap_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{2, 3, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int, 6>{{2, 3, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{10, 9, 2, 3, 5, 6, 7, 8, 4, 1}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{10, 9, 8, 6, 7, 2, 5, 3, 4, 1}};
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::sort_heap(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::sort_heap(
arr1,
testspr::less<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 6>{{2, 3, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 6>{{2, 3, 5, 6, 7, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{10, 9, 2, 3, 5, 6, 7, 8, 4, 1}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SORT_HEAP_HPP

View file

@ -0,0 +1,72 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_HPP
#define TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_HPP
#include <sprout/algorithm/stable_partition.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_stable_partition_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
// パーティション (is_odd)
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition(
arr1,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 10>{{1, 3, 5, 7, 9, 2, 4, 6, 8, 10}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::fit::stable_partition(
arr1,
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 5>{{1, 3, 5, 7, 9}}
));
}
// パーティション (is_odd)
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition(
sprout::sub(arr1, 2, 8),
testspr::is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 6>{{3, 5, 7, 4, 6, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{1, 2, 3, 5, 7, 4, 6, 8, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_HPP

View file

@ -0,0 +1,108 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_COPY_HPP
#include <sprout/algorithm/stable_partition_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_stable_partition_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [2 .. 8) の範囲をパーティション (is_odd)
{
SPROUT_STATIC_CONSTEXPR auto partitioned = sprout::stable_partition_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr2,
is_odd<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 3>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 3>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 6>{{3, 5, 7, 4, 6, 8}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
partitioned,
array<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(partitioned),
array<int, 10>{{0, 0, 3, 5, 7, 4, 6, 8, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_PARTITION_COPY_HPP

View file

@ -0,0 +1,123 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_SORT_HPP
#define TESTSPR_SPROUT_ALGORITHM_STABLE_SORT_HPP
#include <sprout/algorithm/stable_sort.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_stable_sort_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{2, 3, 4, 7, 8, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int, 6>{{2, 3, 4, 7, 8, 9}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{5, 1, 2, 3, 4, 7, 8, 9, 10, 6}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{5, 1, 9, 4, 8, 2, 7, 3, 10, 6}};
// ソート
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::stable_sort(
arr1,
testspr::mod_less<int, 5>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 10>{{5, 10, 1, 6, 2, 7, 8, 3, 9, 4}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto sorted = sprout::fit::stable_sort(
arr1,
testspr::mod_less<int, 5>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 10>{{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<int, 5>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 6>{{2, 7, 8, 3, 9, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{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<int, 5>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sorted,
array<int, 6>{{2, 7, 8, 3, 9, 4}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(sorted),
array<int, 10>{{5, 1, 2, 7, 8, 3, 9, 4, 10, 6}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_STABLE_SORT_HPP

View file

@ -0,0 +1,76 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_HPP
#define TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_HPP
#include <sprout/algorithm/swap_element.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_swap_element_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 10>{{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<int, 6>{{8, 4, 5, 6, 7, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(swapped),
array<int, 10>{{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<int, 6>{{8, 4, 5, 6, 7, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(swapped),
array<int, 10>{{1, 2, 8, 4, 5, 6, 7, 3, 9, 10}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_HPP

View file

@ -0,0 +1,114 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_COPY_HPP
#include <sprout/algorithm/swap_element_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_swap_element_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int, 10>{{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<int, 6>{{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<int, 4>{{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<int, 4>{{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<int, 6>{{8, 4, 5, 6, 7, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(swapped),
array<int, 10>{{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<int, 6>{{8, 4, 5, 6, 7, 3}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(swapped),
array<int, 10>{{0, 0, 8, 4, 5, 6, 7, 3, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_SWAP_ELEMENT_COPY_HPP

View file

@ -0,0 +1,206 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_TRANSFORM_HPP
#define TESTSPR_SPROUT_ALGORITHM_TRANSFORM_HPP
#include <sprout/algorithm/transform.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_transform_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [2 .. 8) の範囲を変換
{
SPROUT_STATIC_CONSTEXPR auto transformed = sprout::transform(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr2,
testspr::x2<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 6>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 4>{{6, 8, 10, 12}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto transformed = sprout::fit::transform(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr3,
testspr::x2<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 6>{{6, 8, 10, 12, 14, 16}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(transformed),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 6>{{6, 8, 10, 12, 14, 16}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(transformed),
array<int, 10>{{0, 0, 6, 8, 10, 12, 14, 16, 0, 0}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr1_2 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 4>{};
// [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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 6>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 4>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 6>{{6, 8, 10, 12, 14, 16}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(transformed),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
transformed,
array<int, 6>{{6, 8, 10, 12, 14, 16}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(transformed),
array<int, 10>{{0, 0, 6, 8, 10, 12, 14, 16, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_TRANSFORM_HPP

View file

@ -0,0 +1,123 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_HPP
#define TESTSPR_SPROUT_ALGORITHM_UNIQUE_HPP
#include <sprout/algorithm/unique.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_unique_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{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<int, 10>{{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<int, 5>{{1, 3, 5, 7, 9}}
));
}
// 「……ユニーク」
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique(
sprout::sub(arr1, 2, 8)
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 6>{{3, 5, 7, 5, 7, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{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<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{1, 1, 3, 5, 7, 5, 7, 7, 9, 9}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 1, 3, 3, 5, 5, 7, 7, 9, 9}};
// 「……ユニーク」
{
SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique(
arr1,
testspr::equal_to<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 10>{{1, 3, 5, 7, 9, 5, 7, 7, 9, 9}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique(
arr1,
testspr::equal_to<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 5>{{1, 3, 5, 7, 9}}
));
}
// 「……ユニーク」
// 範囲の切り出し
{
SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique(
sprout::sub(arr1, 2, 8),
testspr::equal_to<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 6>{{3, 5, 7, 5, 7, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{1, 1, 3, 5, 7, 5, 7, 7, 9, 9}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_HPP

View file

@ -0,0 +1,193 @@
#ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_COPY_HPP
#define TESTSPR_SPROUT_ALGORITHM_UNIQUE_COPY_HPP
#include <sprout/algorithm/unique_copy.hpp>
#include <sprout/array.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_unique_copy_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 1, 3, 3, 5, 5, 7, 7, 9, 9}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// [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<int, 10>{{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<int, 3>{{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<int, 2>{{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<int, 2>{{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<int, 6>{{3, 5, 7, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{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<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}}
));
}
}
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 1, 3, 3, 5, 5, 7, 7, 9, 9}};
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 2>{};
// [2 .. 8) の範囲「……ユニーク」
{
SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::unique_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr2,
testspr::equal_to<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 3>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 2>{{3, 5}}
));
}
{
SPROUT_STATIC_CONSTEXPR auto uniqued = sprout::fit::unique_copy(
sprout::begin(arr1) + 2,
sprout::begin(arr1) + 8,
arr3,
testspr::equal_to<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 2>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 6>{{3, 5, 7, 0, 0, 0}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{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<int>()
);
TESTSPR_DOUBLE_ASSERT(testspr::equal(
uniqued,
array<int, 3>{{3, 5, 7}}
));
TESTSPR_DOUBLE_ASSERT(testspr::equal(
sprout::get_fixed(uniqued),
array<int, 10>{{0, 0, 3, 5, 7, 0, 0, 0, 0, 0}}
));
}
}
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_UNIQUE_COPY_HPP

143
testspr/sprout/array.hpp Normal file
View file

@ -0,0 +1,143 @@
#ifndef TESTSPR_SPROUT_ARRAY_HPP
#define TESTSPR_SPROUT_ARRAY_HPP
#include <sprout/array.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
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<int>(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<int, 0>{{}}.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<int, 2>{{1, 2}};
auto arr2 = array<int, 2>{{-1, -2}};
arr1.swap(arr2);
TESTSPR_ASSERT(arr1[0] == -1);
}
// operator=
{
auto arr1 = array<int, 2>{{1, 2}};
arr1 = array<int, 2>{{-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

41
testspr/sprout/random.hpp Normal file
View file

@ -0,0 +1,41 @@
#ifndef TESTSPR_SPROUT_RANDOM_HPP
#define TESTSPR_SPROUT_RANDOM_HPP
#include <testspr/sprout/random/linear_congruential.hpp>
#include <testspr/sprout/random/additive_combine.hpp>
#include <testspr/sprout/random/shuffle_order.hpp>
#include <testspr/sprout/random/inversive_congruential.hpp>
#include <testspr/sprout/random/taus88.hpp>
//#include <testspr/sprout/random/mersenne_twister.hpp>
#include <testspr/sprout/random/uniform_smallint.hpp>
#include <testspr/sprout/random/uniform_int_distribution.hpp>
#include <testspr/sprout/random/uniform_01.hpp>
#include <testspr/sprout/random/uniform_real_distribution.hpp>
#include <testspr/sprout/random/bernoulli_distribution.hpp>
#include <testspr/sprout/random/binomial_distribution.hpp>
#include <testspr/sprout/random/geometric_distribution.hpp>
#include <testspr/sprout/random/normal_distribution.hpp>
#include <testspr/tools.hpp>
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

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_ADDITIVE_COMBINE_HPP
#define TESTSPR_SPROUT_RANDOM_ADDITIVE_COMBINE_HPP
#include <sprout/random/additive_combine.hpp>
#include <testspr/sprout/random/engine_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_additive_combine_test() {
using namespace sprout;
testspr::random_engine_test_generic<sprout::random::ecuyer1988>();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_ADDITIVE_COMBINE_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP
#define TESTSPR_SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP
#include <sprout/random/bernoulli_distribution.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_bernoulli_distribution_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::bernoulli_distribution<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_BERNOULLI_DISTRIBUTION_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_BINOMIAL_DISTRIBUTION_HPP
#define TESTSPR_SPROUT_RANDOM_BINOMIAL_DISTRIBUTION_HPP
#include <sprout/random/binomial_distribution.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_binomial_distribution_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::binomial_distribution<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_BINOMIAL_DISTRIBUTION_HPP

View file

@ -0,0 +1,82 @@
#ifndef TESTSPR_SPROUT_RANDOM_DISTRIBUTION_GENERIC_HPP
#define TESTSPR_SPROUT_RANDOM_DISTRIBUTION_GENERIC_HPP
#include <string>
#include <sstream>
#include <sprout/random/linear_congruential.hpp>
#include <sprout/random/unique_seed.hpp>
#include <testspr/tools.hpp>
namespace testspr {
template<typename Distribution, typename Engine = sprout::random::minstd_rand0>
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

View file

@ -0,0 +1,71 @@
#ifndef TESTSPR_SPROUT_RANDOM_ENGINE_GENERIC_HPP
#define TESTSPR_SPROUT_RANDOM_ENGINE_GENERIC_HPP
#include <string>
#include <sstream>
#include <sprout/random/unique_seed.hpp>
#include <testspr/tools.hpp>
namespace testspr {
template<typename Engine>
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

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
#define TESTSPR_SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP
#include <sprout/random/geometric_distribution.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_geometric_distribution_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::geometric_distribution<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
#define TESTSPR_SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP
#include <sprout/random/linear_congruential.hpp>
#include <testspr/sprout/random/engine_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_inversive_congruential_test() {
using namespace sprout;
testspr::random_engine_test_generic<sprout::random::hellekalek1995>();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP

View file

@ -0,0 +1,18 @@
#ifndef TESTSPR_SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP
#define TESTSPR_SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP
#include <sprout/random/linear_congruential.hpp>
#include <testspr/sprout/random/engine_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_linear_congruential_test() {
using namespace sprout;
testspr::random_engine_test_generic<sprout::random::minstd_rand0>();
testspr::random_engine_test_generic<sprout::random::minstd_rand>();
testspr::random_engine_test_generic<sprout::random::rand48>();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP

View file

@ -0,0 +1,18 @@
#ifndef TESTSPR_SPROUT_RANDOM_MERSENNE_TWISTER_HPP
#define TESTSPR_SPROUT_RANDOM_MERSENNE_TWISTER_HPP
#include <sprout/random/mersenne_twister.hpp>
#include <testspr/sprout/random/engine_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_mersenne_twister_test() {
using namespace sprout;
testspr::random_engine_test_generic<sprout::random::mt11213b>();
//testspr::random_engine_test_generic<sprout::random::mt19937>();
//testspr::random_engine_test_generic<sprout::random::mt19937_64>();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_MERSENNE_TWISTER_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP
#define TESTSPR_SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP
#include <sprout/random/normal_distribution.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_normal_distribution_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::normal_distribution<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP

View file

@ -0,0 +1,17 @@
#ifndef TESTSPR_SPROUT_RANDOM_SHUFFLE_ORDER_HPP
#define TESTSPR_SPROUT_RANDOM_SHUFFLE_ORDER_HPP
#include <sprout/random/shuffle_order.hpp>
#include <testspr/sprout/random/engine_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_shuffle_order_test() {
using namespace sprout;
testspr::random_engine_test_generic<sprout::random::knuth_b>();
testspr::random_engine_test_generic<sprout::random::kreutzer1986>();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_SHUFFLE_ORDER_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_TAUS88_HPP
#define TESTSPR_SPROUT_RANDOM_TAUS88_HPP
#include <sprout/random/taus88.hpp>
#include <testspr/sprout/random/engine_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_taus88_test() {
using namespace sprout;
testspr::random_engine_test_generic<sprout::random::taus88>();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_TAUS88_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_01_HPP
#define TESTSPR_SPROUT_RANDOM_UNIFORM_01_HPP
#include <sprout/random/uniform_01.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_uniform_01_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::uniform_01<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_01_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
#define TESTSPR_SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP
#include <sprout/random/uniform_int_distribution.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_uniform_int_distribution_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::uniform_int_distribution<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
#define TESTSPR_SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP
#include <sprout/random/uniform_real_distribution.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_uniform_real_distribution_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::uniform_real_distribution<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP

View file

@ -0,0 +1,16 @@
#ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_SMALLINT_HPP
#define TESTSPR_SPROUT_RANDOM_UNIFORM_SMALLINT_HPP
#include <sprout/random/uniform_smallint.hpp>
#include <testspr/sprout/random/distribution_generic.hpp>
#include <testspr/tools.hpp>
namespace testspr {
void random_uniform_smallint_test() {
using namespace sprout;
testspr::random_distribution_test_generic<sprout::random::uniform_smallint<> >();
}
} // namespace testspr
#endif // #ifndef TESTSPR_SPROUT_RANDOM_UNIFORM_SMALLINT_HPP

226
testspr/sprout/string.hpp Normal file
View file

@ -0,0 +1,226 @@
#ifndef TESTSPR_SPROUT_STRING_HPP
#define TESTSPR_SPROUT_STRING_HPP
#include <cstring>
#include <sstream>
#include <type_traits>
#include <sprout/string.hpp>
#include <sprout/fixed_container.hpp>
#include <testspr/tools.hpp>
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<decltype(str1), sprout::basic_string<char, 10> const>::value));
TESTSPR_DOUBLE_ASSERT((std::is_same<decltype(str2), sprout::basic_string<char, 8> 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

194
testspr/tools.hpp Normal file
View file

@ -0,0 +1,194 @@
#ifndef TESTSPR_TOOLS_HPP
#define TESTSPR_TOOLS_HPP
#include <cassert>
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/fixed_container.hpp>
#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING
# include <boost/serialization/static_warning.hpp>
#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<typename T>
struct is_even {
SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 == 0; }
};
//
// is_odd
//
template<typename T>
struct is_odd {
SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 != 0; }
};
//
// less
//
template<typename T>
struct less {
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs < rhs; }
};
//
// greater
//
template<typename T>
struct greater {
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs > rhs; }
};
//
// equal_to
//
template<typename T>
struct equal_to {
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs == rhs; }
};
//
// mod_less
//
template<typename T, T mod>
struct mod_less {
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs % mod < rhs % mod; }
};
//
// x2
//
template<typename T>
struct x2 {
SPROUT_CONSTEXPR T operator()(T const& t) const { return t + t; }
};
//
// plus
//
template<typename T>
struct plus {
SPROUT_CONSTEXPR T operator()(T const& lhs, T const& rhs) const { return lhs + rhs; }
};
//
// distance
//
template<typename Iterator>
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type
distance(Iterator first, Iterator last) {
return first == last ? 0
: 1 + testspr::distance(first + 1, last)
;
}
//
// equal
//
template<typename Iterator1, typename Iterator2>
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<typename Range1, typename Range2>
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<class Iterator, typename T>
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<typename Range, typename T>
SPROUT_CONSTEXPR bool is_found(Range const& range, T const& value) {
return testspr::is_found(sprout::begin(range), sprout::end(range), value);
}
//
// count
//
template<typename Iterator, typename T>
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::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<typename Range, typename T>
SPROUT_CONSTEXPR typename std::iterator_traits<typename Range::const_iterator>::difference_type
count(Range const& range, T const& value) {
return testspr::count(sprout::begin(range), sprout::end(range), value);
}
namespace detail {
template<typename Iterator1, typename Iterator2>
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<typename Iterator1, typename Iterator2>
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<typename Range1, typename Range2>
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