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/push_back.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 <boost/range/irange.hpp>
18 #include <algorithm>
19 #include <list>
20 #include <vector>
21
22 namespace
23 {
24 template< class Container >
test_push_back_impl(std::size_t n)25 void test_push_back_impl(std::size_t n)
26 {
27 Container reference;
28 for (std::size_t i = 0; i < n; ++i)
29 reference.push_back(i);
30
31 Container test;
32 boost::push_back(test, boost::irange<std::size_t>(0, n));
33
34 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
35 test.begin(), test.end() );
36
37 // Do it again to push onto non-empty container
38 for (std::size_t j = 0; j < n; ++j)
39 reference.push_back(j);
40
41 boost::push_back(test, boost::irange<std::size_t>(0, n));
42
43 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
44 test.begin(), test.end() );
45 }
46
47 template< class Container >
test_push_back_impl()48 void test_push_back_impl()
49 {
50 test_push_back_impl< Container >(0);
51 test_push_back_impl< Container >(1);
52 test_push_back_impl< Container >(2);
53 test_push_back_impl< Container >(100);
54 }
55
test_push_back()56 void test_push_back()
57 {
58 test_push_back_impl< std::vector<std::size_t> >();
59 test_push_back_impl< std::list<std::size_t> >();
60 }
61 }
62
63 boost::unit_test::test_suite*
init_unit_test_suite(int argc,char * argv[])64 init_unit_test_suite(int argc, char* argv[])
65 {
66 boost::unit_test::test_suite* test
67 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.push_back" );
68
69 test->add( BOOST_TEST_CASE( &test_push_back ) );
70
71 return test;
72 }
73