PageRenderTime 1ms CodeModel.GetById 25ms app.highlight 10ms RepoModel.GetById 0ms app.codeStats 0ms

/test/spelling/corrector/SpellingCorrectorHelperTest.java

https://github.com/juliengrenier/java-spelling-corrector
Java | 71 lines | 63 code | 8 blank | 0 comment | 4 complexity | 9a3a35766d8ddaabadc94c2a7e6f4b40 MD5 | raw file
 1package spelling.corrector;
 2
 3import java.util.ArrayList;
 4import java.util.List;
 5
 6import junit.framework.TestCase;
 7
 8public abstract class SpellingCorrectorHelperTest extends
 9		TestCase {
10
11	public final void testGetDeletions() {
12		try {
13			List<String> expected = new ArrayList<String>();
14			expected.add("ase");
15			expected.add("cse");
16			expected.add("cae");
17			expected.add("cas");
18			List<String> result = getHelper().getDeletion("case");
19			assertEquals(expected, result);
20		} catch (Exception e) {
21			fail(e.getMessage());
22		}
23	}
24
25	public final void testGetTranspositions() {
26		try {
27			List<String> expected = new ArrayList<String>();
28			expected.add("acse");
29			expected.add("csae");
30			expected.add("caes");
31			List<String> result = getHelper().getTransposition("case");
32			assertEquals(expected, result);
33		} catch (Exception e) {
34			fail(e.getMessage());
35		}
36	}
37
38	public final void testGetAlterations() {
39		try {
40			List<String> expected = new ArrayList<String>();
41			String word = "case";
42			for (int i = 0; i < word.length(); i++) {
43				for (char c = 'a'; c <= 'z'; c++) {
44					expected.add(word.replace(word.charAt(i), c));
45				}
46			}
47			List<String> result = getHelper().getAlterations("case");
48			assertEquals(expected, result);
49		} catch (Exception e) {
50			fail(e.getMessage());
51		}
52	}
53
54	public final void testGetInsertions() {
55		try {
56			List<String> expected = new ArrayList<String>();
57			String word = "case";
58			for (int i = 0; i < word.length() + 1; i++) {
59				for (char c = 'a'; c <= 'z'; c++) {
60					expected.add(word.substring(0, i) + c + word.substring(i));
61				}
62			}
63			List<String> result = getHelper().getInsertions("case");
64			assertEquals(expected, result);
65		} catch (Exception e) {
66			fail(e.getMessage());
67		}
68	}
69
70	abstract protected SpellingCorrectorHelper getHelper();
71}