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/remove_copy.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 |
25 | { |
26 | template<typename Iterator, typename Value> |
27 | void test_append(Iterator target, Value value) |
28 | { |
29 | *target++ = value; |
30 | } |
31 | |
32 | template< class Container, class Value > |
33 | void test_remove_copy_impl( const Container& c, Value to_remove ) |
34 | { |
35 | typedef typename boost::range_value<Container>::type value_type; |
36 | std::vector<value_type> reference; |
37 | |
38 | typedef BOOST_DEDUCED_TYPENAME std::vector<value_type>::iterator |
39 | iterator_t BOOST_RANGE_UNUSED; |
40 | |
41 | test_append( |
42 | std::remove_copy(c.begin(), c.end(), |
43 | std::back_inserter(reference), to_remove), |
44 | to_remove); |
45 | |
46 | std::vector<value_type> test; |
47 | test_append( |
48 | boost::remove_copy(c, std::back_inserter(test), to_remove), |
49 | to_remove); |
50 | |
51 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
52 | test.begin(), test.end() ); |
53 | |
54 | std::vector<value_type> test2; |
55 | test_append( |
56 | boost::remove_copy(boost::make_iterator_range(c), |
57 | std::back_inserter(test2), to_remove), |
58 | to_remove); |
59 | |
60 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
61 | test2.begin(), test2.end() ); |
62 | } |
63 | |
64 | template< class Container > |
65 | void test_remove_copy_impl() |
66 | { |
67 | using namespace boost::assign; |
68 | |
69 | Container cont; |
70 | test_remove_copy_impl(cont, 0); |
71 | |
72 | cont.clear(); |
73 | cont += 1; |
74 | test_remove_copy_impl(cont, 0); |
75 | test_remove_copy_impl(cont, 1); |
76 | |
77 | cont.clear(); |
78 | cont += 1,1,1,1,1; |
79 | test_remove_copy_impl(cont, 0); |
80 | test_remove_copy_impl(cont, 1); |
81 | |
82 | cont.clear(); |
83 | cont += 1,2,3,4,5,6,7,8,9; |
84 | test_remove_copy_impl(cont, 1); |
85 | test_remove_copy_impl(cont, 9); |
86 | test_remove_copy_impl(cont, 4); |
87 | } |
88 | |
89 | void test_remove_copy() |
90 | { |
91 | test_remove_copy_impl< std::vector<int> >(); |
92 | test_remove_copy_impl< std::list<int> >(); |
93 | test_remove_copy_impl< std::deque<int> >(); |
94 | } |
95 | } |
96 | |
97 | boost::unit_test::test_suite* |
98 | init_unit_test_suite(int argc, char* argv[]) |
99 | { |
100 | boost::unit_test::test_suite* test |
101 | = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove_copy" ); |
102 | |
103 | test->add( BOOST_TEST_CASE( &test_remove_copy ) ); |
104 | |
105 | return test; |
106 | } |
107 | |
108 | |