Skip to content

Commit

Permalink
Merge pull request #255 from ABridoux/bugfix/253-jaro-winkler-single-…
Browse files Browse the repository at this point in the history
…character

Fixed Jaro-Winkler crash when comparing two single characters
  • Loading branch information
ABridoux authored Jun 6, 2021
2 parents 05ae72b + 0dcb48a commit d122e68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Scout/Extensions/String+Jaro-Winkler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit d122e68

Please sign in to comment.