Skip to content

Commit 5a79f53

Browse files
committed
fix(ratio): handle NaNs
Signed-off-by: Sphericalkat <[email protected]>
1 parent 26d507a commit 5a79f53

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/ratios/simple_ratio.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import '../diffutils/diff_utils.dart';
44
class SimpleRatio implements Applicable {
55
@override
66
int apply(String s1, String s2) {
7-
return (100 * DiffUtils.getRatio(s1, s2)).round();
7+
final diff = DiffUtils.getRatio(s1, s2);
8+
if (diff.isNaN) {
9+
return 0;
10+
}
11+
return (diff * 100).round();
812
}
913
}

test/fuzzywuzzy_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ void main() {
6060
'the quick brown fox jumps over the small lazy dog');
6161
expect(result, 97);
6262
});
63+
64+
test('Weighted ratio with newlines', () {
65+
final result = weightedRatio('\n \n ', 'test');
66+
expect(result, 0);
67+
});
6368
});
6469

6570
group('Extractors', () {

0 commit comments

Comments
 (0)