Merge pull request #255 from ABridoux/bugfix/253-jaro-winkler-single-character

Fixed Jaro-Winkler crash when comparing two single characters
This commit is contained in:
Alexis Bridoux 2021-06-06 13:39:38 +02:00 committed by GitHub
commit d122e681cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -38,7 +38,7 @@ private struct JaroWinklerDistance {
self.string1 = string1
self.string2 = string2
maxSpacing = max(string1.count, string2.count) / 2 - 1
maxSpacing = max(0, max(string1.count, string2.count) / 2 - 1)
}
func computeMatches() -> [Int] {

View File

@ -33,4 +33,9 @@ final class String_JaroWinklerTests: XCTestCase {
let result = target.bestJaroWinklerMatchIn(propositions: propositions)
XCTAssertEqual(result, "version")
}
func testMatchSingleCharacters_Equals0() {
let result = "b".jaroWinklerDistance(from: "a")
XCTAssertEqual(result, 0)
}
}