Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Test unit for Ratcliff-Obershelp algorithm
  • Loading branch information
denmase authored May 11, 2020
1 parent 5d041fa commit 7750b89
Showing 1 changed file with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* The MIT License
*
* Copyright 2015 Thibault Debatty.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package info.debatty.java.stringsimilarity;

import info.debatty.java.stringsimilarity.testutil.NullEmptyTests;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Agung Nugroho
*/
public class RatcliffObershelpTest {


/**
* Test of similarity method, of class RatcliffObershelp.
*/
@Test
public final void testSimilarity() {
System.out.println("similarity");
RatcliffObershelp instance = new RatcliffObershelp();
assertEquals(
0.888888,
instance.similarity("My string", "My tsring"),
0.000001);

assertEquals(
0.777778,
instance.similarity("My string", "My ntrisg"),
0.000001);

// test data from essay by Ilya Ilyankou
// "Comparison of Jaro-Winkler and Ratcliff/Obershelp algorithms
// in spell check"
// https://ilyankou.files.wordpress.com/2015/06/ib-extended-essay.pdf
// p13, expected result is 0.857
assertEquals(
0.857,
instance.similarity("MATEMATICA", "MATHEMATICS"),
0.001);

// these following test data were based on stringmetric
// https://github.com/rockymadden/stringmetric
// expected output is 0.7368421052631579
assertEquals(
0.736842,
instance.similarity("aleksander", "alexandre"),
0.000001);

// expected output is 0.6666666666666666
assertEquals(
0.666666,
instance.similarity("pennsylvania", "pencilvaneya"),
0.000001);

// test data from wikipedia
// https://en.wikipedia.org/wiki/Gestalt_Pattern_Matching
// expected output is 14/18 = 0.7777777777777778‬
assertEquals(
0.777778,
instance.similarity("WIKIMEDIA", "WIKIMANIA"),
0.000001);

NullEmptyTests.testSimilarity(instance);
}

@Test
public final void testDistance() {
RatcliffObershelp instance = new RatcliffObershelp();
NullEmptyTests.testDistance(instance);

// TODO: regular (non-null/empty) distance tests
}
}

0 comments on commit 7750b89

Please sign in to comment.