Fixed Jaro-Winkler crash when comparing two single characters
This commit is contained in:
parent
05ae72ba9e
commit
0dcb48a3cd
|
@ -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] {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue