1 package org.incava.text; 2 3 import java.io.*; 4 import java.util.*; 5 import junit.framework.TestCase; 6 7 8 public class TestSpellChecker extends TestCase 9 { 10 public TestSpellChecker(String name) 11 { 12 super(name); 13 } 14 15 public void testSame() 16 { 17 SpellChecker sc = new SpellChecker(); 18 assertEquals(0, sc.editDistance("this", "this")); 19 assertEquals(0, sc.editDistance("THIS", "THIS")); 20 assertEquals(0, sc.editDistance("repository", "repository")); 21 } 22 23 public void testDifferent() 24 { 25 SpellChecker sc = new SpellChecker(); 26 27 assertEquals(1, sc.editDistance("the", "they")); 29 assertEquals(2, sc.editDistance("the", "their")); 30 assertEquals(3, sc.editDistance("they", "they're")); 31 assertEquals(4, sc.editDistance("the", "theatre", 5)); 32 assertEquals(4, sc.editDistance("the", "theater", 5)); 33 34 assertEquals(1, sc.editDistance("they", "the")); 36 assertEquals(2, sc.editDistance("their", "the")); 37 assertEquals(3, sc.editDistance("they're", "they")); 38 assertEquals(4, sc.editDistance("theatre", "the", 5)); 39 assertEquals(4, sc.editDistance("theater", "the", 5)); 40 41 assertEquals(2, sc.editDistance("theater", "theatre")); 43 assertEquals(2, sc.editDistance("center", "centre")); 44 assertEquals(2, sc.editDistance("realize", "realise")); 45 assertEquals(4, sc.editDistance("realize", "reality", 5)); 46 47 assertEquals(1, sc.editDistance("here", "there")); 49 assertEquals(5, sc.editDistance("hit", "miss", 5)); 50 assertEquals(6, sc.editDistance("up", "down", 6)); 51 assertEquals(7, sc.editDistance("feast", "famine", 7)); 52 } 53 54 public void testDictionary() 55 { 56 SpellChecker sc = new SpellChecker(); 57 sc.addDictionary("/home/jpace/proj/doctorj/etc/words.en_US"); 58 59 assertTrue(sc.hasWord("locate")); 60 assertTrue(sc.hasWord("logarithm")); 61 assertFalse(sc.hasWord("eujifferous")); 63 Map nearMatches = new TreeMap(); 64 boolean isOK = sc.isCorrect("badd", nearMatches); 65 tr.Ace.log("isOK: " + isOK); 66 tr.Ace.log("nearMatches", nearMatches); 67 } 68 69 } 70 | Popular Tags |