refactor: add test_all()

This commit is contained in:
piotr.idzik 2023-05-23 19:18:50 +02:00
parent fcd8c2fd17
commit 5dcb4c07a8

View File

@ -71,15 +71,18 @@ std::vector<TestCase> get_test_cases() {
TestCase("x12x3x", "123", 3)}; TestCase("x12x3x", "123", 3)};
} }
void test_longest_common_string_length() { template <typename TestCases>
for (const auto& cur_tc : get_test_cases()) { void test_longest_common_string_length(const TestCases& test_cases) {
for (const auto& cur_tc : test_cases) {
assert(longest_common_string_length(cur_tc.str_a, cur_tc.str_b) == assert(longest_common_string_length(cur_tc.str_a, cur_tc.str_b) ==
cur_tc.common_string_len); cur_tc.common_string_len);
} }
} }
void test_longest_common_string_length_is_symmetric() { template <typename TestCases>
for (const auto& cur_tc : get_test_cases()) { void test_longest_common_string_length_is_symmetric(
const TestCases& test_cases) {
for (const auto& cur_tc : test_cases) {
assert(longest_common_string_length(cur_tc.str_b, cur_tc.str_a) == assert(longest_common_string_length(cur_tc.str_b, cur_tc.str_a) ==
cur_tc.common_string_len); cur_tc.common_string_len);
} }
@ -95,17 +98,25 @@ std::string reverse_str(const std::string& in_str) {
return {in_str.rbegin(), in_str.rend()}; return {in_str.rbegin(), in_str.rend()};
} }
void test_longest_common_string_length_for_reversed_inputs() { template <typename TestCases>
for (const auto& cur_tc : get_test_cases()) { void test_longest_common_string_length_for_reversed_inputs(
const TestCases& test_cases) {
for (const auto& cur_tc : test_cases) {
assert(longest_common_string_length(reverse_str(cur_tc.str_a), assert(longest_common_string_length(reverse_str(cur_tc.str_a),
reverse_str(cur_tc.str_b)) == reverse_str(cur_tc.str_b)) ==
cur_tc.common_string_len); cur_tc.common_string_len);
} }
} }
void test_all() {
const auto test_cases = get_test_cases();
assert(test_cases.size() > 0);
test_longest_common_string_length(test_cases);
test_longest_common_string_length_is_symmetric(test_cases);
test_longest_common_string_length_for_reversed_inputs(test_cases);
}
int main() { int main() {
test_longest_common_string_length(); test_all();
test_longest_common_string_length_is_symmetric();
test_longest_common_string_length_for_reversed_inputs();
return 0; return 0;
} }