fix recursion depth: includes

This commit is contained in:
bolero-MURAKAMI 2012-12-15 23:48:52 +09:00
parent eea1c2bbc1
commit 0201107eec
14 changed files with 442 additions and 71 deletions

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_BINARY_SEARCH_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_BINARY_SEARCH_CPP
#include <sprout/algorithm/binary_search.hpp>
#include <sprout/array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_binary_search_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 7, 7, 10}};
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search(
sprout::begin(arr1),
sprout::end(arr1),
7
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
7,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_binary_search_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_BINARY_SEARCH_CPP

View file

@ -0,0 +1,45 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_EQUAL_RANGE_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_EQUAL_RANGE_CPP
#include <sprout/algorithm/equal_range.hpp>
#include <sprout/array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_equal_range_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 7, 7, 10}};
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range(
sprout::begin(arr1),
sprout::end(arr1),
7
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 6);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr1) + 9);
TESTSPR_BOTH_ASSERT(found.second - found.first == 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
7,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(found.first == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second == sprout::begin(arr1) + 5);
TESTSPR_BOTH_ASSERT(found.second - found.first == 0);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_equal_range_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_EQUAL_RANGE_CPP

View file

@ -12,7 +12,7 @@ namespace testspr {
{
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, 3>{{4, 5, 6}};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 3>{{11, 12 ,13}};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 3>{{11, 12, 13}};
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::find_first_of(

View file

@ -0,0 +1,103 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_INCLUDES_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_INCLUDES_CPP
#include <sprout/algorithm/includes.hpp>
#include <sprout/array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_includes_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, 3>{{4, 5, 6}};
SPROUT_STATIC_CONSTEXPR auto arr3 = array<int, 3>{{1, 2, 12}};
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr2),
sprout::end(arr2)
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr3),
sprout::end(arr3)
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
sprout::begin(arr2),
sprout::end(arr2)
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
sprout::begin(arr3),
sprout::end(arr3)
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr2),
sprout::end(arr2),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::end(arr1),
sprout::begin(arr3),
sprout::end(arr3),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
sprout::begin(arr2),
sprout::end(arr2),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::includes(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
sprout::begin(arr3),
sprout::end(arr3),
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(!result);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_includes_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_INCLUDES_CPP

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_LOWER_BOUND_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_LOWER_BOUND_CPP
#include <sprout/algorithm/lower_bound.hpp>
#include <sprout/array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_lower_bound_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 7, 7, 10}};
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound(
sprout::begin(arr1),
sprout::end(arr1),
7
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 6);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
7,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_lower_bound_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_LOWER_BOUND_CPP

View file

@ -27,6 +27,11 @@
#include "./partition_point.cpp"
#include "./is_sorted.cpp"
#include "./is_sorted_until.cpp"
#include "./lower_bound.cpp"
#include "./upper_bound.cpp"
#include "./equal_range.cpp"
#include "./binary_search.cpp"
#include "./includes.cpp"
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_ALGORITHM_TEST_NON_MODIFYIING_CPP
# undef TESTSPR_CPP_INCLUDE
@ -55,6 +60,11 @@ namespace testspr {
testspr::algorithm_partition_point_test();
testspr::algorithm_is_sorted_test();
testspr::algorithm_is_sorted_until_test();
testspr::algorithm_lower_bound_test();
testspr::algorithm_upper_bound_test();
testspr::algorithm_equal_range_test();
testspr::algorithm_binary_search_test();
testspr::algorithm_includes_test();
}
} // namespace testspr

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_LIBS_ALGORITHM_TEST_UPPER_BOUND_CPP
#define SPROUT_LIBS_ALGORITHM_TEST_UPPER_BOUND_CPP
#include <sprout/algorithm/upper_bound.hpp>
#include <sprout/array.hpp>
#include <sprout/container.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void algorithm_upper_bound_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR auto arr1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 7, 7, 10}};
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound(
sprout::begin(arr1),
sprout::end(arr1),
7
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 9);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound(
sprout::begin(arr1),
sprout::begin(arr1) + 5,
7,
testspr::less<int>()
);
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::algorithm_upper_bound_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_ALGORITHM_TEST_UPPER_BOUND_CPP