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/rotate.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
, class Iterator
>
28 void test_rotate_impl(Container
& cont
, Iterator where_it
)
30 Container
reference(cont
);
33 Iterator reference_where_it
= reference
.begin();
34 std::advance(reference_where_it
,
35 std::distance(cont
.begin(), where_it
));
37 std::rotate(reference
.begin(), reference_where_it
, reference
.end());
39 Iterator test_where_it
= test
.begin();
40 std::advance(test_where_it
,
41 std::distance(cont
.begin(), where_it
));
43 boost::rotate(test
, test_where_it
);
45 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
46 test
.begin(), test
.end() );
49 test_where_it
= test
.begin();
50 std::advance(test_where_it
,
51 std::distance(cont
.begin(), where_it
));
53 boost::rotate(boost::make_iterator_range(test
), test_where_it
);
55 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
56 test
.begin(), test
.end() );
59 template<class Container
>
60 void test_rotate_impl(Container
& cont
)
62 typedef BOOST_DEDUCED_TYPENAME range_iterator
<Container
>::type iterator_t
;
64 iterator_t last
= cont
.end();
65 for (iterator_t it
= cont
.begin(); it
!= last
; ++it
)
67 test_rotate_impl(cont
, it
);
71 template<class Container
>
72 void test_rotate_impl()
74 using namespace boost::assign
;
77 test_rotate_impl(cont
);
81 test_rotate_impl(cont
);
84 cont
+= 1,2,3,4,5,6,7,8,9;
85 test_rotate_impl(cont
);
90 test_rotate_impl
< std::vector
<int> >();
91 test_rotate_impl
< std::list
<int> >();
92 test_rotate_impl
< std::deque
<int> >();
98 boost::unit_test::test_suite
*
99 init_unit_test_suite(int argc
, char* argv
[])
101 boost::unit_test::test_suite
* test
102 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.rotate" );
104 test
->add( BOOST_TEST_CASE( &boost::test_rotate
) );