// Boost.Range library // // Copyright Neil Groves 2010. 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 namespace { template< class Container > void test_is_sorted_impl() { Container ascending; Container descending; // Empty ranges are regarded as sorted against any predicate. BOOST_CHECK( boost::is_sorted(ascending) ); BOOST_CHECK( boost::is_sorted(ascending, std::less()) ); BOOST_CHECK( boost::is_sorted(ascending, std::greater()) ); for (std::size_t i = 0; i < 10; ++i) { ascending.push_back(i); descending.push_back(9 - i); } BOOST_CHECK( boost::is_sorted(ascending) ); BOOST_CHECK( !boost::is_sorted(descending) ); BOOST_CHECK( !boost::is_sorted(ascending, std::greater()) ); BOOST_CHECK( boost::is_sorted(descending, std::greater()) ); } void test_is_sorted() { test_is_sorted_impl< std::vector >(); test_is_sorted_impl< 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_ext.is_sorted" ); test->add( BOOST_TEST_CASE( &test_is_sorted ) ); return test; }