Skip to content

Commit 50af5ba

Browse files
committed
Catch up to upstream Java 0.21 release
1 parent fde7399 commit 50af5ba

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/F23.StringSimilarity/NGram.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public double Distance(string s0, string s1)
5656
int sl = s0.Length;
5757
int tl = s1.Length;
5858

59+
if (s0.Equals(s1))
60+
{
61+
return 0;
62+
}
63+
5964
if (sl == 0 || tl == 0)
6065
{
6166
if (sl == tl)

test/F23.StringSimilarity.Tests/NGramTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ public void TestDistance()
1414
var ngram = new NGram();
1515

1616
Assert.True(ngram.Distance(s0, s1) < ngram.Distance(s0, s2));
17+
18+
Assert.Equal(
19+
expected: 0.0,
20+
actual: ngram.Distance("SIJK", "SIJK"),
21+
precision: 1); // 0.0
22+
23+
Assert.Equal(
24+
expected: 0.0,
25+
actual: ngram.Distance("S", "S"),
26+
precision: 1); // 0.0
27+
28+
Assert.Equal(
29+
expected: 1.0,
30+
actual: ngram.Distance("", "S"),
31+
precision: 1); // 0.0
32+
33+
Assert.Equal(
34+
expected: 1.0,
35+
actual: ngram.Distance("", "SIJK"),
36+
precision: 1); // 0.0
1737
}
1838
}
1939
}

test/F23.StringSimilarity.Tests/QGramTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525

26+
using System;
2627
using System.Diagnostics.CodeAnalysis;
2728
using Xunit;
2829

@@ -45,6 +46,16 @@ public void TestDistance()
4546
var result = instance.Distance("ABCD", "ABCE");
4647

4748
Assert.Equal(expected: 2.0, actual: result);
49+
50+
Assert.Equal(
51+
expected: 0.0,
52+
actual: instance.Distance("S", "S"),
53+
precision: 1); // 0.0
54+
55+
Assert.Equal(
56+
expected: 0.0,
57+
actual: instance.Distance("012345", "012345"),
58+
precision: 1); // 0.0
4859
}
4960
}
5061
}

0 commit comments

Comments
 (0)