mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
fix testspr
This commit is contained in:
parent
67902b8643
commit
29b7bc7c06
3 changed files with 177 additions and 129 deletions
|
@ -1,107 +1,12 @@
|
|||
#ifndef TESTSPR_SPROUT_ALGORITHM_HPP
|
||||
#define TESTSPR_SPROUT_ALGORITHM_HPP
|
||||
|
||||
#include <testspr/sprout/algorithm/copy.hpp>
|
||||
#include <testspr/sprout/algorithm/copy_n.hpp>
|
||||
#include <testspr/sprout/algorithm/copy_if.hpp>
|
||||
#include <testspr/sprout/algorithm/copy_backward.hpp>
|
||||
#include <testspr/sprout/algorithm/transform.hpp>
|
||||
#include <testspr/sprout/algorithm/replace.hpp>
|
||||
#include <testspr/sprout/algorithm/replace_if.hpp>
|
||||
#include <testspr/sprout/algorithm/replace_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/replace_copy_if.hpp>
|
||||
#include <testspr/sprout/algorithm/fill.hpp>
|
||||
#include <testspr/sprout/algorithm/fill_n.hpp>
|
||||
#include <testspr/sprout/algorithm/generate.hpp>
|
||||
#include <testspr/sprout/algorithm/generate_n.hpp>
|
||||
#include <testspr/sprout/algorithm/remove.hpp>
|
||||
#include <testspr/sprout/algorithm/remove_if.hpp>
|
||||
#include <testspr/sprout/algorithm/remove_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/remove_copy_if.hpp>
|
||||
#include <testspr/sprout/algorithm/unique.hpp>
|
||||
#include <testspr/sprout/algorithm/unique_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/reverse.hpp>
|
||||
#include <testspr/sprout/algorithm/reverse_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/rotate.hpp>
|
||||
#include <testspr/sprout/algorithm/rotate_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/shuffle.hpp>
|
||||
#include <testspr/sprout/algorithm/shuffle_result.hpp>
|
||||
#include <testspr/sprout/algorithm/partition.hpp>
|
||||
#include <testspr/sprout/algorithm/partition_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/stable_partition.hpp>
|
||||
#include <testspr/sprout/algorithm/stable_partition_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/sort.hpp>
|
||||
#include <testspr/sprout/algorithm/stable_sort.hpp>
|
||||
#include <testspr/sprout/algorithm/partial_sort.hpp>
|
||||
#include <testspr/sprout/algorithm/nth_element.hpp>
|
||||
#include <testspr/sprout/algorithm/merge.hpp>
|
||||
#include <testspr/sprout/algorithm/inplace_merge.hpp>
|
||||
#include <testspr/sprout/algorithm/set_union.hpp>
|
||||
#include <testspr/sprout/algorithm/set_intersection.hpp>
|
||||
#include <testspr/sprout/algorithm/set_difference.hpp>
|
||||
#include <testspr/sprout/algorithm/set_symmetric_difference.hpp>
|
||||
#include <testspr/sprout/algorithm/push_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/pop_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/make_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/make_partial_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/sort_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/swap_element.hpp>
|
||||
#include <testspr/sprout/algorithm/swap_element_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/bogo_sort.hpp>
|
||||
#include <testspr/sprout/algorithm/bogo_sort_result.hpp>
|
||||
#include <testspr/sprout/algorithm/modifying.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_test() {
|
||||
testspr::algorithm_copy_test();
|
||||
testspr::algorithm_copy_n_test();
|
||||
testspr::algorithm_copy_if_test();
|
||||
testspr::algorithm_copy_backward_test();
|
||||
testspr::algorithm_transform_test();
|
||||
testspr::algorithm_replace_test();
|
||||
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_remove_test();
|
||||
testspr::algorithm_remove_if_test();
|
||||
testspr::algorithm_remove_copy_test();
|
||||
testspr::algorithm_remove_copy_if_test();
|
||||
testspr::algorithm_unique_test();
|
||||
testspr::algorithm_unique_copy_test();
|
||||
testspr::algorithm_reverse_test();
|
||||
testspr::algorithm_reverse_copy_test();
|
||||
testspr::algorithm_rotate_test();
|
||||
testspr::algorithm_rotate_copy_test();
|
||||
testspr::algorithm_shuffle_test();
|
||||
testspr::algorithm_shuffle_result_test();
|
||||
testspr::algorithm_partition_test();
|
||||
testspr::algorithm_partition_copy_test();
|
||||
testspr::algorithm_stable_partition_test();
|
||||
testspr::algorithm_stable_partition_copy_test();
|
||||
testspr::algorithm_sort_test();
|
||||
testspr::algorithm_stable_sort_test();
|
||||
testspr::algorithm_partial_sort_test();
|
||||
testspr::algorithm_nth_element_test();
|
||||
testspr::algorithm_merge_test();
|
||||
testspr::algorithm_inplace_merge_test();
|
||||
testspr::algorithm_set_union_test();
|
||||
testspr::algorithm_set_intersection_test();
|
||||
testspr::algorithm_set_difference_test();
|
||||
testspr::algorithm_set_symmetric_difference_test();
|
||||
testspr::algorithm_push_heap_test();
|
||||
testspr::algorithm_pop_heap_test();
|
||||
testspr::algorithm_make_heap_test();
|
||||
testspr::algorithm_make_partial_heap_test();
|
||||
testspr::algorithm_sort_heap_test();
|
||||
testspr::algorithm_swap_element_test();
|
||||
testspr::algorithm_swap_element_copy_test();
|
||||
testspr::algorithm_bogo_sort_test();
|
||||
testspr::algorithm_bogo_sort_result_test();
|
||||
testspr::algorithm_modifying_test();
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_HPP
|
||||
|
||||
|
|
106
testspr/sprout/algorithm/modifying.hpp
Normal file
106
testspr/sprout/algorithm/modifying.hpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
#ifndef TESTSPR_SPROUT_ALGORITHM_MODIFYIING_HPP
|
||||
#define TESTSPR_SPROUT_ALGORITHM_MODIFYIING_HPP
|
||||
|
||||
#include <testspr/sprout/algorithm/copy.hpp>
|
||||
#include <testspr/sprout/algorithm/copy_n.hpp>
|
||||
#include <testspr/sprout/algorithm/copy_if.hpp>
|
||||
#include <testspr/sprout/algorithm/copy_backward.hpp>
|
||||
#include <testspr/sprout/algorithm/transform.hpp>
|
||||
#include <testspr/sprout/algorithm/replace.hpp>
|
||||
#include <testspr/sprout/algorithm/replace_if.hpp>
|
||||
#include <testspr/sprout/algorithm/replace_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/replace_copy_if.hpp>
|
||||
#include <testspr/sprout/algorithm/fill.hpp>
|
||||
#include <testspr/sprout/algorithm/fill_n.hpp>
|
||||
#include <testspr/sprout/algorithm/generate.hpp>
|
||||
#include <testspr/sprout/algorithm/generate_n.hpp>
|
||||
#include <testspr/sprout/algorithm/remove.hpp>
|
||||
#include <testspr/sprout/algorithm/remove_if.hpp>
|
||||
#include <testspr/sprout/algorithm/remove_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/remove_copy_if.hpp>
|
||||
#include <testspr/sprout/algorithm/unique.hpp>
|
||||
#include <testspr/sprout/algorithm/unique_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/reverse.hpp>
|
||||
#include <testspr/sprout/algorithm/reverse_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/rotate.hpp>
|
||||
#include <testspr/sprout/algorithm/rotate_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/shuffle.hpp>
|
||||
#include <testspr/sprout/algorithm/shuffle_result.hpp>
|
||||
#include <testspr/sprout/algorithm/partition.hpp>
|
||||
#include <testspr/sprout/algorithm/partition_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/stable_partition.hpp>
|
||||
#include <testspr/sprout/algorithm/stable_partition_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/sort.hpp>
|
||||
#include <testspr/sprout/algorithm/stable_sort.hpp>
|
||||
#include <testspr/sprout/algorithm/partial_sort.hpp>
|
||||
#include <testspr/sprout/algorithm/nth_element.hpp>
|
||||
#include <testspr/sprout/algorithm/merge.hpp>
|
||||
#include <testspr/sprout/algorithm/inplace_merge.hpp>
|
||||
#include <testspr/sprout/algorithm/set_union.hpp>
|
||||
#include <testspr/sprout/algorithm/set_intersection.hpp>
|
||||
#include <testspr/sprout/algorithm/set_difference.hpp>
|
||||
#include <testspr/sprout/algorithm/set_symmetric_difference.hpp>
|
||||
#include <testspr/sprout/algorithm/push_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/pop_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/make_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/make_partial_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/sort_heap.hpp>
|
||||
#include <testspr/sprout/algorithm/swap_element.hpp>
|
||||
#include <testspr/sprout/algorithm/swap_element_copy.hpp>
|
||||
#include <testspr/sprout/algorithm/bogo_sort.hpp>
|
||||
#include <testspr/sprout/algorithm/bogo_sort_result.hpp>
|
||||
|
||||
namespace testspr {
|
||||
static void algorithm_modifying_test() {
|
||||
testspr::algorithm_copy_test();
|
||||
testspr::algorithm_copy_n_test();
|
||||
testspr::algorithm_copy_if_test();
|
||||
testspr::algorithm_copy_backward_test();
|
||||
testspr::algorithm_transform_test();
|
||||
testspr::algorithm_replace_test();
|
||||
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_remove_test();
|
||||
testspr::algorithm_remove_if_test();
|
||||
testspr::algorithm_remove_copy_test();
|
||||
testspr::algorithm_remove_copy_if_test();
|
||||
testspr::algorithm_unique_test();
|
||||
testspr::algorithm_unique_copy_test();
|
||||
testspr::algorithm_reverse_test();
|
||||
testspr::algorithm_reverse_copy_test();
|
||||
testspr::algorithm_rotate_test();
|
||||
testspr::algorithm_rotate_copy_test();
|
||||
testspr::algorithm_shuffle_test();
|
||||
testspr::algorithm_shuffle_result_test();
|
||||
testspr::algorithm_partition_test();
|
||||
testspr::algorithm_partition_copy_test();
|
||||
testspr::algorithm_stable_partition_test();
|
||||
testspr::algorithm_stable_partition_copy_test();
|
||||
testspr::algorithm_sort_test();
|
||||
testspr::algorithm_stable_sort_test();
|
||||
testspr::algorithm_partial_sort_test();
|
||||
testspr::algorithm_nth_element_test();
|
||||
testspr::algorithm_merge_test();
|
||||
testspr::algorithm_inplace_merge_test();
|
||||
testspr::algorithm_set_union_test();
|
||||
testspr::algorithm_set_intersection_test();
|
||||
testspr::algorithm_set_difference_test();
|
||||
testspr::algorithm_set_symmetric_difference_test();
|
||||
testspr::algorithm_push_heap_test();
|
||||
testspr::algorithm_pop_heap_test();
|
||||
testspr::algorithm_make_heap_test();
|
||||
testspr::algorithm_make_partial_heap_test();
|
||||
testspr::algorithm_sort_heap_test();
|
||||
testspr::algorithm_swap_element_test();
|
||||
testspr::algorithm_swap_element_copy_test();
|
||||
testspr::algorithm_bogo_sort_test();
|
||||
testspr::algorithm_bogo_sort_result_test();
|
||||
}
|
||||
} // namespace testspr
|
||||
|
||||
#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MODIFYIING_HPP
|
|
@ -9,23 +9,13 @@
|
|||
# include <boost/serialization/static_warning.hpp>
|
||||
#endif
|
||||
|
||||
//
|
||||
// TESTSPR_PP_CAT
|
||||
//
|
||||
#define TESTSPR_PP_CAT(a, b) TESTSPR_PP_CAT_I(a, b)
|
||||
#define TESTSPR_PP_CAT_I(a, b) a ## b
|
||||
|
||||
//
|
||||
// TESTSPR_STATIC_ASSERT
|
||||
//
|
||||
#define TESTSPR_STATIC_ASSERT(expr) static_assert(expr, #expr)
|
||||
//
|
||||
// TESTSPR_ASSERT
|
||||
//
|
||||
#define TESTSPR_ASSERT(expr) assert(expr)
|
||||
//
|
||||
// TESTSPR_DOUBLE_ASSERT
|
||||
//
|
||||
#define TESTSPR_STATIC_ASSERT(expr) static_assert(expr, #expr)
|
||||
#define TESTSPR_ASSERT(expr) assert(expr)
|
||||
#define TESTSPR_DOUBLE_ASSERT(expr) TESTSPR_STATIC_ASSERT(expr); TESTSPR_ASSERT(expr)
|
||||
|
||||
//
|
||||
|
@ -39,15 +29,11 @@
|
|||
|
||||
//
|
||||
// TESTSPR_STATIC_UNCHECKED
|
||||
//
|
||||
#define TESTSPR_STATIC_UNCHECKED(expr) TESTSPR_STATIC_WARNING(expr)
|
||||
//
|
||||
// TESTSPR_UNCHECKED
|
||||
//
|
||||
#define TESTSPR_UNCHECKED(expr) (expr)
|
||||
//
|
||||
// TESTSPR_DOUBLE_UNCHECKED
|
||||
//
|
||||
#define TESTSPR_STATIC_UNCHECKED(expr) TESTSPR_STATIC_WARNING(expr)
|
||||
#define TESTSPR_UNCHECKED(expr) (expr)
|
||||
#define TESTSPR_DOUBLE_UNCHECKED(expr) TESTSPR_STATIC_UNCHECKED(expr); TESTSPR_UNCHECKED(expr)
|
||||
|
||||
namespace testspr {
|
||||
|
@ -56,6 +42,10 @@ namespace testspr {
|
|||
//
|
||||
template<typename T>
|
||||
struct is_even {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 == 0; }
|
||||
};
|
||||
//
|
||||
|
@ -63,6 +53,10 @@ namespace testspr {
|
|||
//
|
||||
template<typename T>
|
||||
struct is_odd {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 != 0; }
|
||||
};
|
||||
|
||||
|
@ -71,6 +65,11 @@ namespace testspr {
|
|||
//
|
||||
template<typename T>
|
||||
struct less {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs < rhs; }
|
||||
};
|
||||
//
|
||||
|
@ -78,6 +77,11 @@ namespace testspr {
|
|||
//
|
||||
template<typename T>
|
||||
struct greater {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs > rhs; }
|
||||
};
|
||||
//
|
||||
|
@ -85,6 +89,11 @@ namespace testspr {
|
|||
//
|
||||
template<typename T>
|
||||
struct equal_to {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs == rhs; }
|
||||
};
|
||||
//
|
||||
|
@ -92,6 +101,11 @@ namespace testspr {
|
|||
//
|
||||
template<typename T, T mod>
|
||||
struct mod_less {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs % mod < rhs % mod; }
|
||||
};
|
||||
|
||||
|
@ -100,22 +114,32 @@ namespace testspr {
|
|||
//
|
||||
template<typename T>
|
||||
struct x2 {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T operator()(T const& t) const { return t + t; }
|
||||
};
|
||||
|
||||
//
|
||||
// plus
|
||||
//
|
||||
template<typename T>
|
||||
struct plus {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T operator()(T const& lhs, T const& rhs) const { return lhs + rhs; }
|
||||
};
|
||||
|
||||
//
|
||||
// distance
|
||||
//
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type
|
||||
distance(Iterator first, Iterator last) {
|
||||
template<typename InputIterator>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
||||
distance(InputIterator first, InputIterator last) {
|
||||
return first == last ? 0
|
||||
: 1 + testspr::distance(first + 1, last)
|
||||
;
|
||||
|
@ -124,8 +148,8 @@ namespace testspr {
|
|||
//
|
||||
// equal
|
||||
//
|
||||
template<typename Iterator1, typename Iterator2>
|
||||
SPROUT_CONSTEXPR bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) {
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2) {
|
||||
return first1 == last1 ? first2 == last2
|
||||
: first2 == last2 ? false
|
||||
: !(*first1 == *first2) ? false
|
||||
|
@ -140,8 +164,8 @@ namespace testspr {
|
|||
//
|
||||
// is_found
|
||||
//
|
||||
template<class Iterator, typename T>
|
||||
SPROUT_CONSTEXPR bool is_found(Iterator first, Iterator last, T const& value) {
|
||||
template<class InputIterator, typename T>
|
||||
SPROUT_CONSTEXPR bool is_found(InputIterator first, InputIterator last, T const& value) {
|
||||
return first == last ? false
|
||||
: *first == value ? true
|
||||
: testspr::is_found(first + 1, last, value)
|
||||
|
@ -155,9 +179,9 @@ namespace testspr {
|
|||
//
|
||||
// count
|
||||
//
|
||||
template<typename Iterator, typename T>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<Iterator>::difference_type
|
||||
count(Iterator first, Iterator last, T const& value) {
|
||||
template<typename InputIterator, typename T>
|
||||
SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
||||
count(InputIterator first, InputIterator last, T const& value) {
|
||||
return first == last ? 0
|
||||
: (*first == value ? 1 : 0) + testspr::count(first + 1, last, value)
|
||||
;
|
||||
|
@ -169,8 +193,15 @@ namespace testspr {
|
|||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename Iterator1, typename Iterator2>
|
||||
SPROUT_CONSTEXPR bool is_permutation_impl(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Iterator1 first1_, Iterator2 first2_)
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
SPROUT_CONSTEXPR bool is_permutation_impl(
|
||||
ForwardIterator1 first1,
|
||||
ForwardIterator1 last1,
|
||||
ForwardIterator2 first2,
|
||||
ForwardIterator2 last2,
|
||||
ForwardIterator1 first1_,
|
||||
ForwardIterator2 first2_
|
||||
)
|
||||
{
|
||||
return first1_ == last1 && first2_ == last2 ? true
|
||||
: testspr::count(first1, last1, *first1_) != testspr::count(first2, first2 + testspr::distance(first1, last1), *first1_) ? false
|
||||
|
@ -181,8 +212,14 @@ namespace testspr {
|
|||
//
|
||||
// is_permutation
|
||||
//
|
||||
template<typename Iterator1, typename Iterator2>
|
||||
SPROUT_CONSTEXPR bool is_permutation(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) {
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
SPROUT_CONSTEXPR bool is_permutation(
|
||||
ForwardIterator1 first1,
|
||||
ForwardIterator1 last1,
|
||||
ForwardIterator2 first2,
|
||||
ForwardIterator2 last2
|
||||
)
|
||||
{
|
||||
return testspr::detail::is_permutation_impl(first1, last1, first2, last2, first1, first2);
|
||||
}
|
||||
template<typename Range1, typename Range2>
|
||||
|
|
Loading…
Reference in a new issue