mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-16 15:14:13 +00:00
fix rexursion depth: is_pertitioned, partition_point, is_sorted, is_sorted_until
This commit is contained in:
parent
d6914ddd72
commit
eea1c2bbc1
12 changed files with 410 additions and 50 deletions
56
libs/algorithm/test/is_partitioned.cpp
Normal file
56
libs/algorithm/test/is_partitioned.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_PERTITIONED_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_IS_PERTITIONED_CPP
|
||||
|
||||
#include <sprout/algorithm/is_partitioned.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_is_partitioned_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 result = sprout::is_partitioned(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::is_odd<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::is_odd<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_partitioned(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::less_than<int>(6)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_is_partitioned_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_PERTITIONED_CPP
|
54
libs/algorithm/test/is_sorted.cpp
Normal file
54
libs/algorithm/test/is_sorted.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_SORTED_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_IS_SORTED_CPP
|
||||
|
||||
#include <sprout/algorithm/is_sorted.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_is_sorted_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 result = sprout::is_sorted(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_is_sorted_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_SORTED_CPP
|
54
libs/algorithm/test/is_sorted_until.cpp
Normal file
54
libs/algorithm/test/is_sorted_until.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_SORTED_UNTIL_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_IS_SORTED_UNTIL_CPP
|
||||
|
||||
#include <sprout/algorithm/is_sorted_until.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_is_sorted_until_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 found = sprout::is_sorted_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1)
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::is_sorted_until(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_is_sorted_until_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_SORTED_UNTIL_CPP
|
|
@ -23,6 +23,10 @@
|
|||
#include "./is_permutation.cpp"
|
||||
#include "./search.cpp"
|
||||
#include "./search_n.cpp"
|
||||
#include "./is_partitioned.cpp"
|
||||
#include "./partition_point.cpp"
|
||||
#include "./is_sorted.cpp"
|
||||
#include "./is_sorted_until.cpp"
|
||||
|
||||
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
||||
# undef TESTSPR_CPP_INCLUDE
|
||||
|
@ -47,6 +51,10 @@ namespace testspr {
|
|||
testspr::algorithm_is_permutation_test();
|
||||
testspr::algorithm_search_test();
|
||||
testspr::algorithm_search_n_test();
|
||||
testspr::algorithm_is_partitioned_test();
|
||||
testspr::algorithm_partition_point_test();
|
||||
testspr::algorithm_is_sorted_test();
|
||||
testspr::algorithm_is_sorted_until_test();
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
|
|
40
libs/algorithm/test/partition_point.cpp
Normal file
40
libs/algorithm/test/partition_point.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef SPROUT_LIBS_ALGORITHM_TEST_PERTITION_POINT_CPP
|
||||
#define SPROUT_LIBS_ALGORITHM_TEST_PERTITION_POINT_CPP
|
||||
|
||||
#include <sprout/algorithm/partition_point.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_partition_point_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 found = sprout::partition_point(
|
||||
sprout::begin(arr1),
|
||||
sprout::end(arr1),
|
||||
testspr::is_odd<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::partition_point(
|
||||
sprout::begin(arr1),
|
||||
sprout::begin(arr1) + 5,
|
||||
testspr::is_odd<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#ifndef TESTSPR_CPP_INCLUDE
|
||||
# define TESTSPR_TEST_FUNCTION testspr::algorithm_partition_point_test
|
||||
# include <testspr/include_main.hpp>
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_PERTITION_POINT_CPP
|
Loading…
Add table
Add a link
Reference in a new issue