Skip to content

Commit

Permalink
downgrade catch2 for C++11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Dec 24, 2024
1 parent fdbcc21 commit 6ec7699
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 194 deletions.
8 changes: 4 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Catch2 3 QUIET)
#find_package(Catch2 2 QUIET)
if (Catch2_FOUND)
message("Using system supplied version of Catch2")
else()
Expand All @@ -7,7 +7,7 @@ else()
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
GIT_TAG v2.13.10
)
FetchContent_MakeAvailable(Catch2)
endif()
Expand Down Expand Up @@ -50,9 +50,9 @@ if (RAPIDFUZZ_ENABLE_LINTERS)
endif()

function(rapidfuzz_add_test test)
add_executable(test_${test} tests-${test}.cpp)
add_executable(test_${test} tests-main.cpp tests-${test}.cpp)
target_link_libraries(test_${test} ${PROJECT_NAME})
target_link_libraries(test_${test} Catch2::Catch2WithMain)
target_link_libraries(test_${test} Catch2::Catch2)
if (RAPIDFUZZ_ENABLE_LINTERS)
target_link_libraries(test_${test} project_warnings)
endif()
Expand Down
4 changes: 2 additions & 2 deletions test/distance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function(rapidfuzz_add_test test)
add_executable(test_${test} tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp)
add_executable(test_${test} ../tests-main.cpp tests-${test}.cpp examples/ocr.cpp examples/pythonLevenshteinIssue9.cpp)
target_link_libraries(test_${test} PRIVATE ${PROJECT_NAME})
target_link_libraries(test_${test} PRIVATE Catch2::Catch2WithMain)
target_link_libraries(test_${test} PRIVATE Catch2::Catch2)
if (RAPIDFUZZ_ENABLE_LINTERS)
target_link_libraries(test_${test} PRIVATE project_warnings)
endif()
Expand Down
33 changes: 15 additions & 18 deletions test/distance/tests-DamerauLevenshtein.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>
#include <rapidfuzz/details/Range.hpp>
#include <rapidfuzz/details/types.hpp>
#include <string>
Expand All @@ -8,6 +7,8 @@

#include "../common.hpp"

using Catch::Matchers::WithinAbs;

template <typename Sentence1, typename Sentence2>
size_t damerau_levenshtein_distance(const Sentence1& s1, const Sentence2& s2,
size_t max = std::numeric_limits<size_t>::max())
Expand Down Expand Up @@ -60,10 +61,10 @@ double damerau_levenshtein_normalized_distance(const Sentence1& s1, const Senten
rapidfuzz::experimental::CachedDamerauLevenshtein scorer(s1);
double res4 = scorer.normalized_distance(s2, score_cutoff);
double res5 = scorer.normalized_distance(s2.begin(), s2.end(), score_cutoff);
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
return res1;
}

Expand All @@ -80,10 +81,10 @@ double damerau_levenshtein_normalized_similarity(const Sentence1& s1, const Sent
rapidfuzz::experimental::CachedDamerauLevenshtein scorer(s1);
double res4 = scorer.normalized_similarity(s2, score_cutoff);
double res5 = scorer.normalized_similarity(s2.begin(), s2.end(), score_cutoff);
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
return res1;
}

Expand Down Expand Up @@ -114,19 +115,15 @@ TEST_CASE("Levenshtein")
SECTION("weighted levenshtein calculates correct ratios")
{
REQUIRE(damerau_levenshtein_normalized_similarity(test, test) == 1.0);
REQUIRE(damerau_levenshtein_normalized_similarity(test, no_suffix) ==
Catch::Approx(0.75).epsilon(0.0001));
REQUIRE(damerau_levenshtein_normalized_similarity(swapped1, swapped2) ==
Catch::Approx(0.75).epsilon(0.0001));
REQUIRE(damerau_levenshtein_normalized_similarity(test, no_suffix2) ==
Catch::Approx(0.75).epsilon(0.0001));
REQUIRE_THAT(damerau_levenshtein_normalized_similarity(test, no_suffix), WithinAbs(0.75, 0.0001));
REQUIRE_THAT(damerau_levenshtein_normalized_similarity(swapped1, swapped2), WithinAbs(0.75, 0.0001));
REQUIRE_THAT(damerau_levenshtein_normalized_similarity(test, no_suffix2), WithinAbs(0.75, 0.0001));
REQUIRE(damerau_levenshtein_normalized_similarity(test, replace_all) == 0.0);

{
std::string s1 = "CA";
std::string s2 = "ABC";
REQUIRE(damerau_levenshtein_normalized_similarity(s1, s2) ==
Catch::Approx(0.33333).epsilon(0.0001));
REQUIRE_THAT(damerau_levenshtein_normalized_similarity(s1, s2), WithinAbs(0.33333, 0.0001));
}
}
}
21 changes: 11 additions & 10 deletions test/distance/tests-Hamming.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>
#include <rapidfuzz/distance.hpp>
#include <rapidfuzz/distance/Hamming.hpp>
#include <string>

#include "../common.hpp"

using Catch::Matchers::WithinAbs;

template <typename Sentence1, typename Sentence2>
size_t hamming_distance(const Sentence1& s1, const Sentence2& s2,
size_t max = std::numeric_limits<size_t>::max())
Expand Down Expand Up @@ -55,10 +56,10 @@ double hamming_normalized_distance(const Sentence1& s1, const Sentence2& s2, dou
rapidfuzz::CachedHamming scorer(s1);
double res4 = scorer.normalized_distance(s2, score_cutoff);
double res5 = scorer.normalized_distance(s2.begin(), s2.end(), score_cutoff);
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
return res1;
}

Expand All @@ -74,10 +75,10 @@ double hamming_normalized_similarity(const Sentence1& s1, const Sentence2& s2, d
rapidfuzz::CachedHamming scorer(s1);
double res4 = scorer.normalized_similarity(s2, score_cutoff);
double res5 = scorer.normalized_similarity(s2.begin(), s2.end(), score_cutoff);
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
return res1;
}

Expand Down
30 changes: 15 additions & 15 deletions test/distance/tests-Indel.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch.hpp>
#include <string>

#include <rapidfuzz/distance.hpp>
#include <rapidfuzz/distance/Indel.hpp>

#include "../common.hpp"

using Catch::Approx;
using Catch::Matchers::WithinAbs;

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

REQUIRE(res1 == Catch::Approx(results[0]).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(results[0], 0.0001));
}
#endif
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
return res1;
}

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

REQUIRE(res1 == Catch::Approx(results[0]).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(results[0], 0.0001));
}
#endif
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
REQUIRE(res1 == Catch::Approx(res5).epsilon(0.0001));
REQUIRE_THAT(res1, WithinAbs(res2, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res3, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res4, 0.0001));
REQUIRE_THAT(res1, WithinAbs(res5, 0.0001));
return res1;
}

Expand Down Expand Up @@ -247,8 +246,9 @@ TEST_CASE("Indel")
{
std::string a = "001";
std::string b = "220";
REQUIRE(Approx(0.3333333) == rapidfuzz::indel_normalized_similarity(a, b));
REQUIRE(Approx(0.3333333) == rapidfuzz::CachedIndel<char>(a).normalized_similarity(b));
REQUIRE_THAT(rapidfuzz::indel_normalized_similarity(a, b), WithinAbs(0.3333333, 0.000001));
REQUIRE_THAT(rapidfuzz::CachedIndel<char>(a).normalized_similarity(b),
WithinAbs(0.3333333, 0.000001));
}

SECTION("test banded implementation")
Expand Down
Loading

0 comments on commit 6ec7699

Please sign in to comment.