-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalgorithm_string_distances.cpp
More file actions
45 lines (39 loc) · 1.64 KB
/
algorithm_string_distances.cpp
File metadata and controls
45 lines (39 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright - 2020 - Jan Christoph Uhde <[email protected]>
// Please see LICENSE.md for license or visit https://github.com/extcpp/basics
#include <ext/algorithm/string_distances.hpp>
#include <gtest/gtest.h>
namespace ext { namespace algorithm { namespace distances {
class string_distance_fixture : public ::testing::Test {
protected:
typedef std::vector<std::pair<std::string, std::string>> test_data_type;
test_data_type test_data;
string_distance_fixture() {
test_data = {
{"ulaula", "ohlala"}, {"1234567890", "67890"}, {"jan", "mann"}, {"loster", "lopster"}, {"hallo", "hallo"}};
}
virtual ~string_distance_fixture() {}
virtual void SetUp() {}
virtual void TearDown() {}
void test_function(std::size_t distance_fun(const std::string&, const std::string&),
std::vector<std::size_t> result) {
for (std::size_t i = 0; i < result.size(); ++i) {
std::size_t j;
EXPECT_EQ(result[i], j = distance_fun(test_data[i].first, test_data[i].second))
<< "\n"
<< " index: " << i << std::endl
<< " input: '" << test_data[i].first << "' and '" << test_data[i].second << "'\n"
<< " result: " << j << std::endl
<< "expected: " << result[i] << "\n\n";
}
}
};
TEST_F(string_distance_fixture, length) {
test_function(length, {0, 5, 1, 1, 0});
}
TEST_F(string_distance_fixture, edit_matrix) {
test_function(edit_matrix, {3, 5, 2, 1, 0});
}
TEST_F(string_distance_fixture, edit_fast) {
test_function(edit_fast, {3, 5, 2, 1, 0});
}
}}} // namespace ext::algorithm::distances