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 | #include <boost/range/algorithm/fill.hpp> |
12 | |
13 | #include <boost/test/test_tools.hpp> |
14 | #include <boost/test/unit_test.hpp> |
15 | |
16 | #include <boost/assign.hpp> |
17 | #include <algorithm> |
18 | #include <functional> |
19 | #include <list> |
20 | #include <numeric> |
21 | #include <deque> |
22 | #include <vector> |
23 | |
24 | namespace boost |
25 | { |
26 | namespace |
27 | { |
28 | template< class Container > |
29 | void test_fill_impl(Container& cont) |
30 | { |
31 | Container reference(cont); |
32 | std::fill(reference.begin(), reference.end(), 1); |
33 | |
34 | Container target(cont); |
35 | boost::fill(target, 1); |
36 | |
37 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
38 | target.begin(), target.end() ); |
39 | |
40 | Container target2(cont); |
41 | boost::fill(boost::make_iterator_range(target2), 1); |
42 | |
43 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
44 | target2.begin(), target2.end() ); |
45 | } |
46 | |
47 | template< class Container > |
48 | void test_fill_impl() |
49 | { |
50 | using namespace boost::assign; |
51 | |
52 | Container cont; |
53 | test_fill_impl(cont); |
54 | |
55 | cont.clear(); |
56 | cont += 2; |
57 | test_fill_impl(cont); |
58 | |
59 | cont.clear(); |
60 | cont += 1,2; |
61 | test_fill_impl(cont); |
62 | |
63 | cont.clear(); |
64 | cont += 1,2,3,4,5,6,7,8,9; |
65 | test_fill_impl(cont); |
66 | } |
67 | |
68 | void test_fill() |
69 | { |
70 | test_fill_impl< std::vector<int> >(); |
71 | test_fill_impl< std::list<int> >(); |
72 | test_fill_impl< std::deque<int> >(); |
73 | } |
74 | } |
75 | } |
76 | |
77 | boost::unit_test::test_suite* |
78 | init_unit_test_suite(int argc, char* argv[]) |
79 | { |
80 | boost::unit_test::test_suite* test |
81 | = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.fill" ); |
82 | |
83 | test->add( BOOST_TEST_CASE( &boost::test_fill ) ); |
84 | |
85 | return test; |
86 | } |
87 | |