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/reverse_copy.hpp>
10
11#include <boost/test/test_tools.hpp>
12#include <boost/test/unit_test.hpp>
13
14#include <boost/assign.hpp>
15#include <algorithm>
16#include <functional>
17#include <list>
18#include <numeric>
19#include <deque>
20#include <vector>
21
22namespace
23{
24 template<class OutputIterator, class Value>
25 void test_append(OutputIterator out, Value value)
26 {
27 *out++ = value;
28 }
29
30 template<class Container>
31 void test_reverse_copy_impl(Container& cont)
32 {
33 typedef BOOST_DEDUCED_TYPENAME boost::range_value<Container>::type value_type;
34 std::vector<value_type> reference;
35 std::vector<value_type> test;
36
37 test_append(
38 std::reverse_copy(cont.begin(), cont.end(), std::back_inserter(reference)),
39 value_type()
40 );
41
42 test_append(
43 boost::reverse_copy(cont, std::back_inserter(test)),
44 value_type()
45 );
46
47 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
48 test.begin(), test.end() );
49
50 test.clear();
51
52 test_append(
53 boost::reverse_copy(boost::make_iterator_range(cont),
54 std::back_inserter(test)),
55 value_type()
56 );
57
58 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
59 test.begin(), test.end() );
60 }
61
62 template<class Container>
63 void test_reverse_copy_impl()
64 {
65 using namespace boost::assign;
66
67 Container cont;
68 test_reverse_copy_impl(cont);
69
70 cont.clear();
71 cont += 1;
72 test_reverse_copy_impl(cont);
73
74 cont.clear();
75 cont += 1,2,3,4,5,6,7,8,9;
76 test_reverse_copy_impl(cont);
77 }
78
79 void test_reverse_copy()
80 {
81 test_reverse_copy_impl< std::vector<int> >();
82 test_reverse_copy_impl< std::list<int> >();
83 test_reverse_copy_impl< std::deque<int> >();
84 }
85}
86
87boost::unit_test::test_suite*
88init_unit_test_suite(int argc, char* argv[])
89{
90 boost::unit_test::test_suite* test
91 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.reverse_copy" );
92
93 test->add( BOOST_TEST_CASE( &::test_reverse_copy ) );
94
95 return test;
96}
97

source code of boost/libs/range/test/algorithm_test/reverse_copy.cpp