diff --git a/test/partition_subrange_test.cpp b/test/partition_subrange_test.cpp index 018f140..c33fb46 100644 --- a/test/partition_subrange_test.cpp +++ b/test/partition_subrange_test.cpp @@ -7,6 +7,20 @@ #include #include + +#if __cplusplus >= 201103L +#include + +std::default_random_engine gen; +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::shuffle(first, last, gen); } +#else +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::random_shuffle(first, last); } +#endif + namespace ba = boost::algorithm; template @@ -72,14 +86,14 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[5], 5); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, b + 8); check_sequence (b, v.end(), b + 7, b + 8); // BOOST_CHECK_EQUAL(v[7], 7); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, v.end()); check_sequence (b, v.end(), b + 7, v.end()); @@ -88,7 +102,7 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[9], 9); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b + 2); check_sequence (b, v.end(), b, b + 2); @@ -96,12 +110,12 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[1], 1); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b); check_sequence (b, v.end(), b, b); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, v.end()); check_sequence (b, v.end(), b, v.end()); } @@ -120,14 +134,14 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[5], 4); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, b + 8, std::greater()); check_sequence (b, v.end(), b + 7, b + 8, std::greater()); // BOOST_CHECK_EQUAL(v[7], 2); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, v.end(), std::greater()); check_sequence (b, v.end(), b + 7, v.end(), std::greater()); @@ -136,7 +150,7 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[9], 0); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b + 2, std::greater()); check_sequence (b, v.end(), b, b + 2, std::greater()); @@ -144,12 +158,12 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[1], 8); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b, std::greater()); check_sequence (b, v.end(), b, b, std::greater()); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, v.end(), std::greater()); check_sequence (b, v.end(), b, v.end(), std::greater()); } diff --git a/test/sort_subrange_test.cpp b/test/sort_subrange_test.cpp index 4c1192e..de6a3fa 100644 --- a/test/sort_subrange_test.cpp +++ b/test/sort_subrange_test.cpp @@ -7,6 +7,20 @@ #include #include + +#if __cplusplus >= 201103L +#include + +std::default_random_engine gen; +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::shuffle(first, last, gen); } +#else +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::random_shuffle(first, last); } +#endif + namespace ba = boost::algorithm; template @@ -53,14 +67,14 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[5], 5); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, b + 8); check_sequence (b, v.end(), b + 7, b + 8); BOOST_CHECK_EQUAL(v[7], 7); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, v.end()); check_sequence (b, v.end(), b + 7, v.end()); @@ -69,7 +83,7 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[9], 9); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b + 2); check_sequence (b, v.end(), b, b + 2); @@ -77,12 +91,12 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[1], 1); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b); check_sequence (b, v.end(), b, b); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, v.end()); check_sequence (b, v.end(), b, v.end()); } @@ -101,14 +115,14 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[5], 4); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, b + 8, std::greater()); check_sequence (b, v.end(), b + 7, b + 8, std::greater()); BOOST_CHECK_EQUAL(v[7], 2); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, v.end(), std::greater()); check_sequence (b, v.end(), b + 7, v.end(), std::greater()); @@ -117,7 +131,7 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[9], 0); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b + 2, std::greater()); check_sequence (b, v.end(), b, b + 2, std::greater()); @@ -125,12 +139,12 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[1], 8); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b, std::greater()); check_sequence (b, v.end(), b, b, std::greater()); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, v.end(), std::greater()); check_sequence (b, v.end(), b, v.end(), std::greater()); }