1 | // Boost.Range library |
2 | // |
3 | // Copyright Neil Groves 2009. Use, modification and |
4 | // distribution is subject to the Boost Software License, Version |
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | // |
8 | // |
9 | // For more information, see http://www.boost.org/libs/range/ |
10 | // |
11 | #include <boost/range/adaptor/reversed.hpp> |
12 | |
13 | #include <boost/test/test_tools.hpp> |
14 | #include <boost/test/unit_test.hpp> |
15 | |
16 | #include <boost/assign.hpp> |
17 | #include <boost/range/algorithm_ext.hpp> |
18 | |
19 | #include <algorithm> |
20 | #include <list> |
21 | #include <set> |
22 | #include <vector> |
23 | |
24 | namespace boost |
25 | { |
26 | template< class Container > |
27 | void reversed_test_impl( Container& c ) |
28 | { |
29 | using namespace boost::adaptors; |
30 | |
31 | std::vector< int > test_result1; |
32 | boost::push_back(test_result1, c | reversed); |
33 | |
34 | std::vector< int > test_result2; |
35 | boost::push_back(test_result2, adaptors::reverse(c)); |
36 | |
37 | std::vector< int > reference( c.rbegin(), c.rend() ); |
38 | |
39 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
40 | test_result1.begin(), test_result1.end() ); |
41 | |
42 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
43 | test_result2.begin(), test_result2.end() ); |
44 | } |
45 | |
46 | template< class Container > |
47 | void reversed_test_impl() |
48 | { |
49 | using namespace boost::assign; |
50 | |
51 | Container c; |
52 | |
53 | // Test empty |
54 | reversed_test_impl(c); |
55 | |
56 | // Test one |
57 | c += 1; |
58 | reversed_test_impl(c); |
59 | |
60 | // Test many |
61 | c += 1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,5,6,7,8,9; |
62 | reversed_test_impl(c); |
63 | } |
64 | |
65 | void reversed_test() |
66 | { |
67 | reversed_test_impl< std::vector< int > >(); |
68 | reversed_test_impl< std::list< int > >(); |
69 | reversed_test_impl< std::set< int > >(); |
70 | reversed_test_impl< std::multiset< int > >(); |
71 | } |
72 | } |
73 | |
74 | |
75 | boost::unit_test::test_suite* |
76 | init_unit_test_suite(int argc, char* argv[]) |
77 | { |
78 | boost::unit_test::test_suite* test |
79 | = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.reversed" ); |
80 | |
81 | test->add( BOOST_TEST_CASE( &boost::reversed_test ) ); |
82 | |
83 | return test; |
84 | } |
85 | |