mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
add test: some algorithms
This commit is contained in:
parent
e2b207d3be
commit
830fc27394
8 changed files with 176 additions and 12 deletions
|
@ -29,6 +29,46 @@ namespace testspr {
|
|||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::end(arr1)),
|
||||
7
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::end(arr1)),
|
||||
7
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(result);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::binary_search(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(!result);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <sprout/algorithm/equal_range.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <sprout/iterator.hpp>
|
||||
#include <testspr/tools.hpp>
|
||||
|
||||
namespace testspr {
|
||||
|
@ -20,7 +21,7 @@ namespace testspr {
|
|||
);
|
||||
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);
|
||||
TESTSPR_BOTH_ASSERT(sprout::distance(found.first, found.second) == 3);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range(
|
||||
|
@ -31,8 +32,54 @@ namespace testspr {
|
|||
);
|
||||
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);
|
||||
TESTSPR_BOTH_ASSERT(sprout::distance(found.first, found.second) == 0);
|
||||
}
|
||||
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::end(arr1)),
|
||||
7
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 6);
|
||||
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 9);
|
||||
TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 3);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
|
||||
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 5);
|
||||
TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 0);
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::end(arr1)),
|
||||
7
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 6);
|
||||
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 9);
|
||||
TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 3);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::equal_range(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
);
|
||||
TESTSPR_BOTH_ASSERT(found.first.base() == sprout::begin(arr1) + 5);
|
||||
TESTSPR_BOTH_ASSERT(found.second.base() == sprout::begin(arr1) + 5);
|
||||
TESTSPR_BOTH_ASSERT(sprout::distance(found.first.base(), found.second.base()) == 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
|
|
@ -29,6 +29,44 @@ namespace testspr {
|
|||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::end(arr1)),
|
||||
7
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 6);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::end(arr1)),
|
||||
7
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 6);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::lower_bound(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
|
|
@ -29,6 +29,44 @@ namespace testspr {
|
|||
);
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::end(arr1)),
|
||||
7
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 9);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound(
|
||||
testspr::reduct_forward(sprout::begin(arr1)),
|
||||
testspr::reduct_forward(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::end(arr1)),
|
||||
7
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 9);
|
||||
}
|
||||
{
|
||||
SPROUT_STATIC_CONSTEXPR auto found = sprout::upper_bound(
|
||||
testspr::reduct_random_access(sprout::begin(arr1)),
|
||||
testspr::reduct_random_access(sprout::begin(arr1) + 5),
|
||||
7,
|
||||
testspr::less<int>()
|
||||
).base();
|
||||
TESTSPR_BOTH_ASSERT(found == sprout::begin(arr1) + 5);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace testspr
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SPROUT_ALGORITHM_BINARY_SEARCH_HPP
|
||||
#define SPROUT_ALGORITHM_BINARY_SEARCH_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/lower_bound.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
@ -17,8 +18,7 @@ namespace sprout {
|
|||
// 25.4.3.4 binary_search
|
||||
//
|
||||
// recursion depth:
|
||||
// [first, last) is RandomAccessIterator -> O(log N)
|
||||
// otherwise -> O(N)
|
||||
// O(log N)
|
||||
//
|
||||
template<typename ForwardIterator, typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SPROUT_ALGORITHM_EQUAL_RANGE_HPP
|
||||
#define SPROUT_ALGORITHM_EQUAL_RANGE_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/algorithm/lower_bound.hpp>
|
||||
#include <sprout/algorithm/upper_bound.hpp>
|
||||
|
@ -13,13 +14,15 @@ namespace sprout {
|
|||
// 25.4.3.3 equal_range
|
||||
//
|
||||
// recursion depth:
|
||||
// [first, last) is RandomAccessIterator -> O(log N)
|
||||
// otherwise -> O(N)
|
||||
// O(log N)
|
||||
//
|
||||
template<typename ForwardIterator, typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR pair<ForwardIterator, ForwardIterator>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
|
||||
equal_range(ForwardIterator first, ForwardIterator last, T const& value, Compare comp) {
|
||||
return {sprout::lower_bound(first, last, value, comp), sprout::upper_bound(first, last, value, comp)};
|
||||
return sprout::pair<ForwardIterator, ForwardIterator>{
|
||||
sprout::lower_bound(first, last, value, comp),
|
||||
sprout::upper_bound(first, last, value, comp)
|
||||
};
|
||||
}
|
||||
|
||||
template<typename ForwardIterator, typename T>
|
||||
|
|
|
@ -12,8 +12,7 @@ namespace sprout {
|
|||
// 25.4.3.1 lower_bound
|
||||
//
|
||||
// recursion depth:
|
||||
// [first, last) is RandomAccessIterator -> O(log N)
|
||||
// otherwise -> O(N)
|
||||
// O(log N)
|
||||
//
|
||||
template<typename ForwardIterator, typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
|
|
|
@ -12,8 +12,7 @@ namespace sprout {
|
|||
// 25.4.3.2 upper_bound
|
||||
//
|
||||
// recursion depth:
|
||||
// [first, last) is RandomAccessIterator -> O(log N)
|
||||
// otherwise -> O(N)
|
||||
// O(log N)
|
||||
//
|
||||
template<typename ForwardIterator, typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
|
|
Loading…
Reference in a new issue