diff --git a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp index 8498602479..9625a14cb4 100644 --- a/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp +++ b/tests/std/tests/VSO_0000000_vector_algorithms/test.cpp @@ -1218,12 +1218,31 @@ void test_bitset(mt19937_64& gen) { test_randomized_bitset_base_count<512 - 5, 32 + 10>(gen); } +template +void test_case_string_find(const basic_string& input_haystack, const T ch) { + const auto expected_iter = last_known_good_find(input_haystack.begin(), input_haystack.end(), ch); + const auto expected = + (expected_iter != input_haystack.end()) ? expected_iter - input_haystack.begin() : ptrdiff_t{-1}; + const auto actual = static_cast(input_haystack.find(ch)); + assert(expected == actual); +} + +template +void test_case_string_rfind(const basic_string& input_haystack, const T ch) { + const auto expected_iter = last_known_good_find_last(input_haystack.begin(), input_haystack.end(), ch); + const auto expected = + (expected_iter != input_haystack.end()) ? expected_iter - input_haystack.begin() : ptrdiff_t{-1}; + const auto actual = static_cast(input_haystack.rfind(ch)); + assert(expected == actual); +} + template void test_case_string_find_first_of(const basic_string& input_haystack, const basic_string& input_needle) { - auto expected_iter = last_known_good_find_first_of( + const auto expected_iter = last_known_good_find_first_of( input_haystack.begin(), input_haystack.end(), input_needle.begin(), input_needle.end()); - auto expected = (expected_iter != input_haystack.end()) ? expected_iter - input_haystack.begin() : ptrdiff_t{-1}; - auto actual = static_cast(input_haystack.find_first_of(input_needle)); + const auto expected = + (expected_iter != input_haystack.end()) ? expected_iter - input_haystack.begin() : ptrdiff_t{-1}; + const auto actual = static_cast(input_haystack.find_first_of(input_needle)); assert(expected == actual); } @@ -1242,8 +1261,8 @@ size_t last_known_good_find_last_of(const basic_string& h, const basic_string template void test_case_string_find_last_of(const basic_string& input_haystack, const basic_string& input_needle) { - size_t expected = last_known_good_find_last_of(input_haystack, input_needle); - size_t actual = input_haystack.find_last_of(input_needle); + const size_t expected = last_known_good_find_last_of(input_haystack, input_needle); + const size_t actual = input_haystack.find_last_of(input_needle); assert(expected == actual); } @@ -1255,6 +1274,10 @@ void test_basic_string_dis(mt19937_64& gen, D& dis) { input_needle.reserve(needleDataCount); for (;;) { + const T ch = static_cast(dis(gen)); + test_case_string_find(input_haystack, ch); + test_case_string_rfind(input_haystack, ch); + input_needle.clear(); test_case_string_find_first_of(input_haystack, input_needle);