Skip to content

Commit

Permalink
single character coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGuteniev committed Oct 27, 2024
1 parent 8082c9e commit 8750935
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions tests/std/tests/VSO_0000000_vector_algorithms/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,12 +1218,31 @@ void test_bitset(mt19937_64& gen) {
test_randomized_bitset_base_count<512 - 5, 32 + 10>(gen);
}

template <class T>
void test_case_string_find(const basic_string<T>& 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<ptrdiff_t>(input_haystack.find(ch));
assert(expected == actual);
}

template <class T>
void test_case_string_rfind(const basic_string<T>& 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<ptrdiff_t>(input_haystack.rfind(ch));
assert(expected == actual);
}

template <class T>
void test_case_string_find_first_of(const basic_string<T>& input_haystack, const basic_string<T>& 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<ptrdiff_t>(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<ptrdiff_t>(input_haystack.find_first_of(input_needle));
assert(expected == actual);
}

Expand All @@ -1242,8 +1261,8 @@ size_t last_known_good_find_last_of(const basic_string<T>& h, const basic_string

template <class T>
void test_case_string_find_last_of(const basic_string<T>& input_haystack, const basic_string<T>& 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);
}

Expand All @@ -1255,6 +1274,10 @@ void test_basic_string_dis(mt19937_64& gen, D& dis) {
input_needle.reserve(needleDataCount);

for (;;) {
const T ch = static_cast<T>(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);
Expand Down

0 comments on commit 8750935

Please sign in to comment.