mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add some algorithm test
This commit is contained in:
parent
bc04943aaa
commit
570b834367
10 changed files with 255 additions and 0 deletions
47
libs/algorithm/test/clamp.cpp
Normal file
47
libs/algorithm/test/clamp.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#ifndef SPROUT_LIBS_ALGORITHM_TEST_CLAMP_CPP
|
||||||
|
#define SPROUT_LIBS_ALGORITHM_TEST_CLAMP_CPP
|
||||||
|
|
||||||
|
#include <sprout/algorithm/clamp.hpp>
|
||||||
|
#include <sprout/array.hpp>
|
||||||
|
#include <testspr/tools.hpp>
|
||||||
|
|
||||||
|
namespace testspr {
|
||||||
|
static void algorithm_clamp_test() {
|
||||||
|
using namespace sprout;
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 2>{{4, 7}};
|
||||||
|
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::clamp(
|
||||||
|
0,
|
||||||
|
arr1[0],
|
||||||
|
arr1[1]
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(result == arr1[0]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::clamp(
|
||||||
|
10,
|
||||||
|
arr1[0],
|
||||||
|
arr1[1]
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(result == arr1[1]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::clamp(
|
||||||
|
5,
|
||||||
|
arr1[0],
|
||||||
|
arr1[1]
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(result == 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace testspr
|
||||||
|
|
||||||
|
#ifndef TESTSPR_CPP_INCLUDE
|
||||||
|
# define TESTSPR_TEST_FUNCTION testspr::algorithm_clamp_test
|
||||||
|
# include <testspr/include_main.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_CLAMP_CPP
|
38
libs/algorithm/test/is_decreasing.cpp
Normal file
38
libs/algorithm/test/is_decreasing.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_DECREASING_CPP
|
||||||
|
#define SPROUT_LIBS_ALGORITHM_TEST_IS_DECREASING_CPP
|
||||||
|
|
||||||
|
#include <sprout/algorithm/is_decreasing.hpp>
|
||||||
|
#include <sprout/array.hpp>
|
||||||
|
#include <sprout/container.hpp>
|
||||||
|
#include <testspr/tools.hpp>
|
||||||
|
|
||||||
|
namespace testspr {
|
||||||
|
static void algorithm_is_decreasing_test() {
|
||||||
|
using namespace sprout;
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{10, 8, 6, 4, 2, 9, 7, 5, 3, 1}};
|
||||||
|
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_decreasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::end(arr1)
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_decreasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::begin(arr1) + 5
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace testspr
|
||||||
|
|
||||||
|
#ifndef TESTSPR_CPP_INCLUDE
|
||||||
|
# define TESTSPR_TEST_FUNCTION testspr::algorithm_is_decreasing_test
|
||||||
|
# include <testspr/include_main.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_DECREASING_CPP
|
38
libs/algorithm/test/is_increasing.cpp
Normal file
38
libs/algorithm/test/is_increasing.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_INCREASING_CPP
|
||||||
|
#define SPROUT_LIBS_ALGORITHM_TEST_IS_INCREASING_CPP
|
||||||
|
|
||||||
|
#include <sprout/algorithm/is_increasing.hpp>
|
||||||
|
#include <sprout/array.hpp>
|
||||||
|
#include <sprout/container.hpp>
|
||||||
|
#include <testspr/tools.hpp>
|
||||||
|
|
||||||
|
namespace testspr {
|
||||||
|
static void algorithm_is_increasing_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_increasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::end(arr1)
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_increasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::begin(arr1) + 5
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace testspr
|
||||||
|
|
||||||
|
#ifndef TESTSPR_CPP_INCLUDE
|
||||||
|
# define TESTSPR_TEST_FUNCTION testspr::algorithm_is_increasing_test
|
||||||
|
# include <testspr/include_main.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_INCREASING_CPP
|
53
libs/algorithm/test/is_strictly_decreasing.cpp
Normal file
53
libs/algorithm/test/is_strictly_decreasing.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_STRICTLY_DECREASING_CPP
|
||||||
|
#define SPROUT_LIBS_ALGORITHM_TEST_IS_STRICTLY_DECREASING_CPP
|
||||||
|
|
||||||
|
#include <sprout/algorithm/is_strictly_decreasing.hpp>
|
||||||
|
#include <sprout/array.hpp>
|
||||||
|
#include <sprout/container.hpp>
|
||||||
|
#include <testspr/tools.hpp>
|
||||||
|
|
||||||
|
namespace testspr {
|
||||||
|
static void algorithm_is_strictly_decreasing_test() {
|
||||||
|
using namespace sprout;
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{10, 8, 6, 4, 2, 9, 7, 5, 3, 1}};
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto arr2 = array<int, 10>{{10, 10, 6, 4, 2, 9, 7, 5, 1, 1}};
|
||||||
|
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_decreasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::end(arr1)
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_decreasing(
|
||||||
|
sprout::begin(arr2),
|
||||||
|
sprout::end(arr2)
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_decreasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::begin(arr1) + 5
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_decreasing(
|
||||||
|
sprout::begin(arr2),
|
||||||
|
sprout::begin(arr2) + 5
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace testspr
|
||||||
|
|
||||||
|
#ifndef TESTSPR_CPP_INCLUDE
|
||||||
|
# define TESTSPR_TEST_FUNCTION testspr::algorithm_is_strictly_decreasing_test
|
||||||
|
# include <testspr/include_main.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_STRICTLY_DECREASING_CPP
|
53
libs/algorithm/test/is_strictly_increasing.cpp
Normal file
53
libs/algorithm/test/is_strictly_increasing.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_STRICTLY_INCREASING_CPP
|
||||||
|
#define SPROUT_LIBS_ALGORITHM_TEST_IS_STRICTLY_INCREASING_CPP
|
||||||
|
|
||||||
|
#include <sprout/algorithm/is_strictly_increasing.hpp>
|
||||||
|
#include <sprout/array.hpp>
|
||||||
|
#include <sprout/container.hpp>
|
||||||
|
#include <testspr/tools.hpp>
|
||||||
|
|
||||||
|
namespace testspr {
|
||||||
|
static void algorithm_is_strictly_increasing_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 arr2 = array<int, 10>{{1, 1, 5, 7, 9, 2, 4, 6, 10, 10}};
|
||||||
|
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_increasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::end(arr1)
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_increasing(
|
||||||
|
sprout::begin(arr2),
|
||||||
|
sprout::end(arr2)
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_increasing(
|
||||||
|
sprout::begin(arr1),
|
||||||
|
sprout::begin(arr1) + 5
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(result);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_strictly_increasing(
|
||||||
|
sprout::begin(arr2),
|
||||||
|
sprout::begin(arr2) + 5
|
||||||
|
);
|
||||||
|
TESTSPR_BOTH_ASSERT(!result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace testspr
|
||||||
|
|
||||||
|
#ifndef TESTSPR_CPP_INCLUDE
|
||||||
|
# define TESTSPR_TEST_FUNCTION testspr::algorithm_is_strictly_increasing_test
|
||||||
|
# include <testspr/include_main.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_IS_STRICTLY_INCREASING_CPP
|
|
@ -45,6 +45,11 @@
|
||||||
#include "./any_of_equal.cpp"
|
#include "./any_of_equal.cpp"
|
||||||
#include "./none_of_equal.cpp"
|
#include "./none_of_equal.cpp"
|
||||||
#include "./one_of_equal.cpp"
|
#include "./one_of_equal.cpp"
|
||||||
|
#include "./is_increasing.cpp"
|
||||||
|
#include "./is_decreasing.cpp"
|
||||||
|
#include "./is_strictly_increasing.cpp"
|
||||||
|
#include "./is_strictly_decreasing.cpp"
|
||||||
|
#include "./clamp.cpp"
|
||||||
|
|
||||||
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
|
||||||
# undef TESTSPR_CPP_INCLUDE
|
# undef TESTSPR_CPP_INCLUDE
|
||||||
|
@ -91,6 +96,11 @@ namespace testspr {
|
||||||
testspr::algorithm_any_of_equal_test();
|
testspr::algorithm_any_of_equal_test();
|
||||||
testspr::algorithm_none_of_equal_test();
|
testspr::algorithm_none_of_equal_test();
|
||||||
testspr::algorithm_one_of_equal_test();
|
testspr::algorithm_one_of_equal_test();
|
||||||
|
testspr::algorithm_is_increasing_test();
|
||||||
|
testspr::algorithm_is_decreasing_test();
|
||||||
|
testspr::algorithm_is_strictly_increasing_test();
|
||||||
|
testspr::algorithm_is_strictly_decreasing_test();
|
||||||
|
testspr::algorithm_clamp_test();
|
||||||
}
|
}
|
||||||
} // namespace testspr
|
} // namespace testspr
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// is_decreasing
|
// is_decreasing
|
||||||
//
|
//
|
||||||
|
// recursion depth:
|
||||||
|
// [first, last) is RandomAccessIterator -> O(log N)
|
||||||
|
// otherwise -> O(N)
|
||||||
|
//
|
||||||
template<typename ForwardIterator>
|
template<typename ForwardIterator>
|
||||||
inline SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_decreasing(ForwardIterator first, ForwardIterator last) {
|
is_decreasing(ForwardIterator first, ForwardIterator last) {
|
||||||
|
|
|
@ -10,6 +10,10 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// is_increasing
|
// is_increasing
|
||||||
//
|
//
|
||||||
|
// recursion depth:
|
||||||
|
// [first, last) is RandomAccessIterator -> O(log N)
|
||||||
|
// otherwise -> O(N)
|
||||||
|
//
|
||||||
template<typename ForwardIterator>
|
template<typename ForwardIterator>
|
||||||
inline SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_increasing(ForwardIterator first, ForwardIterator last) {
|
is_increasing(ForwardIterator first, ForwardIterator last) {
|
||||||
|
|
|
@ -10,6 +10,10 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// is_strictly_decreasing
|
// is_strictly_decreasing
|
||||||
//
|
//
|
||||||
|
// recursion depth:
|
||||||
|
// [first, last) is RandomAccessIterator -> O(log N)
|
||||||
|
// otherwise -> O(N)
|
||||||
|
//
|
||||||
template<typename ForwardIterator>
|
template<typename ForwardIterator>
|
||||||
inline SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_strictly_decreasing(ForwardIterator first, ForwardIterator last) {
|
is_strictly_decreasing(ForwardIterator first, ForwardIterator last) {
|
||||||
|
|
|
@ -10,6 +10,10 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
// is_strictly_increasing
|
// is_strictly_increasing
|
||||||
//
|
//
|
||||||
|
// recursion depth:
|
||||||
|
// [first, last) is RandomAccessIterator -> O(log N)
|
||||||
|
// otherwise -> O(N)
|
||||||
|
//
|
||||||
template<typename ForwardIterator>
|
template<typename ForwardIterator>
|
||||||
inline SPROUT_CONSTEXPR bool
|
inline SPROUT_CONSTEXPR bool
|
||||||
is_strictly_increasing(ForwardIterator first, ForwardIterator last) {
|
is_strictly_increasing(ForwardIterator first, ForwardIterator last) {
|
||||||
|
|
Loading…
Reference in a new issue