File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
test/F23.StringSimilarity.Tests Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 2323 */
2424
2525
26+ using System ;
2627using System . Diagnostics . CodeAnalysis ;
2728using 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}
You can’t perform that action at this time.
0 commit comments