Skip to content

Commit

Permalink
handle empty strings more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Apr 16, 2023
1 parent a33e6f2 commit faa0687
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion extras/rapidfuzz_amalgamated.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// RapidFuzz v1.0.2
// Generated: 2023-04-16 23:07:04.138210
// Generated: 2023-04-17 01:55:45.256062
// ----------------------------------------------------------
// This file is an amalgamation of multiple different files.
// You probably shouldn't edit it directly.
Expand Down Expand Up @@ -5203,6 +5203,8 @@ double jaro_similarity(Range<InputIt1> P, Range<InputIt2> T, double score_cutoff
int64_t P_len = P.size();
int64_t T_len = T.size();

if (!P_len && !T_len) return 1.0;

/* filter out based on the length difference between the two strings */
if (!jaro_length_filter(P_len, T_len, score_cutoff)) return 0.0;

Expand Down Expand Up @@ -5248,6 +5250,8 @@ double jaro_similarity(const BlockPatternMatchVector& PM, Range<InputIt1> P, Ran
int64_t P_len = P.size();
int64_t T_len = T.size();

if (!P_len && !T_len) return 1.0;

/* filter out based on the length difference between the two strings */
if (!jaro_length_filter(P_len, T_len, score_cutoff)) return 0.0;

Expand Down
4 changes: 4 additions & 0 deletions rapidfuzz/distance/Jaro_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ double jaro_similarity(Range<InputIt1> P, Range<InputIt2> T, double score_cutoff
int64_t P_len = P.size();
int64_t T_len = T.size();

if (!P_len && !T_len) return 1.0;

/* filter out based on the length difference between the two strings */
if (!jaro_length_filter(P_len, T_len, score_cutoff)) return 0.0;

Expand Down Expand Up @@ -388,6 +390,8 @@ double jaro_similarity(const BlockPatternMatchVector& PM, Range<InputIt1> P, Ran
int64_t P_len = P.size();
int64_t T_len = T.size();

if (!P_len && !T_len) return 1.0;

/* filter out based on the length difference between the two strings */
if (!jaro_length_filter(P_len, T_len, score_cutoff)) return 0.0;

Expand Down
2 changes: 1 addition & 1 deletion rapidfuzz_reference/Jaro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ double jaro_similarity(InputIt1 P_first, InputIt1 P_last, InputIt2 T_first, Inpu
size_t P_len = static_cast<size_t>(std::distance(P_first, P_last));
size_t T_len = static_cast<size_t>(std::distance(T_first, T_last));

if (!P_len || !T_len) return 0;
if (!P_len || !T_len) return 1.0;

std::vector<int> P_flag(P_len + 1);
std::vector<int> T_flag(T_len + 1);
Expand Down
4 changes: 2 additions & 2 deletions test/distance/tests-Jaro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ double jaro_distance(const Sentence1& s1, const Sentence2& s2, double score_cuto
*/
TEST_CASE("JaroWinklerTest")
{
std::array<std::string, 19> names = {"james", "robert", "john", "michael", "william",
std::array<std::string, 20> names = {"james", "robert", "john", "michael", "william",
"david", "joseph", "thomas", "charles", "mary",
"patricia", "jennifer", "linda", "elizabeth", "barbara",
"susan", "jessica", "sarah", "karen"};
"susan", "jessica", "sarah", "karen", ""};

SECTION("testFullResultWithScoreCutoff")
{
Expand Down
4 changes: 2 additions & 2 deletions test/distance/tests-JaroWinkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ double jaro_winkler_distance(const Sentence1& s1, const Sentence2& s2, double pr
*/
TEST_CASE("JaroWinklerTest")
{
std::array<std::string, 19> names = {"james", "robert", "john", "michael", "william",
std::array<std::string, 20> names = {"james", "robert", "john", "michael", "william",
"david", "joseph", "thomas", "charles", "mary",
"patricia", "jennifer", "linda", "elizabeth", "barbara",
"susan", "jessica", "sarah", "karen"};
"susan", "jessica", "sarah", "karen", ""};

SECTION("testFullResultWithScoreCutoff")
{
Expand Down

4 comments on commit faa0687

@mgorny
Copy link

@mgorny mgorny commented on faa0687 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing the same test failures as CI. Do you need me to report a bug? ;-)

@maxbachmann
Copy link
Member Author

@maxbachmann maxbachmann commented on faa0687 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have really checked the CI one more time before pressing the release button :/

At least this is only a bug in the test suite.

@maxbachmann
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I released a fixed v1.11.2 release

@mgorny
Copy link

@mgorny mgorny commented on faa0687 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

Please sign in to comment.