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

source code of boost/libs/range/test/algorithm_test/remove.cpp