1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// Boost.Range library
//
// Copyright Neil Groves 2009. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//
// For more information, see http://www.boost.org/libs/range/
//
#include <boost/range/algorithm/equal.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/assign.hpp>
#include <algorithm>
#include <list>
#include <set>
#include <vector>
namespace boost
{
namespace
{
template< class Container1, class Container2 >
void test_equal_impl()
{
using namespace boost::assign;
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
container1_t mcont1;
container2_t mcont2;
Container1& cont1 = mcont1;
Container2& cont2 = mcont2;
BOOST_CHECK( boost::equal(cont1, cont2) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2) );
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( boost::equal(cont1, cont2, std::not_equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
mcont1 += 1;
BOOST_CHECK( !boost::equal(cont1, cont2) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2) );
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2)) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
mcont1.clear();
mcont2 += 1;
BOOST_CHECK( !boost::equal(cont1, cont2) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
mcont1 += 1;
BOOST_CHECK( boost::equal(cont1, cont2) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2) );
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
mcont1 += 2,3,4,5,6,7,8,9;
mcont2 += 2,3,4,5,6,7,8,9;
BOOST_CHECK( boost::equal(cont1, cont2) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2) );
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
}
template< class Container1, class Container2 >
void test_driver()
{
typedef Container1 container1_t;
typedef Container2 container2_t;
typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container1>::type const_container1_t;
typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container2>::type const_container2_t;
test_equal_impl< const_container1_t, const_container2_t >();
test_equal_impl< const_container1_t, container2_t >();
test_equal_impl< container1_t, const_container2_t >();
test_equal_impl< container1_t, container2_t >();
}
void test_equal()
{
test_driver< std::list<int>, std::list<int> >();
test_driver< std::vector<int>, std::vector<int> >();
test_driver< std::set<int>, std::set<int> >();
test_driver< std::multiset<int>, std::multiset<int> >();
test_driver< std::list<int>, std::vector<int> >();
test_driver< std::vector<int>, std::list<int> >();
}
}
}
boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal" );
test->add( BOOST_TEST_CASE( &boost::test_equal ) );
return test;
}
|