• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/insert.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_insert_impl(int n)25     void test_insert_impl( int n )
26     {
27         Container test;
28         boost::insert( test, test.end(), boost::irange(0, n) );
29 
30         Container reference;
31         for (int i = 0; i < n; ++i)
32             reference.push_back(i);
33 
34         BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
35             test.begin(), test.end() );
36 
37         // Do it again so that we are inserting into a non-empty target
38         boost::insert( test, test.end(), boost::irange(0, n) );
39 
40         for (int j = 0; j < n; ++j)
41             reference.push_back(j);
42 
43         BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
44             test.begin(), test.end() );
45     }
46 
47     template< class Container >
test_insert_impl()48     void test_insert_impl()
49     {
50         test_insert_impl< Container >(0);
51         test_insert_impl< Container >(1);
52         test_insert_impl< Container >(2);
53         test_insert_impl< Container >(100);
54     }
55 
test_insert()56     void test_insert()
57     {
58         test_insert_impl< std::vector<std::size_t> >();
59         test_insert_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.insert" );
68 
69     test->add( BOOST_TEST_CASE( &test_insert ) );
70 
71     return test;
72 }
73