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