Skip to content

Commit

Permalink
fix(ratio): handle NaNs
Browse files Browse the repository at this point in the history
Signed-off-by: Sphericalkat <[email protected]>
  • Loading branch information
SphericalKat committed Aug 15, 2024
1 parent 26d507a commit 5a79f53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ratios/simple_ratio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import '../diffutils/diff_utils.dart';
class SimpleRatio implements Applicable {
@override
int apply(String s1, String s2) {
return (100 * DiffUtils.getRatio(s1, s2)).round();
final diff = DiffUtils.getRatio(s1, s2);
if (diff.isNaN) {
return 0;
}
return (diff * 100).round();
}
}
5 changes: 5 additions & 0 deletions test/fuzzywuzzy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ void main() {
'the quick brown fox jumps over the small lazy dog');
expect(result, 97);
});

test('Weighted ratio with newlines', () {
final result = weightedRatio('\n \n ', 'test');
expect(result, 0);
});
});

group('Extractors', () {
Expand Down

0 comments on commit 5a79f53

Please sign in to comment.