Skip to content

Commit 7750b89

Browse files
authored
Add files via upload
Test unit for Ratcliff-Obershelp algorithm
1 parent 5d041fa commit 7750b89

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 info.debatty.java.stringsimilarity.testutil.NullEmptyTests;
28+
import org.junit.Test;
29+
import static org.junit.Assert.*;
30+
31+
/**
32+
*
33+
* @author Agung Nugroho
34+
*/
35+
public class RatcliffObershelpTest {
36+
37+
38+
/**
39+
* Test of similarity method, of class RatcliffObershelp.
40+
*/
41+
@Test
42+
public final void testSimilarity() {
43+
System.out.println("similarity");
44+
RatcliffObershelp instance = new RatcliffObershelp();
45+
assertEquals(
46+
0.888888,
47+
instance.similarity("My string", "My tsring"),
48+
0.000001);
49+
50+
assertEquals(
51+
0.777778,
52+
instance.similarity("My string", "My ntrisg"),
53+
0.000001);
54+
55+
// test data from essay by Ilya Ilyankou
56+
// "Comparison of Jaro-Winkler and Ratcliff/Obershelp algorithms
57+
// in spell check"
58+
// https://ilyankou.files.wordpress.com/2015/06/ib-extended-essay.pdf
59+
// p13, expected result is 0.857
60+
assertEquals(
61+
0.857,
62+
instance.similarity("MATEMATICA", "MATHEMATICS"),
63+
0.001);
64+
65+
// these following test data were based on stringmetric
66+
// https://github.com/rockymadden/stringmetric
67+
// expected output is 0.7368421052631579
68+
assertEquals(
69+
0.736842,
70+
instance.similarity("aleksander", "alexandre"),
71+
0.000001);
72+
73+
// expected output is 0.6666666666666666
74+
assertEquals(
75+
0.666666,
76+
instance.similarity("pennsylvania", "pencilvaneya"),
77+
0.000001);
78+
79+
// test data from wikipedia
80+
// https://en.wikipedia.org/wiki/Gestalt_Pattern_Matching
81+
// expected output is 14/18 = 0.7777777777777778‬
82+
assertEquals(
83+
0.777778,
84+
instance.similarity("WIKIMEDIA", "WIKIMANIA"),
85+
0.000001);
86+
87+
NullEmptyTests.testSimilarity(instance);
88+
}
89+
90+
@Test
91+
public final void testDistance() {
92+
RatcliffObershelp instance = new RatcliffObershelp();
93+
NullEmptyTests.testDistance(instance);
94+
95+
// TODO: regular (non-null/empty) distance tests
96+
}
97+
}

0 commit comments

Comments
 (0)