mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-02 14:04:20 +00:00
destructive change sprout::generate -> sprout::unfold
add range adapter reversed, replaced, filtered
This commit is contained in:
parent
6b3f7ad894
commit
73ead93fe5
60 changed files with 3840 additions and 318 deletions
|
@ -11,29 +11,27 @@ 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 arr1 = array<int, 10>{{0}};
|
||||
|
||||
// <20>¶<EFBFBD>¬
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate(
|
||||
arr1,
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 10>{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}}
|
||||
array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate(
|
||||
arr1,
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 10>{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}}
|
||||
array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
|
||||
));
|
||||
}
|
||||
// <20>¶<EFBFBD>¬
|
||||
|
@ -41,31 +39,29 @@ namespace testspr {
|
|||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 6>{{2, 4, 8, 16, 32, 64}}
|
||||
array<int, 6>{{1, 2, 3, 4, 5, 6}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(generated),
|
||||
array<int, 10>{{1, 2, 2, 4, 8, 16, 32, 64, 9, 10}}
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 5, 6, 0, 0}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 6>{{2, 4, 8, 16, 32, 64}}
|
||||
array<int, 6>{{1, 2, 3, 4, 5, 6}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(generated),
|
||||
array<int, 10>{{1, 2, 2, 4, 8, 16, 32, 64, 9, 10}}
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 5, 6, 0, 0}}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,31 +11,29 @@ 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 arr1 = array<int, 10>{{0}};
|
||||
|
||||
// <20>¶<EFBFBD>¬
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate_n(
|
||||
arr1,
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 10>{{1, 2, 4, 8, 5, 6, 7, 8, 9, 10}}
|
||||
array<int, 10>{{1, 2, 3, 4, 0, 0, 0, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate_n(
|
||||
arr1,
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 4>{{1, 2, 4, 8}}
|
||||
array<int, 4>{{1, 2, 3, 4}}
|
||||
));
|
||||
}
|
||||
// <20>¶<EFBFBD>¬
|
||||
|
@ -44,32 +42,30 @@ namespace testspr {
|
|||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::generate_n(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 6>{{1, 2, 4, 8, 7, 8}}
|
||||
array<int, 6>{{1, 2, 3, 4, 0, 0}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(generated),
|
||||
array<int, 10>{{1, 2, 1, 2, 4, 8, 7, 8, 9, 10}}
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 0, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto generated = sprout::fit::generate_n(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
testspr::gen_iota<int>(1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
generated,
|
||||
array<int, 4>{{1, 2, 4, 8}}
|
||||
array<int, 4>{{1, 2, 3, 4}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(generated),
|
||||
array<int, 10>{{1, 2, 1, 2, 4, 8, 7, 8, 9, 10}}
|
||||
array<int, 10>{{0, 0, 1, 2, 3, 4, 0, 0, 0, 0}}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "./fill_n.cpp"
|
||||
#include "./generate.cpp"
|
||||
#include "./generate_n.cpp"
|
||||
#include "./unfold.cpp"
|
||||
#include "./unfold_n.cpp"
|
||||
#include "./remove.cpp"
|
||||
#include "./remove_if.cpp"
|
||||
#include "./remove_copy.cpp"
|
||||
|
@ -76,10 +78,12 @@ namespace testspr {
|
|||
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_fill_test();
|
||||
testspr::algorithm_fill_n_test();
|
||||
testspr::algorithm_unfold_test();
|
||||
testspr::algorithm_unfold_n_test();
|
||||
testspr::algorithm_remove_test();
|
||||
testspr::algorithm_remove_if_test();
|
||||
testspr::algorithm_remove_copy_test();
|
||||
|
|
80
libs/algorithm/test/unfold.cpp
Normal file
80
libs/algorithm/test/unfold.cpp
Normal file
|
@ -0,0 +1,80 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_UNFOLD_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_UNFOLD_CPP
|
||||
|
||||
#include <sprout/algorithm/unfold.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/sub_array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_unfold_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 unfolded = sprout::unfold(
|
||||
arr1,
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 10>{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto unfolded = sprout::fit::unfold(
|
||||
arr1,
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 10>{{2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}}
|
||||
));
|
||||
}
|
||||
// 生成
|
||||
// 範囲の切り出し
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto unfolded = sprout::unfold(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 6>{{2, 4, 8, 16, 32, 64}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(unfolded),
|
||||
array<int, 10>{{1, 2, 2, 4, 8, 16, 32, 64, 9, 10}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto unfolded = sprout::fit::unfold(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
testspr::x2<int>(),
|
||||
2
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 6>{{2, 4, 8, 16, 32, 64}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(unfolded),
|
||||
array<int, 10>{{1, 2, 2, 4, 8, 16, 32, 64, 9, 10}}
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_unfold_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_UNFOLD_CPP
|
84
libs/algorithm/test/unfold_n.cpp
Normal file
84
libs/algorithm/test/unfold_n.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_UNFOLD_N_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_UNFOLD_N_CPP
|
||||
|
||||
#include <sprout/algorithm/unfold_n.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/sub_array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_unfold_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 unfolded = sprout::unfold_n(
|
||||
arr1,
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 10>{{1, 2, 4, 8, 5, 6, 7, 8, 9, 10}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto unfolded = sprout::fit::unfold_n(
|
||||
arr1,
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 4>{{1, 2, 4, 8}}
|
||||
));
|
||||
}
|
||||
// 生成
|
||||
// 範囲の切り出し
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto unfolded = sprout::unfold_n(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 6>{{1, 2, 4, 8, 7, 8}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(unfolded),
|
||||
array<int, 10>{{1, 2, 1, 2, 4, 8, 7, 8, 9, 10}}
|
||||
));
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto unfolded = sprout::fit::unfold_n(
|
||||
sprout::sub(arr1, 2, 8),
|
||||
4,
|
||||
testspr::x2<int>(),
|
||||
1
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
unfolded,
|
||||
array<int, 4>{{1, 2, 4, 8}}
|
||||
));
|
||||
TESTSPR_BOTH_ASSERT(testspr::equal(
|
||||
sprout::get_internal(unfolded),
|
||||
array<int, 10>{{1, 2, 1, 2, 4, 8, 7, 8, 9, 10}}
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_unfold_n_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_UNFOLD_N_CPP
|
Loading…
Add table
Add a link
Reference in a new issue