diff --git a/lib/ratios/simple_ratio.dart b/lib/ratios/simple_ratio.dart index b6d142b..57d5970 100644 --- a/lib/ratios/simple_ratio.dart +++ b/lib/ratios/simple_ratio.dart @@ -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(); } } diff --git a/test/fuzzywuzzy_test.dart b/test/fuzzywuzzy_test.dart index d762783..f7f6fae 100644 --- a/test/fuzzywuzzy_test.dart +++ b/test/fuzzywuzzy_test.dart @@ -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', () {