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/overwrite.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 >
test_overwrite_impl(std::size_t n)24 void test_overwrite_impl(std::size_t n)
25 {
26 Container overwrite_source;
27 for (std::size_t i = 0; i < n; ++i)
28 overwrite_source.push_back(i);
29
30 Container reference;
31 reference.resize(n);
32 std::copy(overwrite_source.begin(), overwrite_source.end(), reference.begin());
33
34 Container test;
35 test.resize(n);
36 boost::overwrite(overwrite_source, test);
37
38 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
39 test.begin(), test.end() );
40
41 test.clear();
42 test.resize(n);
43 const Container& const_overwrite_source = overwrite_source;
44 boost::overwrite(const_overwrite_source, test);
45
46 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
47 test.begin(), test.end() );
48 }
49
50 template< class Container >
test_overwrite_impl()51 void test_overwrite_impl()
52 {
53 test_overwrite_impl<Container>(0);
54 test_overwrite_impl<Container>(1);
55 test_overwrite_impl<Container>(10);
56 }
57
test_overwrite()58 void test_overwrite()
59 {
60 test_overwrite_impl< std::vector<std::size_t> >();
61 test_overwrite_impl< std::list<std::size_t> >();
62 }
63 }
64
65 boost::unit_test::test_suite*
init_unit_test_suite(int argc,char * argv[])66 init_unit_test_suite(int argc, char* argv[])
67 {
68 boost::unit_test::test_suite* test
69 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.overwrite" );
70
71 test->add( BOOST_TEST_CASE( &test_overwrite ) );
72
73 return test;
74 }
75