From 22cafea3deada509b0b799e972c5968ea47b17ee Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Sun, 5 May 2024 16:20:34 +0300 Subject: [PATCH 1/3] Reduce mismatch test run time Done the following: * Reused lgk mismatch result in lgk lex compare * Reduced the number of random mismatches --- .../VSO_0000000_vector_algorithms/test.cpp | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp index 07b9081706..4cbba1cc5c 100644 --- a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp +++ b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp @@ -426,38 +426,36 @@ auto last_known_good_mismatch(FwdIt first1, FwdIt last1, FwdIt first2, FwdIt las } template -bool last_known_good_lex_compare(FwdIt first1, FwdIt last1, FwdIt first2, FwdIt last2) { - for (;; ++first1, ++first2) { - if (first2 == last2) { - return false; - } else if (first1 == last1) { - return true; - } else if (*first1 < *first2) { - return true; - } else if (*first2 < *first1) { - return false; - } +bool last_known_good_lex_compare(pair mismatch, FwdIt last1, FwdIt last2) { + if (mismatch.second == last2) { + return false; + } else if (mismatch.first == last1) { + return true; + } else if (*mismatch.first < *mismatch.second) { + return true; + } else if (*mismatch.second < *mismatch.first) { + return false; + } else { + assert(false); + return false; } } #if _HAS_CXX20 template -auto last_known_good_lex_compare_3way(FwdIt first1, FwdIt last1, FwdIt first2, FwdIt last2) { - for (;; ++first1, ++first2) { - if (first2 == last2) { - if (first1 == last1) { - return strong_ordering::equal; - } else { - return strong_ordering::greater; - } - } else if (first1 == last1) { - return strong_ordering::less; +auto last_known_good_lex_compare_3way(pair mismatch, FwdIt last1, FwdIt last2) { + if (mismatch.second == last2) { + if (mismatch.first == last1) { + return strong_ordering::equal; } else { - auto order = *first1 <=> *first2; - if (order != 0) { - return order; - } + return strong_ordering::greater; } + } else if (mismatch.first == last1) { + return strong_ordering::less; + } else { + auto order = *mismatch.first <=> *mismatch.second; + assert(order != 0); + return order; } } #endif // _HAS_CXX20 @@ -468,7 +466,7 @@ void test_case_mismatch_and_lex_compare_family(const vector& a, const vector< auto actual_mismatch = mismatch(a.begin(), a.end(), b.begin(), b.end()); assert(expected_mismatch == actual_mismatch); - auto expected_lex = last_known_good_lex_compare(a.begin(), a.end(), b.begin(), b.end()); + auto expected_lex = last_known_good_lex_compare(expected_mismatch, a.end(), b.end()); auto actual_lex = lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()); assert(expected_lex == actual_lex); @@ -480,7 +478,7 @@ void test_case_mismatch_and_lex_compare_family(const vector& a, const vector< auto ranges_actual_lex = ranges::lexicographical_compare(a, b); assert(expected_lex == ranges_actual_lex); - auto expected_lex_3way = last_known_good_lex_compare_3way(a.begin(), a.end(), b.begin(), b.end()); + auto expected_lex_3way = last_known_good_lex_compare_3way(expected_mismatch, a.end(), b.end()); auto actual_lex_3way = lexicographical_compare_three_way(a.begin(), a.end(), b.begin(), b.end()); assert(expected_lex_3way == actual_lex_3way); #endif // _HAS_CXX20 @@ -489,7 +487,7 @@ void test_case_mismatch_and_lex_compare_family(const vector& a, const vector< template void test_mismatch_and_lex_compare_family(mt19937_64& gen) { constexpr size_t shrinkCount = 4; - constexpr size_t mismatchCount = 30; + constexpr size_t mismatchCount = 10; using TD = conditional_t; uniform_int_distribution dis('a', 'z'); vector input_a; From 7e5579e08232a6e07c50d470a03405b8d749eff5 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 14 May 2024 20:53:26 -0700 Subject: [PATCH 2/3] Avoid shadowing: `mismatch` => `expected_mismatch` --- .../VSO_0000000_vector_algorithms/test.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp index 4cbba1cc5c..2a0a1026fb 100644 --- a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp +++ b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp @@ -426,14 +426,14 @@ auto last_known_good_mismatch(FwdIt first1, FwdIt last1, FwdIt first2, FwdIt las } template -bool last_known_good_lex_compare(pair mismatch, FwdIt last1, FwdIt last2) { - if (mismatch.second == last2) { +bool last_known_good_lex_compare(pair expected_mismatch, FwdIt last1, FwdIt last2) { + if (expected_mismatch.second == last2) { return false; - } else if (mismatch.first == last1) { + } else if (expected_mismatch.first == last1) { return true; - } else if (*mismatch.first < *mismatch.second) { + } else if (*expected_mismatch.first < *expected_mismatch.second) { return true; - } else if (*mismatch.second < *mismatch.first) { + } else if (*expected_mismatch.second < *expected_mismatch.first) { return false; } else { assert(false); @@ -443,17 +443,17 @@ bool last_known_good_lex_compare(pair mismatch, FwdIt last1, FwdIt #if _HAS_CXX20 template -auto last_known_good_lex_compare_3way(pair mismatch, FwdIt last1, FwdIt last2) { - if (mismatch.second == last2) { - if (mismatch.first == last1) { +auto last_known_good_lex_compare_3way(pair expected_mismatch, FwdIt last1, FwdIt last2) { + if (expected_mismatch.second == last2) { + if (expected_mismatch.first == last1) { return strong_ordering::equal; } else { return strong_ordering::greater; } - } else if (mismatch.first == last1) { + } else if (expected_mismatch.first == last1) { return strong_ordering::less; } else { - auto order = *mismatch.first <=> *mismatch.second; + auto order = *expected_mismatch.first <=> *expected_mismatch.second; assert(order != 0); return order; } From 4325ced7374757bb0951a8b4c749767698832e5c Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 14 May 2024 21:00:05 -0700 Subject: [PATCH 3/3] Avoid `assert(false);` followed by `return false;`. --- tests/std/tests/VSO_0000000_vector_algorithms/test.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp index 2a0a1026fb..123ada62d2 100644 --- a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp +++ b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp @@ -433,10 +433,8 @@ bool last_known_good_lex_compare(pair expected_mismatch, FwdIt las return true; } else if (*expected_mismatch.first < *expected_mismatch.second) { return true; - } else if (*expected_mismatch.second < *expected_mismatch.first) { - return false; } else { - assert(false); + assert(*expected_mismatch.second < *expected_mismatch.first); return false; } }