-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestLexicon.java
60 lines (50 loc) · 1.92 KB
/
TestLexicon.java
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
import static org.junit.Assert.*;
import org.junit.*;
import java.util.*;
public class TestLexicon {
private ArrayList<String> myWords;
private ArrayList<String> myPrefixes;
private ArrayList<String> myNonWords;
private ILexicon myLexicon;
public ILexicon makeLexicon(){
return new CompressedTrieLexicon();
}
@Before
public void setUp(){
String[] words = { "apple", "berry", "cherry", "date",
"fig", "melon", "orange", "pineapple",
"blueberry", "cherry-pie", "blueberry-pie",
"apple-pie", "pineapple-upside-down-cake",
"watermelon"};
String[] prefixes = { "pine", "blue", "water", "melo", "fi", "cherr"};
String[] nonWords = { "aardvark", "figgy", "melon-ball", "dater", "xylophone",
"oranges", "goofy", "mickey"};
myWords = new ArrayList<String>(Arrays.asList(words));
myPrefixes = new ArrayList<String>(Arrays.asList(prefixes));
myNonWords = new ArrayList<String>(Arrays.asList(nonWords));
myLexicon = makeLexicon();
myLexicon.load(myWords);
}
@Test
public void wordTest(){
assertEquals("size of lexicon failed",myWords.size(), myLexicon.size());
for(String s : myWords){
LexStatus stat = myLexicon.wordStatus(s);
assertEquals("fail for word: "+s,LexStatus.WORD,stat);
}
}
@Test
public void prefixTest(){
for(String s : myPrefixes){
LexStatus stat = myLexicon.wordStatus(s);
assertEquals("fail for prefix: "+s,LexStatus.PREFIX,stat);
}
}
@Test
public void nonWordTest(){
for(String s : myNonWords){
LexStatus stat = myLexicon.wordStatus(s);
assertEquals("fail for non word: "+s,LexStatus.NOT_WORD,stat);
}
}
}