forked from mitchfry/SpellChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDLListTester.java
More file actions
390 lines (342 loc) · 13.6 KB
/
DLListTester.java
File metadata and controls
390 lines (342 loc) · 13.6 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import static org.junit.Assert.*;
import java.util.Iterator;
import org.junit.Test;
/**
* JUnit tests for some of the List interface methods in Lab#2
*
* @author Mitch Fry
* @version 1.0 October 2013
*
*/
public class DLListTester {
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#size()}.
*/
@Test
public void testSize() {
TestList<Integer> testList = new TestList<Integer>( );
assertEquals("Size must be 0 after constructor", 0, testList.size());
testList.clear( );
assertEquals("Size must be 0 after clear", 0, testList.size());
testList.add( 10);
assertEquals("Size must be 1 after 1 add", 1, testList.size());
testList.add( 20);
assertEquals("Size must be 2 after 2 adds", 2, testList.size());
testList.add( 30);
assertEquals("Size must be 3 after 3 adds", 3, testList.size());
testList.add( 40);
assertEquals("Size must be 4 after 4 adds", 4, testList.size());
testList.add( 15);
assertEquals("Size must be 5 after 5 adds", 5, testList.size());
testList.add( 25);
assertEquals("Size must be 6 after 6 adds", 6, testList.size());
testList.add( 35);
assertEquals("Size must be 7 after 7 adds", 7, testList.size());
testList.add( 45);
assertEquals("Size must be 8 after the 8 adds", 8, testList.size());
testList.remove(0);
assertEquals("Size must be 7 after the 1st remove", 7, testList.size());
testList.remove(3);
assertEquals("Size must be 6 after the 2nd remove", 6, testList.size());
testList.clear( );
assertEquals("Size must be 0 after clear", 0, testList.size());
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#isEmpty()}.
*/
@Test
public void testIsEmpty() {
TestList<Integer> testList = new TestList<Integer>( );
assertTrue("IsEmpty must be true after the constructor", testList.isEmpty());
testList.clear( );
assertTrue("IsEmpty must be true after the clear", testList.isEmpty());
testList.add( 10);
testList.add( 20);
assertFalse("IsEmpty must be false after the adds", testList.isEmpty());
testList.add( 30);
testList.add( 40);
testList.add( 15);
assertFalse("IsEmpty must be false after the adds", testList.isEmpty());
testList.add( 25);
testList.add( 35);
testList.add( 45);
assertFalse("IsEmpty must be false after the adds", testList.isEmpty());
testList.clear( );
assertTrue("IsEmpty must be true after the clear", testList.isEmpty());
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#contains(java.lang.Object)}.
*/
@Test
public void testContains() {
TestList<Integer> testList = new TestList<Integer>( );
testList.clear( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
testList.add( 15);
testList.add( 25);
testList.add( 35);
testList.add( 45);
assertFalse("contains must return false for the element 80", testList.contains(80));
assertFalse("contains must return false for the element 5", testList.contains(5));
assertTrue("contains must return true for the element 30", testList.contains(30));
assertTrue("contains must return true for the element 45", testList.contains(45));
assertTrue("contains must return true for the element 10", testList.contains(10));
testList.clear( );
assertFalse("contains must return false for any element after a clear", testList.contains(45));
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#iterator()}.
*/
@Test
public void testIterator() {
int sum = 0;
TestList<Integer> testList = new TestList<Integer>( );
testList.clear( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
Iterator<Integer> it = testList.iterator( );
while (it.hasNext( )) {
sum = sum + it.next( );
}
assertEquals("The sum from the iteration must be 100", 100, sum);
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#add(java.lang.Object)}.
*/
@Test
public void testAddT() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 10);
assertEquals("Tail of list must be 10 after the add", 10, (testList.get( testList.size( ) -1 )).intValue());
testList.add( 20);
assertEquals("Tail of list must be 20 after the add", 20, (testList.get( testList.size( ) - 1 )).intValue());
testList.add( 30);
assertEquals("Tail of list must be 30 after the add", 30, (testList.get( testList.size( ) - 1 )).intValue());
testList.add( 40);
assertEquals("Tail of list must be 40 after the add", 40, (testList.get( testList.size( ) - 1 )).intValue());
testList.add( 15);
assertEquals("Tail of list must be 15 after the add", 15, (testList.get( testList.size( ) - 1 )).intValue());
testList.add( 25);
assertEquals("Tail of list must be 25 after the add", 25, (testList.get( testList.size( ) - 1 )).intValue());
testList.add( 35);
assertEquals("Tail of list must be 35 after the add", 35, (testList.get( testList.size( ) - 1 )).intValue());
testList.add( 45);
assertEquals("Tail of list must be 45 after the add", 45, (testList.get( testList.size( ) - 1 )).intValue());
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#get(int)}.
*/
@Test
public void testGetInt() {
TestList<Integer> testList = new TestList<Integer>( );
testList.clear( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
testList.add( 15);
testList.add( 25);
testList.add( 35);
testList.add( 45);
assertEquals("Head of list must be 10 after the adds", 10, (testList.get( 0).intValue()));
assertEquals("Tail of list must be 45 after the adds", 45, (testList.get( 7).intValue()));
assertEquals("4th item of list must be 40 after the adds", 40, (testList.get( 3).intValue()));
assertEquals("6th item of list must be 25 after the adds", 25, (testList.get( 5).intValue()));
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#get(int)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testGetIntExeption1() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
//Here is the real test for throwing exception
testList.get( 4);
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#get(int)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testGetIntExeption2() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
//Here is the real test for throwing exception
testList.get( -1);
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#remove(java.lang.Object)}.
*/
@Test
public void testRemoveObject() {
TestList<Integer> testList = new TestList<Integer>( );
testList.clear( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
testList.add( 15);
testList.add( 25);
testList.add( 35);
testList.add( 45);
assertFalse("Remove must return false for 99", testList.remove(new Integer(99)));
assertEquals("size must be 8 after failed remove", 8, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(45)));
assertFalse("contains must return false for 45 after remove", testList.contains(45));
assertEquals("size must be 7 after remove", 7, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(10)));
assertFalse("contains must return false for 10 after remove", testList.contains(10));
assertEquals("size must be 6 after remove", 6, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(40)));
assertFalse("contains must return false for 40 after remove", testList.contains(40));
assertEquals("size must be 5 after remove", 5, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(20)));
assertFalse("contains must return false for 20 after remove", testList.contains(20));
assertEquals("size must be 4 after remove", 4, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(30)));
assertFalse("contains must return false for 30 after remove", testList.contains(30));
assertEquals("size must be 3 after remove", 3, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(15)));
assertFalse("contains must return false for 15 after remove", testList.contains(15));
assertEquals("size must be 2 after remove", 2, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(25)));
assertFalse("contains must return false for 25 after remove", testList.contains(25));
assertEquals("size must be 1 after remove", 1, testList.size());
assertTrue("Remove must return true", testList.remove(new Integer(35)));
assertFalse("contains must return false for 35 after remove", testList.contains(35));
assertEquals("size must be 0 after remove", 0, testList.size());
assertFalse("Remove must return false on empty list", testList.remove(new Integer(40)));
assertEquals("size must be 0 after failed remove", 0, testList.size());
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#clear()}.
*/
@Test
public void testClear() {
TestList<Integer> testList = new TestList<Integer>( );
testList.clear( );
testList.add( 10);
testList.add( 20);
testList.clear( );
assertEquals("Size must be 0 after clear", 0, testList.size( ));
assertTrue("IsEmpty must be true after the adds & clear", testList.isEmpty());
testList.add( 30);
testList.add( 40);
testList.add( 15);
testList.clear( );
assertEquals("Size must be 0 after clear", 0, testList.size( ));
assertTrue("IsEmpty must be true after the adds & clear", testList.isEmpty());
testList.add( 25);
testList.add( 35);
testList.add( 45);
testList.clear( );
assertEquals("Size must be 0 after clear", 0, testList.size( ));
assertTrue("IsEmpty must be true after the adds & clear", testList.isEmpty());
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#add(int, java.lang.Object)}.
*/
@Test
public void testAddIntT() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 0, 10);
assertEquals("Tail of list must be 10 after the add", 10, (testList.get( 0)).intValue());
assertEquals("Size should be 1", 1, testList.size( ));
testList.add( 0, 20);
assertEquals("Head of list must be 20 after the add", 20, (testList.get( 0).intValue()));
assertEquals("Size should be 2", 2, testList.size( ));
testList.add( 2, 30);
assertEquals("Tail of list must be 30 after the add", 30, (testList.get( 2).intValue()));
assertEquals("Size should be 3", 3, testList.size( ));
testList.add( 1, 40);
assertEquals("2nd element of list must be 40 after the add", 40, (testList.get( 1).intValue()));
assertEquals("Size should be 4", 4, testList.size( ));
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#add(int, java.lang.Object)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testAddIntTExeption1() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
//Here is the real test for throwing exception
testList.add( 5, 15);
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#add(int, java.lang.Object)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testAddIntTExeption2() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
//Here is the real test for throwing exception
testList.add( -1, 15);
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#remove(int)}.
*/
@Test
public void testRemoveInt() {
TestList<Integer> testList = new TestList<Integer>( );
testList.clear( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
testList.add( 15);
testList.add( 25);
testList.add( 35);
testList.add( 45);
assertTrue("contains must return true before the removal of 10", testList.contains( 10));
assertEquals("remove must return 10 on removal of item at index 0", new Integer( 10), testList.remove(0));
assertFalse("contains must return false after the removal of 10", testList.contains( 10));
assertTrue("contains must return true before the removal of 40", testList.contains( 40));
assertEquals("remove must return 40 on removal of item at index 2", new Integer( 40), testList.remove(2));
assertFalse("contains must return false after the removal of 40", testList.contains( 40));
assertTrue("contains must return true before the removal of 45", testList.contains( 45));
assertEquals("remove must return 45 on removal of item at index 5", new Integer( 45), testList.remove( 5));
assertFalse("contains must return false after the removal of 45", testList.contains( 45));
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#remove(int)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testRemoveIntTExeption1() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
//Here is the real test for throwing exception
testList.remove( 4);
}
/**
* Test method for {@link edu.ccc.cs260.SpellChecker.TestList#remove(int)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public void testRemoveIntTExeption2() {
TestList<Integer> testList = new TestList<Integer>( );
testList.add( 10);
testList.add( 20);
testList.add( 30);
testList.add( 40);
//Here is the real test for throwing exception
testList.remove( -1);
}
}