-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpellTest.java
More file actions
124 lines (101 loc) · 4.24 KB
/
SpellTest.java
File metadata and controls
124 lines (101 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.io.IOException;
import java.io.File;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
/**
* The test class SpellTest.
*
* @author Iryna
* @version 3/14/18
*/
//add test for each answer in a requirenment question
public class SpellTest{
/**
* Default constructor for test class SpellTest
*/
public SpellTest() {
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp(){
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown(){
}
/**
* Tests if the dictionary set contains all the words from the file
* This test assums that the dictionary is correct if its size is equal to the file size
*
*/
@Test
public void testDictionary() throws IOException{
int fileSize = SpellChecker.countLinesInTextFile("words.txt");
SpellChecker check = new SpellChecker("words.txt");
//assertEquals(fileSize, check.getDictionary().size());
}
@Test
public void shouldReturnOriginalIfCorrect()throws IOException{
SpellChecker check = new SpellChecker("words.txt");
assertEquals("apple",check.checkWord("apple")) ;
assertEquals("Englisher",check.checkWord("Englisher")) ;
assertEquals("Aani",check.checkWord("Aani")) ;
assertEquals("imaginableness",check.checkWord("imaginableness")) ;
assertEquals("phototelegraphically",check.checkWord("phototelegraphically")) ;
assertEquals("separativeness",check.checkWord("separativeness")) ;
}
@Test
public void shouldReturnNoCorrectionsFoundIfNoCorrec() throws IOException{
SpellChecker check = new SpellChecker("words.txt");
assertEquals("No Correction Found", check.checkWord("abcdefghijklmnop"));
assertEquals("No Correction Found", check.checkWord("aabcdedfegwgaesbwtfghijklmnop"));
assertEquals("No Correction Found", check.checkWord("abcd"));
assertEquals("Jean-Christophe", check.checkWord("Jean--------Christophe"));
assertEquals("Jean-Pierre", check.checkWord("JJJJjjjeaaaan--------PiiiierrRRRrreeee"));
}
@Test
public void shouldFindClosestMatchingWord() throws IOException{
SpellChecker check = new SpellChecker("words.txt");
assertEquals("apple", check.findClosestMatchingWord("ApppLLee"));
//testing the worse case scenario - when the characters are subliated over numerous times in numerous locations
assertEquals("apple", check.findClosestMatchingWord("ApppLLee"));
assertEquals("apple", check.findClosestMatchingWord("ApppLLee"));
}
@Test
public void shouldFindClosestMatchingWordInWorseCaseScenario() throws IOException{
SpellChecker check = new SpellChecker("words.txt");
assertEquals("Aaru", check.findClosestMatchingWord("AAAAAAAAAaaaaaarrrrrrrrruuuuuuuu"));
assertEquals("abdominohysterectomy", check.findClosestMatchingWord("AaaAAaabbBBBbbBbdddddddDDoOOOOOOmmmmmmmiiiiiiiiiiiNNNNNnnnnoooooooohhhhhhhyyyyyyyyyyysssssssstttteeeerrrreeeeccccttttoooomMMyYYYY"));
}
@Test
public void shouldRemoveSingleDuplicate(){
assertEquals("aple",SpellChecker.makeCanonical("apple")) ;
assertEquals("abaf",SpellChecker.makeCanonical("abaff")) ;
assertEquals("aba",SpellChecker.makeCanonical("aba")) ;
}
@Test
public void shouldRemoveMultipleDuplicate(){
assertEquals("asba",SpellChecker.makeCanonical("assbaa")) ;
assertEquals("autosupresion",SpellChecker.makeCanonical("autosuppression")) ;
}
@Test
public void testLevenhstein() throws IOException{
SpellChecker check = new SpellChecker("words.txt");
assertEquals(1, check.modifiedLevenshteinDistance("appple","apple"));
assertEquals(4, check.modifiedLevenshteinDistance("apppleeee", "apple"));
assertEquals(5, check.modifiedLevenshteinDistance("jjeeaannss", "jeans"));
assertEquals(1, check.modifiedLevenshteinDistance("Ninevitish", "ninevitish"));
assertEquals(6, check.modifiedLevenshteinDistance("IIIIIIInermes", "Inermes"));
}
}