]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/sort.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / range / test / algorithm_test / sort.cpp
1 // Copyright Neil Groves 2009. Use, modification and
2 // distribution is subject to the Boost Software License, Version
3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 //
6 //
7 // For more information, see http://www.boost.org/libs/range/
8 //
9 #include <boost/range/algorithm/sort.hpp>
10
11 #include <boost/test/test_tools.hpp>
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/assign.hpp>
15 #include <boost/bind.hpp>
16 #include <algorithm>
17 #include <functional>
18 #include <list>
19 #include <numeric>
20 #include <deque>
21 #include <vector>
22
23 namespace boost
24 {
25 namespace
26 {
27 template<class Container>
28 void test_sort_impl(Container& cont)
29 {
30 Container reference(cont);
31 Container test(cont);
32
33 boost::sort(test);
34 std::sort(reference.begin(), reference.end());
35
36 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
37 test.begin(), test.end() );
38
39 Container test2(cont);
40 boost::sort(boost::make_iterator_range(test2));
41 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
42 test2.begin(), test2.end() );
43 }
44
45 template<class Container, class BinaryPredicate>
46 void test_sort_impl(Container& cont, BinaryPredicate pred)
47 {
48 Container reference(cont);
49 Container test(cont);
50
51 boost::sort(test, pred);
52 std::sort(reference.begin(), reference.end(), pred);
53
54 BOOST_CHECK_EQUAL_COLLECTIONS(
55 reference.begin(), reference.end(),
56 test.begin(), test.end()
57 );
58
59 Container test2(cont);
60 boost::sort(boost::make_iterator_range(test2), pred);
61 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
62 test2.begin(), test2.end() );
63 }
64
65 template<class Container>
66 void test_sort_impl()
67 {
68 using namespace boost::assign;
69
70 Container cont;
71 test_sort_impl(cont);
72 test_sort_impl(cont, std::less<int>());
73 test_sort_impl(cont, std::greater<int>());
74
75 cont.clear();
76 cont += 1;
77 test_sort_impl(cont);
78 test_sort_impl(cont, std::less<int>());
79 test_sort_impl(cont, std::greater<int>());
80
81 cont.clear();
82 cont += 1,2,3,4,5,6,7,8,9;
83 test_sort_impl(cont);
84 test_sort_impl(cont, std::less<int>());
85 test_sort_impl(cont, std::greater<int>());
86 }
87
88 void test_sort()
89 {
90 test_sort_impl< std::vector<int> >();
91 test_sort_impl< std::deque<int> >();
92 }
93 }
94 }
95
96 boost::unit_test::test_suite*
97 init_unit_test_suite(int argc, char* argv[])
98 {
99 boost::unit_test::test_suite* test
100 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.sort" );
101
102 test->add( BOOST_TEST_CASE( &boost::test_sort ) );
103
104 return test;
105 }