@@ -80,9 +80,33 @@ public final void testLargeString() throws IOException {
80
80
@ Test
81
81
public final void testDistance () {
82
82
Cosine instance = new Cosine ();
83
+
84
+ double result = instance .distance ("ABC" , "ABCE" );
85
+ assertEquals (0.29 , result , 0.01 );
86
+
83
87
NullEmptyTests .testDistance (instance );
88
+ }
89
+
90
+ @ Test
91
+ public final void testDistanceSmallString () {
92
+ System .out .println ("test small string" );
93
+ Cosine instance = new Cosine (3 );
94
+ double result = instance .distance ("AB" , "ABCE" );
95
+ assertEquals (1 , result , 0.00001 );
96
+ }
97
+
98
+ @ Test
99
+ public final void testDistanceLargeString () throws IOException {
100
+
101
+ System .out .println ("Test with large strings" );
102
+ Cosine cos = new Cosine ();
103
+
104
+ // read from 2 text files
105
+ String string1 = readResourceFile ("71816-2.txt" );
106
+ String string2 = readResourceFile ("11328-1.txt" );
107
+ double similarity = cos .distance (string1 , string2 );
84
108
85
- // TODO: regular (non-null/empty) distance tests
109
+ assertEquals ( 0.1885 , similarity , 0.001 );
86
110
}
87
111
88
112
private static String readResourceFile (String file ) throws IOException {
0 commit comments