Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5daaa2b

Browse files
committed
Add regular (non-null/empty) Cosine Test Cases.
1 parent 0c20faa commit 5daaa2b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

‎src/test/java/info/debatty/java/stringsimilarity/CosineTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,33 @@ public final void testLargeString() throws IOException {
8080
@Test
8181
public final void testDistance() {
8282
Cosine instance = new Cosine();
83+
84+
double result = instance.distance("ABC", "ABCE");
85+
assertEquals(0.29, result, 0.01);
86+
8387
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);
84108

85-
// TODO: regular (non-null/empty) distance tests
109+
assertEquals(0.1885, similarity, 0.001);
86110
}
87111

88112
private static String readResourceFile(String file) throws IOException {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /