1
- #include < catch2/catch_approx.hpp>
2
- #include < catch2/catch_test_macros.hpp>
1
+ #include < catch2/catch.hpp>
3
2
#include < rapidfuzz/details/Range.hpp>
4
3
#include < rapidfuzz/details/types.hpp>
5
4
#include < string>
8
7
9
8
#include " ../common.hpp"
10
9
10
+ using Catch::Matchers::WithinAbs;
11
+
11
12
template <typename Sentence1, typename Sentence2>
12
13
size_t damerau_levenshtein_distance (const Sentence1& s1, const Sentence2& s2,
13
14
size_t max = std::numeric_limits<size_t >::max())
@@ -60,10 +61,10 @@ double damerau_levenshtein_normalized_distance(const Sentence1& s1, const Senten
60
61
rapidfuzz::experimental::CachedDamerauLevenshtein scorer (s1);
61
62
double res4 = scorer.normalized_distance (s2, score_cutoff);
62
63
double res5 = scorer.normalized_distance (s2.begin (), s2.end (), score_cutoff);
63
- REQUIRE (res1 == Catch::Approx (res2). epsilon ( 0.0001 ));
64
- REQUIRE (res1 == Catch::Approx (res3). epsilon ( 0.0001 ));
65
- REQUIRE (res1 == Catch::Approx (res4). epsilon ( 0.0001 ));
66
- REQUIRE (res1 == Catch::Approx (res5). epsilon ( 0.0001 ));
64
+ REQUIRE_THAT (res1, WithinAbs (res2, 0.0001 ));
65
+ REQUIRE_THAT (res1, WithinAbs (res3, 0.0001 ));
66
+ REQUIRE_THAT (res1, WithinAbs (res4, 0.0001 ));
67
+ REQUIRE_THAT (res1, WithinAbs (res5, 0.0001 ));
67
68
return res1;
68
69
}
69
70
@@ -80,10 +81,10 @@ double damerau_levenshtein_normalized_similarity(const Sentence1& s1, const Sent
80
81
rapidfuzz::experimental::CachedDamerauLevenshtein scorer (s1);
81
82
double res4 = scorer.normalized_similarity (s2, score_cutoff);
82
83
double res5 = scorer.normalized_similarity (s2.begin (), s2.end (), score_cutoff);
83
- REQUIRE (res1 == Catch::Approx (res2). epsilon ( 0.0001 ));
84
- REQUIRE (res1 == Catch::Approx (res3). epsilon ( 0.0001 ));
85
- REQUIRE (res1 == Catch::Approx (res4). epsilon ( 0.0001 ));
86
- REQUIRE (res1 == Catch::Approx (res5). epsilon ( 0.0001 ));
84
+ REQUIRE_THAT (res1, WithinAbs (res2, 0.0001 ));
85
+ REQUIRE_THAT (res1, WithinAbs (res3, 0.0001 ));
86
+ REQUIRE_THAT (res1, WithinAbs (res4, 0.0001 ));
87
+ REQUIRE_THAT (res1, WithinAbs (res5, 0.0001 ));
87
88
return res1;
88
89
}
89
90
@@ -114,19 +115,15 @@ TEST_CASE("Levenshtein")
114
115
SECTION (" weighted levenshtein calculates correct ratios" )
115
116
{
116
117
REQUIRE (damerau_levenshtein_normalized_similarity (test, test) == 1.0 );
117
- REQUIRE (damerau_levenshtein_normalized_similarity (test, no_suffix) ==
118
- Catch::Approx (0.75 ).epsilon (0.0001 ));
119
- REQUIRE (damerau_levenshtein_normalized_similarity (swapped1, swapped2) ==
120
- Catch::Approx (0.75 ).epsilon (0.0001 ));
121
- REQUIRE (damerau_levenshtein_normalized_similarity (test, no_suffix2) ==
122
- Catch::Approx (0.75 ).epsilon (0.0001 ));
118
+ REQUIRE_THAT (damerau_levenshtein_normalized_similarity (test, no_suffix), WithinAbs (0.75 , 0.0001 ));
119
+ REQUIRE_THAT (damerau_levenshtein_normalized_similarity (swapped1, swapped2), WithinAbs (0.75 , 0.0001 ));
120
+ REQUIRE_THAT (damerau_levenshtein_normalized_similarity (test, no_suffix2), WithinAbs (0.75 , 0.0001 ));
123
121
REQUIRE (damerau_levenshtein_normalized_similarity (test, replace_all) == 0.0 );
124
122
125
123
{
126
124
std::string s1 = " CA" ;
127
125
std::string s2 = " ABC" ;
128
- REQUIRE (damerau_levenshtein_normalized_similarity (s1, s2) ==
129
- Catch::Approx (0.33333 ).epsilon (0.0001 ));
126
+ REQUIRE_THAT (damerau_levenshtein_normalized_similarity (s1, s2), WithinAbs (0.33333 , 0.0001 ));
130
127
}
131
128
}
132
129
}
0 commit comments