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/equal.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 <set>
20#include <vector>
21
22namespace boost
23{
24 namespace
25 {
26 template< class Container1, class Container2 >
27 void test_equal_impl()
28 {
29 using namespace boost::assign;
30
31 typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
32 typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
33
34 container1_t mcont1;
35 container2_t mcont2;
36
37 Container1& cont1 = mcont1;
38 Container2& cont2 = mcont2;
39
40 BOOST_CHECK( boost::equal(cont1, cont2) );
41 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2) );
42 BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
43 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
44 BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
45 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
46 BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
47 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
48 BOOST_CHECK( boost::equal(cont1, cont2, std::not_equal_to<int>()) );
49 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
50 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
51
52 mcont1 += 1;
53 BOOST_CHECK( !boost::equal(cont1, cont2) );
54 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2) );
55 BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2)) );
56 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
57 BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
58 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
59 BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
60 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
61 BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
62 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
63 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
64
65 mcont1.clear();
66 mcont2 += 1;
67 BOOST_CHECK( !boost::equal(cont1, cont2) );
68 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2) );
69 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
70 BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
71 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
72 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
73 BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
74 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
75 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
76
77 mcont1 += 1;
78 BOOST_CHECK( boost::equal(cont1, cont2) );
79 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2) );
80 BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
81 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
82 BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
83 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
84 BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
85 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
86 BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
87 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
88 BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
89 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
90
91 mcont1 += 2,3,4,5,6,7,8,9;
92 mcont2 += 2,3,4,5,6,7,8,9;
93 BOOST_CHECK( boost::equal(cont1, cont2) );
94 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2) );
95 BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
96 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
97 BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
98 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
99 BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
100 BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
101 BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
102 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
103 BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
104 BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
105 }
106
107 template< class Container1, class Container2 >
108 void test_driver()
109 {
110 typedef Container1 container1_t;
111 typedef Container2 container2_t;
112 typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container1>::type const_container1_t;
113 typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container2>::type const_container2_t;
114
115 test_equal_impl< const_container1_t, const_container2_t >();
116 test_equal_impl< const_container1_t, container2_t >();
117 test_equal_impl< container1_t, const_container2_t >();
118 test_equal_impl< container1_t, container2_t >();
119 }
120
121 void test_equal()
122 {
123 test_driver< std::list<int>, std::list<int> >();
124 test_driver< std::vector<int>, std::vector<int> >();
125 test_driver< std::set<int>, std::set<int> >();
126 test_driver< std::multiset<int>, std::multiset<int> >();
127 test_driver< std::list<int>, std::vector<int> >();
128 test_driver< std::vector<int>, std::list<int> >();
129 }
130 }
131}
132
133
134boost::unit_test::test_suite*
135init_unit_test_suite(int argc, char* argv[])
136{
137 boost::unit_test::test_suite* test
138 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal" );
139
140 test->add( BOOST_TEST_CASE( &boost::test_equal ) );
141
142 return test;
143}
144

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