]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/rotate.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / range / test / algorithm_test / rotate.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/rotate.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, class Iterator>
28 void test_rotate_impl(Container& cont, Iterator where_it)
29 {
30 Container reference(cont);
31 Container test(cont);
32
33 Iterator reference_where_it = reference.begin();
34 std::advance(reference_where_it,
35 std::distance(cont.begin(), where_it));
36
37 std::rotate(reference.begin(), reference_where_it, reference.end());
38
39 Iterator test_where_it = test.begin();
40 std::advance(test_where_it,
41 std::distance(cont.begin(), where_it));
42
43 boost::rotate(test, test_where_it);
44
45 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
46 test.begin(), test.end() );
47
48 test = cont;
49 test_where_it = test.begin();
50 std::advance(test_where_it,
51 std::distance(cont.begin(), where_it));
52
53 boost::rotate(boost::make_iterator_range(test), test_where_it);
54
55 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
56 test.begin(), test.end() );
57 }
58
59 template<class Container>
60 void test_rotate_impl(Container& cont)
61 {
62 typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
63
64 iterator_t last = cont.end();
65 for (iterator_t it = cont.begin(); it != last; ++it)
66 {
67 test_rotate_impl(cont, it);
68 }
69 }
70
71 template<class Container>
72 void test_rotate_impl()
73 {
74 using namespace boost::assign;
75
76 Container cont;
77 test_rotate_impl(cont);
78
79 cont.clear();
80 cont += 1;
81 test_rotate_impl(cont);
82
83 cont.clear();
84 cont += 1,2,3,4,5,6,7,8,9;
85 test_rotate_impl(cont);
86 }
87
88 void test_rotate()
89 {
90 test_rotate_impl< std::vector<int> >();
91 test_rotate_impl< std::list<int> >();
92 test_rotate_impl< std::deque<int> >();
93 }
94 }
95 }
96
97
98 boost::unit_test::test_suite*
99 init_unit_test_suite(int argc, char* argv[])
100 {
101 boost::unit_test::test_suite* test
102 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.rotate" );
103
104 test->add( BOOST_TEST_CASE( &boost::test_rotate ) );
105
106 return test;
107 }