KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > text > TestNoCaseSpellChecker


1 package org.incava.text;
2
3 import java.io.*;
4 import java.util.*;
5 import junit.framework.TestCase;
6
7
8 public class TestNoCaseSpellChecker extends TestCase
9 {
10     public TestNoCaseSpellChecker(String JavaDoc name)
11     {
12         super(name);
13     }
14
15     public void testSame()
16     {
17         NoCaseSpellChecker sc = new NoCaseSpellChecker();
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         NoCaseSpellChecker sc = new NoCaseSpellChecker();
26
27         // additions
28
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         // deletions
35
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         // changes
42
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         // miscellaneous
48
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         NoCaseSpellChecker sc = new NoCaseSpellChecker();
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")); // alas.
62

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