Skip to content

Commit 890e6fe

Browse files
committed
added qgram and sorensen dice tests
1 parent fafdf4c commit 890e6fe

3 files changed

Lines changed: 148 additions & 1 deletion

File tree

src/main/java/info/debatty/java/stringsimilarity/QGram.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@ public double distance(String s1, String s2) {
4848
}
4949

5050
return d;
51-
5251
}
5352
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2015 Thibault Debatty.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package info.debatty.java.stringsimilarity;
26+
27+
import org.junit.After;
28+
import org.junit.AfterClass;
29+
import org.junit.Before;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import static org.junit.Assert.*;
33+
34+
/**
35+
*
36+
* @author Thibault Debatty
37+
*/
38+
public class QGramTest {
39+
40+
public QGramTest() {
41+
}
42+
43+
@BeforeClass
44+
public static void setUpClass() {
45+
}
46+
47+
@AfterClass
48+
public static void tearDownClass() {
49+
}
50+
51+
@Before
52+
public void setUp() {
53+
}
54+
55+
@After
56+
public void tearDown() {
57+
}
58+
59+
/**
60+
* Test of distance method, of class QGram.
61+
*/
62+
@Test
63+
public void testDistance() {
64+
System.out.println("distance");
65+
QGram instance = new QGram(2);
66+
// AB BC CD CE
67+
// 1 1 1 0
68+
// 1 1 0 1
69+
// Total: 2
70+
double result = instance.distance("ABCD", "ABCE");
71+
assertEquals(2.0, result, 0.0);
72+
}
73+
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2015 Thibault Debatty.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package info.debatty.java.stringsimilarity;
26+
27+
import org.junit.After;
28+
import org.junit.AfterClass;
29+
import org.junit.Before;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import static org.junit.Assert.*;
33+
34+
/**
35+
*
36+
* @author Thibault Debatty
37+
*/
38+
public class SorensenDiceTest {
39+
40+
public SorensenDiceTest() {
41+
}
42+
43+
@BeforeClass
44+
public static void setUpClass() {
45+
}
46+
47+
@AfterClass
48+
public static void tearDownClass() {
49+
}
50+
51+
@Before
52+
public void setUp() {
53+
}
54+
55+
@After
56+
public void tearDown() {
57+
}
58+
59+
/**
60+
* Test of similarity method, of class SorensenDice.
61+
*/
62+
@Test
63+
public void testSimilarity() {
64+
System.out.println("similarity");
65+
SorensenDice instance = new SorensenDice(2);
66+
// AB BC CD DE DF FG
67+
// 1 1 1 1 0 0
68+
// 1 1 1 0 1 1
69+
// => 2 x 3 / (4 + 5) = 6/9 = 0.6666
70+
double result = instance.similarity("ABCDE", "ABCDFG");
71+
assertEquals(0.6666, result, 0.0001);
72+
}
73+
74+
}

0 commit comments

Comments
 (0)