// 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_lexicographical_compare_impl_nopred(ForwardRange1& rng1, ForwardRange2& rng2) { const bool reference = std::lexicographical_compare( boost::begin(rng1), boost::end(rng1), boost::begin(rng2), boost::end(rng2)); const bool test = boost::lexicographical_compare(rng1, rng2); BOOST_CHECK( reference == test ); BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), rng2) ); BOOST_CHECK( test == boost::lexicographical_compare(rng1, boost::make_iterator_range(rng2)) ); BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), boost::make_iterator_range(rng2)) ); } template void test_lexicographical_compare_impl_pred(ForwardRange1& rng1, ForwardRange2& rng2, BinaryPredicate pred) { const bool reference = std::lexicographical_compare( boost::begin(rng1), boost::end(rng1), boost::begin(rng2), boost::end(rng2), pred); const bool test = boost::lexicographical_compare(rng1, rng2, pred); BOOST_CHECK( reference == test ); BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), rng2, pred) ); BOOST_CHECK( test == boost::lexicographical_compare(rng1, boost::make_iterator_range(rng2), pred) ); BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), boost::make_iterator_range(rng2), pred) ); } template void test_lexicographical_compare_impl(Container1& cont1, Container2& cont2) { typedef BOOST_DEDUCED_TYPENAME boost::range_value::type value_t; test_lexicographical_compare_impl_nopred(cont1, cont2); test_lexicographical_compare_impl_pred(cont1, cont2, std::less()); test_lexicographical_compare_impl_pred(cont1, cont2, std::greater()); } template void test_lexicographical_compare_impl() { using namespace boost::assign; typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container1_t; typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container2_t; container1_t cont1; container2_t cont2; test_lexicographical_compare_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1.push_back(1); cont2.push_back(1); test_lexicographical_compare_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 2; cont2 += 1; test_lexicographical_compare_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 1; cont2 += 2; test_lexicographical_compare_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 1,2,3,4,5,6,7; cont2 += 1,2,3,4,5,6,7; test_lexicographical_compare_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 1,2,3,4,5,6,7; cont2 += 1,2,3,4,5,6; test_lexicographical_compare_impl(cont1, cont2); cont1.clear(); cont2.clear(); cont1 += 1,2,3,4,5,6; cont2 += 1,2,3,4,5,6,7; test_lexicographical_compare_impl(cont1, cont2); } template void test_lexicographical_compare_rhs() { typedef BOOST_DEDUCED_TYPENAME range_value::type value_t; test_lexicographical_compare_impl >(); test_lexicographical_compare_impl >(); test_lexicographical_compare_impl >(); test_lexicographical_compare_impl >(); test_lexicographical_compare_impl >(); test_lexicographical_compare_impl >(); } void test_lexicographical_compare() { test_lexicographical_compare_rhs< const std::vector >(); test_lexicographical_compare_rhs< const std::deque >(); test_lexicographical_compare_rhs< const std::list >(); test_lexicographical_compare_rhs< std::vector >(); test_lexicographical_compare_rhs< std::deque >(); test_lexicographical_compare_rhs< std::list >(); } } } boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lexicographical_compare" ); test->add( BOOST_TEST_CASE( &boost::test_lexicographical_compare ) ); return test; }