1 | // Boost.Range library |
---|---|
2 | // |
3 | // Copyright Neil Groves 2010. 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/algorithm_ext/copy_n.hpp> |
12 | |
13 | #include <boost/test/test_tools.hpp> |
14 | #include <boost/test/unit_test.hpp> |
15 | |
16 | #include <boost/range/iterator.hpp> |
17 | #include <algorithm> |
18 | #include <list> |
19 | #include <vector> |
20 | |
21 | namespace |
22 | { |
23 | template< class Container > |
24 | void test_copy_n_impl() |
25 | { |
26 | std::vector<std::size_t> source; |
27 | for (std::size_t i = 0; i < 10; ++i) |
28 | source.push_back(x: i); |
29 | |
30 | for (std::size_t k = 0; k < 10; ++k) |
31 | { |
32 | std::vector<std::size_t> reference; |
33 | for (std::size_t j = 0; j < k; ++j) |
34 | reference.push_back(x: j); |
35 | |
36 | Container test; |
37 | boost::copy_n(source, k, std::back_inserter(test)); |
38 | |
39 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
40 | test.begin(), test.end() ); |
41 | } |
42 | } |
43 | |
44 | void test_copy_n() |
45 | { |
46 | test_copy_n_impl< std::vector<std::size_t> >(); |
47 | test_copy_n_impl< std::list<std::size_t> >(); |
48 | } |
49 | } |
50 | |
51 | boost::unit_test::test_suite* |
52 | init_unit_test_suite(int argc, char* argv[]) |
53 | { |
54 | boost::unit_test::test_suite* test |
55 | = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.copy_n"); |
56 | |
57 | test->add( BOOST_TEST_CASE( &test_copy_n ) ); |
58 | |
59 | return test; |
60 | } |
61 |