-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryLLTester.java
More file actions
130 lines (93 loc) · 4.39 KB
/
DictionaryLLTester.java
File metadata and controls
130 lines (93 loc) · 4.39 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
125
126
127
128
129
130
/**
*
*/
package spelling;
import static org.junit.Assert.*;
import java.util.LinkedList;
import org.junit.Before;
import org.junit.Test;
/**
* @author UC San Diego MOOC team
*
*/
public class DictionaryLLTester {
private String dictFile = "data/words.small.txt";
DictionaryLL emptyDict;
DictionaryLL smallDict;
DictionaryLL largeDict;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception
{
emptyDict = new DictionaryLL();
smallDict = new DictionaryLL();
largeDict = new DictionaryLL();
smallDict.addWord("Hello");
smallDict.addWord("HElLo");
smallDict.addWord("help");
smallDict.addWord("a");
smallDict.addWord("subsequent");
DictionaryLoader.loadDictionary(largeDict, dictFile);
System.out.println("Larg size "+largeDict.size());
}
/** Test if the size method is working correctly.
*/
@Test
public void testSize()
{
assertEquals("Testing size for empty dict", 0, emptyDict.size());
assertEquals("Testing size for small dict", 4, smallDict.size());
assertEquals("Testing size for large dict", 4438, largeDict.size());
}
/** Test the isWord method */
@Test
public void testIsWord()
{
assertEquals("Testing isWord on empty: Hello", false, emptyDict.isWord("Hello"));
assertEquals("Testing isWord on small: Hello", true, smallDict.isWord("Hello"));
assertEquals("Testing isWord on large: Hello", true, largeDict.isWord("Hello"));
assertEquals("Testing isWord on small: hello", true, smallDict.isWord("hello"));
assertEquals("Testing isWord on large: hello", true, largeDict.isWord("hello"));
assertEquals("Testing isWord on small: hellow", false, smallDict.isWord("hellow"));
assertEquals("Testing isWord on large: hellow", false, largeDict.isWord("hellow"));
assertEquals("Testing isWord on empty: empty string", false, emptyDict.isWord(""));
assertEquals("Testing isWord on small: empty string", false, smallDict.isWord(""));
assertEquals("Testing isWord on large: empty string", false, largeDict.isWord(""));
assertEquals("Testing isWord on small: no", false, smallDict.isWord("no"));
assertEquals("Testing isWord on large: no", true, largeDict.isWord("no"));
assertEquals("Testing isWord on small: subsequent", true, smallDict.isWord("subsequent"));
assertEquals("Testing isWord on large: subsequent", true, largeDict.isWord("subsequent"));
}
/** Test the addWord method */
@Test
public void addWord()
{
assertEquals("Asserting hellow is not in empty dict", false, emptyDict.isWord("hellow"));
assertEquals("Asserting hellow is not in small dict", false, smallDict.isWord("hellow"));
assertEquals("Asserting hellow is not in large dict", false, largeDict.isWord("hellow"));
emptyDict.addWord("hellow");
smallDict.addWord("hellow");
largeDict.addWord("hellow");
assertEquals("Asserting hellow is in empty dict", true, emptyDict.isWord("hellow"));
assertEquals("Asserting hellow is in small dict", true, smallDict.isWord("hellow"));
assertEquals("Asserting hellow is in large dict", true, largeDict.isWord("hellow"));
assertEquals("Asserting xyzabc is not in empty dict", false, emptyDict.isWord("xyzabc"));
assertEquals("Asserting xyzabc is not in small dict", false, smallDict.isWord("xyzabc"));
assertEquals("Asserting xyzabc is in large dict", false, largeDict.isWord("xyzabc"));
emptyDict.addWord("XYZAbC");
smallDict.addWord("XYZAbC");
largeDict.addWord("XYZAbC");
assertEquals("Asserting xyzabc is in empty dict", true, emptyDict.isWord("xyzabc"));
assertEquals("Asserting xyzabc is in small dict", true, smallDict.isWord("xyzabc"));
assertEquals("Asserting xyzabc is large dict", true, largeDict.isWord("xyzabc"));
assertEquals("Testing isWord on empty: empty string", false, emptyDict.isWord(""));
assertEquals("Testing isWord on small: empty string", false, smallDict.isWord(""));
assertEquals("Testing isWord on large: empty string", false, largeDict.isWord(""));
assertEquals("Testing isWord on small: no", false, smallDict.isWord("no"));
assertEquals("Testing isWord on large: no", true, largeDict.isWord("no"));
assertEquals("Testing isWord on small: subsequent", true, smallDict.isWord("subsequent"));
assertEquals("Testing isWord on large: subsequent", true, largeDict.isWord("subsequent"));
}
}