// 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 #include #include #include #include #include #include #include #include #include #include namespace boost { namespace { template void test(Container1& cont1, Container2& cont2) { Container1 old_cont1(cont1); Container2 old_cont2(cont2); bool reference_result = std::includes(cont1.begin(), cont1.end(), cont2.begin(), cont2.end()); bool test_result = boost::includes(cont1, cont2); BOOST_CHECK( reference_result == test_result ); BOOST_CHECK_EQUAL_COLLECTIONS( old_cont1.begin(), old_cont1.end(), cont1.begin(), cont1.end() ); BOOST_CHECK_EQUAL_COLLECTIONS( old_cont2.begin(), old_cont2.end(), cont2.begin(), cont2.end() ); BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), cont2) ); BOOST_CHECK( test_result == boost::includes(cont1, boost::make_iterator_range(cont2)) ); BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) ); } template void sort_container(Container& cont, BinaryPredicate pred) { typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; std::vector temp(cont.begin(), cont.end()); std::sort(temp.begin(), temp.end(), pred); cont.assign(temp.begin(), temp.end()); } template void test_pred(Container1 cont1, Container2 cont2, BinaryPredicate pred) { sort_container(cont1, pred); sort_container(cont2, pred); Container1 old_cont1(cont1); Container2 old_cont2(cont2); bool reference_result = std::includes(cont1.begin(), cont1.end(), cont2.begin(), cont2.end(), pred); bool test_result = boost::includes(cont1, cont2, pred); BOOST_CHECK( reference_result == test_result ); BOOST_CHECK_EQUAL_COLLECTIONS( old_cont1.begin(), old_cont1.end(), cont1.begin(), cont1.end() ); BOOST_CHECK_EQUAL_COLLECTIONS( old_cont2.begin(), old_cont2.end(), cont2.begin(), cont2.end() ); BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), cont2, pred) ); BOOST_CHECK( test_result == boost::includes(cont1, boost::make_iterator_range(cont2), pred) ); BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), pred) ); } template void test_includes_impl( Container1& cont1, Container2& cont2 ) { test(cont1, cont2); test_pred(cont1, cont2, std::less()); test_pred(cont1, cont2, std::greater()); } template void test_includes_impl() { using namespace boost::assign; Container1 cont1; Container2 cont2; test_includes_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 1; test_includes_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont2 += 1; test_includes_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 1,2,3,4,5,6,7,8,9; cont2 += 2,3,4; test_includes_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 2,3,4; cont2 += 1,2,3,4,5,6,7,8,9; test_includes_impl(cont1, cont2); } void test_includes() { test_includes_impl< std::vector, std::vector >(); test_includes_impl< std::list, std::list >(); test_includes_impl< std::deque, std::deque >(); test_includes_impl< std::vector, std::list >(); test_includes_impl< std::list, std::vector >(); } } } boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.includes" ); test->add( BOOST_TEST_CASE( &boost::test_includes ) ); return test; }