]>
git.proxmox.com Git - ceph.git/blob - 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)
7 // For more information, see http://www.boost.org/libs/range/
9 #include <boost/range/algorithm/sort.hpp>
11 #include <boost/test/test_tools.hpp>
12 #include <boost/test/unit_test.hpp>
14 #include <boost/assign.hpp>
15 #include <boost/bind.hpp>
27 template<class Container
>
28 void test_sort_impl(Container
& cont
)
30 Container
reference(cont
);
34 std::sort(reference
.begin(), reference
.end());
36 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
37 test
.begin(), test
.end() );
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() );
45 template<class Container
, class BinaryPredicate
>
46 void test_sort_impl(Container
& cont
, BinaryPredicate pred
)
48 Container
reference(cont
);
51 boost::sort(test
, pred
);
52 std::sort(reference
.begin(), reference
.end(), pred
);
54 BOOST_CHECK_EQUAL_COLLECTIONS(
55 reference
.begin(), reference
.end(),
56 test
.begin(), test
.end()
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() );
65 template<class Container
>
68 using namespace boost::assign
;
72 test_sort_impl(cont
, std::less
<int>());
73 test_sort_impl(cont
, std::greater
<int>());
78 test_sort_impl(cont
, std::less
<int>());
79 test_sort_impl(cont
, std::greater
<int>());
82 cont
+= 1,2,3,4,5,6,7,8,9;
84 test_sort_impl(cont
, std::less
<int>());
85 test_sort_impl(cont
, std::greater
<int>());
90 test_sort_impl
< std::vector
<int> >();
91 test_sort_impl
< std::deque
<int> >();
96 boost::unit_test::test_suite
*
97 init_unit_test_suite(int argc
, char* argv
[])
99 boost::unit_test::test_suite
* test
100 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.sort" );
102 test
->add( BOOST_TEST_CASE( &boost::test_sort
) );