Skip to content

Commit 6ec7699

Browse files
committed
downgrade catch2 for C++11 support
1 parent fdbcc21 commit 6ec7699

13 files changed

+202
-194
lines changed

test/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
find_package(Catch2 3 QUIET)
1+
#find_package(Catch2 2 QUIET)
22
if (Catch2_FOUND)
33
message("Using system supplied version of Catch2")
44
else()
@@ -7,7 +7,7 @@ else()
77
FetchContent_Declare(
88
Catch2
99
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
10-
GIT_TAG v3.4.0
10+
GIT_TAG v2.13.10
1111
)
1212
FetchContent_MakeAvailable(Catch2)
1313
endif()
@@ -50,9 +50,9 @@ if (RAPIDFUZZ_ENABLE_LINTERS)
5050
endif()
5151

5252
function(rapidfuzz_add_test test)
53-
add_executable(test_${test} tests-${test}.cpp)
53+
add_executable(test_${test} tests-main.cpp tests-${test}.cpp)
5454
target_link_libraries(test_${test} ${PROJECT_NAME})
55-
target_link_libraries(test_${test} Catch2::Catch2WithMain)
55+
target_link_libraries(test_${test} Catch2::Catch2)
5656
if (RAPIDFUZZ_ENABLE_LINTERS)
5757
target_link_libraries(test_${test} project_warnings)
5858
endif()

test/distance/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function(rapidfuzz_add_test test)
2-
add_executable(test_${test} tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp)
2+
add_executable(test_${test} ../tests-main.cpp tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp)
33
target_link_libraries(test_${test} PRIVATE ${PROJECT_NAME})
4-
target_link_libraries(test_${test} PRIVATE Catch2::Catch2WithMain)
4+
target_link_libraries(test_${test} PRIVATE Catch2::Catch2)
55
if (RAPIDFUZZ_ENABLE_LINTERS)
66
target_link_libraries(test_${test} PRIVATE project_warnings)
77
endif()

test/distance/tests-DamerauLevenshtein.cpp

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <catch2/catch_approx.hpp>
2-
#include <catch2/catch_test_macros.hpp>
1+
#include <catch2/catch.hpp>
32
#include <rapidfuzz/details/Range.hpp>
43
#include <rapidfuzz/details/types.hpp>
54
#include <string>
@@ -8,6 +7,8 @@
87

98
#include "../common.hpp"
109

10+
using Catch::Matchers::WithinAbs;
11+
1112
template <typename Sentence1, typename Sentence2>
1213
size_t damerau_levenshtein_distance(const Sentence1& s1, const Sentence2& s2,
1314
size_t max = std::numeric_limits<size_t>::max())
@@ -60,10 +61,10 @@ double damerau_levenshtein_normalized_distance(const Sentence1& s1, const Senten
6061
rapidfuzz::experimental::CachedDamerauLevenshtein scorer(s1);
6162
double res4 = scorer.normalized_distance(s2, score_cutoff);
6263
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));
6768
return res1;
6869
}
6970

@@ -80,10 +81,10 @@ double damerau_levenshtein_normalized_similarity(const Sentence1& s1, const Sent
8081
rapidfuzz::experimental::CachedDamerauLevenshtein scorer(s1);
8182
double res4 = scorer.normalized_similarity(s2, score_cutoff);
8283
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));
8788
return res1;
8889
}
8990

@@ -114,19 +115,15 @@ TEST_CASE("Levenshtein")
114115
SECTION("weighted levenshtein calculates correct ratios")
115116
{
116117
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));
123121
REQUIRE(damerau_levenshtein_normalized_similarity(test, replace_all) == 0.0);
124122

125123
{
126124
std::string s1 = "CA";
127125
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));
130127
}
131128
}
132129
}

test/distance/tests-Hamming.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#include <catch2/catch_approx.hpp>
2-
#include <catch2/catch_test_macros.hpp>
1+
#include <catch2/catch.hpp>
32
#include <rapidfuzz/distance.hpp>
43
#include <rapidfuzz/distance/Hamming.hpp>
54
#include <string>
65

76
#include "../common.hpp"
87

8+
using Catch::Matchers::WithinAbs;
9+
910
template <typename Sentence1, typename Sentence2>
1011
size_t hamming_distance(const Sentence1& s1, const Sentence2& s2,
1112
size_t max = std::numeric_limits<size_t>::max())
@@ -55,10 +56,10 @@ double hamming_normalized_distance(const Sentence1& s1, const Sentence2& s2, dou
5556
rapidfuzz::CachedHamming scorer(s1);
5657
double res4 = scorer.normalized_distance(s2, score_cutoff);
5758
double res5 = scorer.normalized_distance(s2.begin(), s2.end(), score_cutoff);
58-
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
59-
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
60-
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
61-
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
59+
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
60+
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
61+
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
62+
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
6263
return res1;
6364
}
6465

@@ -74,10 +75,10 @@ double hamming_normalized_similarity(const Sentence1& s1, const Sentence2& s2, d
7475
rapidfuzz::CachedHamming scorer(s1);
7576
double res4 = scorer.normalized_similarity(s2, score_cutoff);
7677
double res5 = scorer.normalized_similarity(s2.begin(), s2.end(), score_cutoff);
77-
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
78-
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
79-
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
80-
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
78+
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
79+
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
80+
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
81+
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
8182
return res1;
8283
}
8384

test/distance/tests-Indel.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
#include <catch2/catch_approx.hpp>
2-
#include <catch2/catch_test_macros.hpp>
1+
#include <catch2/catch.hpp>
32
#include <string>
43

54
#include <rapidfuzz/distance.hpp>
65
#include <rapidfuzz/distance/Indel.hpp>
76

87
#include "../common.hpp"
98

10-
using Catch::Approx;
9+
using Catch::Matchers::WithinAbs;
1110

1211
template <typename Sentence1, typename Sentence2>
1312
size_t indel_distance(const Sentence1& s1, const Sentence2& s2,
@@ -141,13 +140,13 @@ double indel_normalized_distance(const Sentence1& s1, const Sentence2& s2, doubl
141140
simd_scorer.normalized_distance(&results[0], results.size(), s2, score_cutoff);
142141
}
143142

144-
REQUIRE(res1 == Catch::Approx(results[0]).epsilon(0.0001));
143+
REQUIRE_THAT(res1, WithinAbs(results[0], 0.0001));
145144
}
146145
#endif
147-
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
148-
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
149-
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
150-
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
146+
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
147+
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
148+
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
149+
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
151150
return res1;
152151
}
153152

@@ -188,13 +187,13 @@ double indel_normalized_similarity(const Sentence1& s1, const Sentence2& s2, dou
188187
simd_scorer.normalized_similarity(&results[0], results.size(), s2, score_cutoff);
189188
}
190189

191-
REQUIRE(res1 == Catch::Approx(results[0]).epsilon(0.0001));
190+
REQUIRE_THAT(res1, WithinAbs(results[0], 0.0001));
192191
}
193192
#endif
194-
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
195-
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
196-
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
197-
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
193+
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
194+
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
195+
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
196+
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
198197
return res1;
199198
}
200199

@@ -247,8 +246,9 @@ TEST_CASE("Indel")
247246
{
248247
std::string a = "001";
249248
std::string b = "220";
250-
REQUIRE(Approx(0.3333333) == rapidfuzz::indel_normalized_similarity(a, b));
251-
REQUIRE(Approx(0.3333333) == rapidfuzz::CachedIndel<char>(a).normalized_similarity(b));
249+
REQUIRE_THAT(rapidfuzz::indel_normalized_similarity(a, b), WithinAbs(0.3333333, 0.000001));
250+
REQUIRE_THAT(rapidfuzz::CachedIndel<char>(a).normalized_similarity(b),
251+
WithinAbs(0.3333333, 0.000001));
252252
}
253253

254254
SECTION("test banded implementation")

0 commit comments

Comments
 (0)