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 // Credits:
12 // awulkiew highlighted that this test was not successfully testing the
13 // algorithm.
14 //
15 #include <boost/range/algorithm/copy_backward.hpp>
16
17 #include <boost/test/test_tools.hpp>
18 #include <boost/test/unit_test.hpp>
19
20 #include <boost/assign.hpp>
21 #include <boost/range/iterator.hpp>
22 #include <algorithm>
23 #include <list>
24 #include <vector>
25
26 namespace boost_range_test
27 {
28 namespace
29 {
30 template<typename Container>
test_copy_backward_impl(std::size_t n)31 void test_copy_backward_impl(std::size_t n)
32 {
33 Container source;
34 typedef typename Container::value_type value_t;
35 for (std::size_t i = 0; i < n; ++i)
36 source.push_back(static_cast<value_t>(i));
37
38 std::vector<value_t> target(n);
39
40 typedef typename boost::range_iterator<
41 std::vector<value_t>
42 >::type iterator_t;
43
44 iterator_t it = boost::copy_backward(source, target.end());
45
46 BOOST_CHECK(it == target.begin());
47
48 BOOST_CHECK_EQUAL_COLLECTIONS(target.begin(), target.end(),
49 source.begin(), source.end());
50
51 BOOST_CHECK(it == boost::copy_backward(
52 boost::make_iterator_range(source), target.end()));
53
54 BOOST_CHECK_EQUAL_COLLECTIONS(target.begin(), target.end(),
55 source.begin(), source.end());
56 }
57
58 template<typename Container>
test_copy_backward_impl()59 void test_copy_backward_impl()
60 {
61 test_copy_backward_impl<Container>(0u);
62 test_copy_backward_impl<Container>(1u);
63 test_copy_backward_impl<Container>(100u);
64 }
65
test_copy_backward()66 void test_copy_backward()
67 {
68 test_copy_backward_impl<std::vector<int> >();
69 test_copy_backward_impl<std::list<int> >();
70 }
71 } // anonymous namespace
72 } // namespace boost_range_test
73
74
75 boost::unit_test::test_suite*
init_unit_test_suite(int,char * [])76 init_unit_test_suite(int, char*[])
77 {
78 boost::unit_test::test_suite* test
79 = BOOST_TEST_SUITE("RangeTestSuite.algorithm.copy_backward");
80
81 test->add(BOOST_TEST_CASE(&boost_range_test::test_copy_backward));
82
83 return test;
84 }
85