Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce mismatch test run time #4656

Merged
merged 3 commits into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 24 additions & 28 deletions tests/std/tests/VSO_0000000_vector_algorithms/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,38 +426,34 @@ auto last_known_good_mismatch(FwdIt first1, FwdIt last1, FwdIt first2, FwdIt las
}

template <class FwdIt>
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<FwdIt, FwdIt> expected_mismatch, FwdIt last1, FwdIt last2) {
if (expected_mismatch.second == last2) {
return false;
} else if (expected_mismatch.first == last1) {
return true;
} else if (*expected_mismatch.first < *expected_mismatch.second) {
return true;
} else {
assert(*expected_mismatch.second < *expected_mismatch.first);
return false;
}
}

#if _HAS_CXX20
template <class FwdIt>
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<FwdIt, FwdIt> expected_mismatch, FwdIt last1, FwdIt last2) {
if (expected_mismatch.second == last2) {
if (expected_mismatch.first == last1) {
return strong_ordering::equal;
} else {
auto order = *first1 <=> *first2;
if (order != 0) {
return order;
}
return strong_ordering::greater;
}
} else if (expected_mismatch.first == last1) {
return strong_ordering::less;
} else {
auto order = *expected_mismatch.first <=> *expected_mismatch.second;
assert(order != 0);
return order;
}
}
#endif // _HAS_CXX20
Expand All @@ -468,7 +464,7 @@ void test_case_mismatch_and_lex_compare_family(const vector<T>& 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);

Expand All @@ -480,7 +476,7 @@ void test_case_mismatch_and_lex_compare_family(const vector<T>& 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
Expand All @@ -489,7 +485,7 @@ void test_case_mismatch_and_lex_compare_family(const vector<T>& a, const vector<
template <class T>
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<sizeof(T) == 1, int, T>;
uniform_int_distribution<TD> dis('a', 'z');
vector<T> input_a;
Expand Down