9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
|
|
12 |
< |
public class LinkedListTest extends TestCase { |
13 |
< |
|
14 |
< |
private static final int N = 10; |
15 |
< |
private static final long SHORT_DELAY_MS = 100; |
16 |
< |
private static final long MEDIUM_DELAY_MS = 1000; |
17 |
< |
private static final long LONG_DELAY_MS = 10000; |
18 |
< |
|
12 |
> |
public class LinkedListTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
|
junit.textui.TestRunner.run (suite()); |
15 |
|
} |
22 |
|
* Create a queue of given size containing consecutive |
23 |
|
* Integers 0 ... n. |
24 |
|
*/ |
25 |
< |
private LinkedList fullQueue(int n) { |
25 |
> |
private LinkedList populatedQueue(int n) { |
26 |
|
LinkedList q = new LinkedList(); |
27 |
|
assertTrue(q.isEmpty()); |
28 |
|
for(int i = 0; i < n; ++i) |
32 |
|
return q; |
33 |
|
} |
34 |
|
|
35 |
< |
public void testConstructor1(){ |
35 |
> |
/** |
36 |
> |
* new queue is empty |
37 |
> |
*/ |
38 |
> |
public void testConstructor1() { |
39 |
|
assertEquals(0, new LinkedList().size()); |
40 |
|
} |
41 |
|
|
42 |
+ |
/** |
43 |
+ |
* Initializing from null Collection throws NPE |
44 |
+ |
*/ |
45 |
|
public void testConstructor3() { |
46 |
|
try { |
47 |
|
LinkedList q = new LinkedList((Collection)null); |
48 |
< |
fail("Cannot make from null collection"); |
48 |
> |
shouldThrow(); |
49 |
|
} |
50 |
|
catch (NullPointerException success) {} |
51 |
|
} |
52 |
|
|
53 |
< |
public void testConstructor6(){ |
53 |
> |
/** |
54 |
> |
* Queue contains all elements of collection used to initialize |
55 |
> |
|
56 |
> |
*/ |
57 |
> |
public void testConstructor6() { |
58 |
|
try { |
59 |
< |
Integer[] ints = new Integer[N]; |
60 |
< |
for (int i = 0; i < N; ++i) |
59 |
> |
Integer[] ints = new Integer[SIZE]; |
60 |
> |
for (int i = 0; i < SIZE; ++i) |
61 |
|
ints[i] = new Integer(i); |
62 |
|
LinkedList q = new LinkedList(Arrays.asList(ints)); |
63 |
< |
for (int i = 0; i < N; ++i) |
63 |
> |
for (int i = 0; i < SIZE; ++i) |
64 |
|
assertEquals(ints[i], q.poll()); |
65 |
|
} |
66 |
|
finally {} |
67 |
|
} |
68 |
|
|
69 |
+ |
/** |
70 |
+ |
* isEmpty is true before add, false after |
71 |
+ |
*/ |
72 |
|
public void testEmpty() { |
73 |
|
LinkedList q = new LinkedList(); |
74 |
|
assertTrue(q.isEmpty()); |
80 |
|
assertTrue(q.isEmpty()); |
81 |
|
} |
82 |
|
|
83 |
+ |
/** |
84 |
+ |
* size changes when elements added and removed |
85 |
+ |
*/ |
86 |
|
public void testSize() { |
87 |
< |
LinkedList q = fullQueue(N); |
88 |
< |
for (int i = 0; i < N; ++i) { |
89 |
< |
assertEquals(N-i, q.size()); |
87 |
> |
LinkedList q = populatedQueue(SIZE); |
88 |
> |
for (int i = 0; i < SIZE; ++i) { |
89 |
> |
assertEquals(SIZE-i, q.size()); |
90 |
|
q.remove(); |
91 |
|
} |
92 |
< |
for (int i = 0; i < N; ++i) { |
92 |
> |
for (int i = 0; i < SIZE; ++i) { |
93 |
|
assertEquals(i, q.size()); |
94 |
|
q.add(new Integer(i)); |
95 |
|
} |
96 |
|
} |
97 |
|
|
98 |
< |
public void testOfferNull(){ |
98 |
> |
/** |
99 |
> |
* offer(null) succeeds |
100 |
> |
*/ |
101 |
> |
public void testOfferNull() { |
102 |
|
try { |
103 |
|
LinkedList q = new LinkedList(); |
104 |
|
q.offer(null); |
105 |
|
} catch (NullPointerException ie) { |
106 |
< |
fail("should not throw NPE"); |
106 |
> |
unexpectedException(); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
+ |
/** |
111 |
+ |
* Offer succeeds |
112 |
+ |
*/ |
113 |
|
public void testOffer() { |
114 |
|
LinkedList q = new LinkedList(); |
115 |
|
assertTrue(q.offer(new Integer(0))); |
116 |
|
assertTrue(q.offer(new Integer(1))); |
117 |
|
} |
118 |
|
|
119 |
< |
public void testAdd(){ |
119 |
> |
/** |
120 |
> |
* add succeeds |
121 |
> |
*/ |
122 |
> |
public void testAdd() { |
123 |
|
LinkedList q = new LinkedList(); |
124 |
< |
for (int i = 0; i < N; ++i) { |
124 |
> |
for (int i = 0; i < SIZE; ++i) { |
125 |
|
assertEquals(i, q.size()); |
126 |
|
assertTrue(q.add(new Integer(i))); |
127 |
|
} |
128 |
|
} |
129 |
|
|
130 |
< |
public void testAddAll1(){ |
130 |
> |
/** |
131 |
> |
* addAll(null) throws NPE |
132 |
> |
*/ |
133 |
> |
public void testAddAll1() { |
134 |
|
try { |
135 |
|
LinkedList q = new LinkedList(); |
136 |
|
q.addAll(null); |
137 |
< |
fail("Cannot add null collection"); |
137 |
> |
shouldThrow(); |
138 |
|
} |
139 |
|
catch (NullPointerException success) {} |
140 |
|
} |
141 |
|
|
142 |
< |
public void testAddAll5(){ |
142 |
> |
/** |
143 |
> |
* Queue contains all elements, in traversal order, of successful addAll |
144 |
> |
*/ |
145 |
> |
public void testAddAll5() { |
146 |
|
try { |
147 |
|
Integer[] empty = new Integer[0]; |
148 |
< |
Integer[] ints = new Integer[N]; |
149 |
< |
for (int i = 0; i < N; ++i) |
148 |
> |
Integer[] ints = new Integer[SIZE]; |
149 |
> |
for (int i = 0; i < SIZE; ++i) |
150 |
|
ints[i] = new Integer(i); |
151 |
|
LinkedList q = new LinkedList(); |
152 |
|
assertFalse(q.addAll(Arrays.asList(empty))); |
153 |
|
assertTrue(q.addAll(Arrays.asList(ints))); |
154 |
< |
for (int i = 0; i < N; ++i) |
154 |
> |
for (int i = 0; i < SIZE; ++i) |
155 |
|
assertEquals(ints[i], q.poll()); |
156 |
|
} |
157 |
|
finally {} |
158 |
|
} |
159 |
|
|
160 |
< |
public void testPoll(){ |
161 |
< |
LinkedList q = fullQueue(N); |
162 |
< |
for (int i = 0; i < N; ++i) { |
160 |
> |
/** |
161 |
> |
* addAll with too large an index throws IOOBE |
162 |
> |
*/ |
163 |
> |
public void testAddAll2_IndexOutOfBoundsException() { |
164 |
> |
try { |
165 |
> |
LinkedList l = new LinkedList(); |
166 |
> |
l.add(new Object()); |
167 |
> |
LinkedList m = new LinkedList(); |
168 |
> |
m.add(new Object()); |
169 |
> |
l.addAll(4,m); |
170 |
> |
shouldThrow(); |
171 |
> |
} catch(IndexOutOfBoundsException success) {} |
172 |
> |
} |
173 |
> |
|
174 |
> |
/** |
175 |
> |
* addAll with negative index throws IOOBE |
176 |
> |
*/ |
177 |
> |
public void testAddAll4_BadIndex() { |
178 |
> |
try { |
179 |
> |
LinkedList l = new LinkedList(); |
180 |
> |
l.add(new Object()); |
181 |
> |
LinkedList m = new LinkedList(); |
182 |
> |
m.add(new Object()); |
183 |
> |
l.addAll(-1,m); |
184 |
> |
shouldThrow(); |
185 |
> |
} catch(IndexOutOfBoundsException success){} |
186 |
> |
} |
187 |
> |
|
188 |
> |
/** |
189 |
> |
* poll succeeds unless empty |
190 |
> |
*/ |
191 |
> |
public void testPoll() { |
192 |
> |
LinkedList q = populatedQueue(SIZE); |
193 |
> |
for (int i = 0; i < SIZE; ++i) { |
194 |
|
assertEquals(i, ((Integer)q.poll()).intValue()); |
195 |
|
} |
196 |
|
assertNull(q.poll()); |
197 |
|
} |
198 |
|
|
199 |
< |
public void testPeek(){ |
200 |
< |
LinkedList q = fullQueue(N); |
201 |
< |
for (int i = 0; i < N; ++i) { |
199 |
> |
/** |
200 |
> |
* peek returns next element, or null if empty |
201 |
> |
*/ |
202 |
> |
public void testPeek() { |
203 |
> |
LinkedList q = populatedQueue(SIZE); |
204 |
> |
for (int i = 0; i < SIZE; ++i) { |
205 |
|
assertEquals(i, ((Integer)q.peek()).intValue()); |
206 |
|
q.poll(); |
207 |
|
assertTrue(q.peek() == null || |
210 |
|
assertNull(q.peek()); |
211 |
|
} |
212 |
|
|
213 |
< |
public void testElement(){ |
214 |
< |
LinkedList q = fullQueue(N); |
215 |
< |
for (int i = 0; i < N; ++i) { |
213 |
> |
/** |
214 |
> |
* element returns next element, or throws NSEE if empty |
215 |
> |
*/ |
216 |
> |
public void testElement() { |
217 |
> |
LinkedList q = populatedQueue(SIZE); |
218 |
> |
for (int i = 0; i < SIZE; ++i) { |
219 |
|
assertEquals(i, ((Integer)q.element()).intValue()); |
220 |
|
q.poll(); |
221 |
|
} |
222 |
|
try { |
223 |
|
q.element(); |
224 |
< |
fail("no such element"); |
224 |
> |
shouldThrow(); |
225 |
|
} |
226 |
|
catch (NoSuchElementException success) {} |
227 |
|
} |
228 |
|
|
229 |
< |
public void testRemove(){ |
230 |
< |
LinkedList q = fullQueue(N); |
231 |
< |
for (int i = 0; i < N; ++i) { |
229 |
> |
/** |
230 |
> |
* remove removes next element, or throws NSEE if empty |
231 |
> |
*/ |
232 |
> |
public void testRemove() { |
233 |
> |
LinkedList q = populatedQueue(SIZE); |
234 |
> |
for (int i = 0; i < SIZE; ++i) { |
235 |
|
assertEquals(i, ((Integer)q.remove()).intValue()); |
236 |
|
} |
237 |
|
try { |
238 |
|
q.remove(); |
239 |
< |
fail("remove should throw"); |
239 |
> |
shouldThrow(); |
240 |
|
} catch (NoSuchElementException success){ |
241 |
|
} |
242 |
|
} |
243 |
|
|
244 |
< |
public void testRemoveElement(){ |
245 |
< |
LinkedList q = fullQueue(N); |
246 |
< |
for (int i = 1; i < N; i+=2) { |
244 |
> |
/** |
245 |
> |
* remove(x) removes x and returns true if present |
246 |
> |
*/ |
247 |
> |
public void testRemoveElement() { |
248 |
> |
LinkedList q = populatedQueue(SIZE); |
249 |
> |
for (int i = 1; i < SIZE; i+=2) { |
250 |
|
assertTrue(q.remove(new Integer(i))); |
251 |
|
} |
252 |
< |
for (int i = 0; i < N; i+=2) { |
252 |
> |
for (int i = 0; i < SIZE; i+=2) { |
253 |
|
assertTrue(q.remove(new Integer(i))); |
254 |
|
assertFalse(q.remove(new Integer(i+1))); |
255 |
|
} |
256 |
< |
assert(q.isEmpty()); |
256 |
> |
assertTrue(q.isEmpty()); |
257 |
|
} |
258 |
|
|
259 |
< |
public void testContains(){ |
260 |
< |
LinkedList q = fullQueue(N); |
261 |
< |
for (int i = 0; i < N; ++i) { |
259 |
> |
/** |
260 |
> |
* contains(x) reports true when elements added but not yet removed |
261 |
> |
*/ |
262 |
> |
public void testContains() { |
263 |
> |
LinkedList q = populatedQueue(SIZE); |
264 |
> |
for (int i = 0; i < SIZE; ++i) { |
265 |
|
assertTrue(q.contains(new Integer(i))); |
266 |
|
q.poll(); |
267 |
|
assertFalse(q.contains(new Integer(i))); |
268 |
|
} |
269 |
|
} |
270 |
|
|
271 |
< |
public void testClear(){ |
272 |
< |
LinkedList q = fullQueue(N); |
271 |
> |
/** |
272 |
> |
* clear removes all elements |
273 |
> |
*/ |
274 |
> |
public void testClear() { |
275 |
> |
LinkedList q = populatedQueue(SIZE); |
276 |
|
q.clear(); |
277 |
|
assertTrue(q.isEmpty()); |
278 |
|
assertEquals(0, q.size()); |
282 |
|
assertTrue(q.isEmpty()); |
283 |
|
} |
284 |
|
|
285 |
< |
public void testContainsAll(){ |
286 |
< |
LinkedList q = fullQueue(N); |
285 |
> |
/** |
286 |
> |
* containsAll(c) is true when c contains a subset of elements |
287 |
> |
*/ |
288 |
> |
public void testContainsAll() { |
289 |
> |
LinkedList q = populatedQueue(SIZE); |
290 |
|
LinkedList p = new LinkedList(); |
291 |
< |
for (int i = 0; i < N; ++i) { |
291 |
> |
for (int i = 0; i < SIZE; ++i) { |
292 |
|
assertTrue(q.containsAll(p)); |
293 |
|
assertFalse(p.containsAll(q)); |
294 |
|
p.add(new Integer(i)); |
296 |
|
assertTrue(p.containsAll(q)); |
297 |
|
} |
298 |
|
|
299 |
< |
public void testRetainAll(){ |
300 |
< |
LinkedList q = fullQueue(N); |
301 |
< |
LinkedList p = fullQueue(N); |
302 |
< |
for (int i = 0; i < N; ++i) { |
299 |
> |
/** |
300 |
> |
* retainAll(c) retains only those elements of c and reports true if changed |
301 |
> |
*/ |
302 |
> |
public void testRetainAll() { |
303 |
> |
LinkedList q = populatedQueue(SIZE); |
304 |
> |
LinkedList p = populatedQueue(SIZE); |
305 |
> |
for (int i = 0; i < SIZE; ++i) { |
306 |
|
boolean changed = q.retainAll(p); |
307 |
|
if (i == 0) |
308 |
|
assertFalse(changed); |
310 |
|
assertTrue(changed); |
311 |
|
|
312 |
|
assertTrue(q.containsAll(p)); |
313 |
< |
assertEquals(N-i, q.size()); |
313 |
> |
assertEquals(SIZE-i, q.size()); |
314 |
|
p.remove(); |
315 |
|
} |
316 |
|
} |
317 |
|
|
318 |
< |
public void testRemoveAll(){ |
319 |
< |
for (int i = 1; i < N; ++i) { |
320 |
< |
LinkedList q = fullQueue(N); |
321 |
< |
LinkedList p = fullQueue(i); |
318 |
> |
/** |
319 |
> |
* removeAll(c) removes only those elements of c and reports true if changed |
320 |
> |
*/ |
321 |
> |
public void testRemoveAll() { |
322 |
> |
for (int i = 1; i < SIZE; ++i) { |
323 |
> |
LinkedList q = populatedQueue(SIZE); |
324 |
> |
LinkedList p = populatedQueue(i); |
325 |
|
assertTrue(q.removeAll(p)); |
326 |
< |
assertEquals(N-i, q.size()); |
326 |
> |
assertEquals(SIZE-i, q.size()); |
327 |
|
for (int j = 0; j < i; ++j) { |
328 |
|
Integer I = (Integer)(p.remove()); |
329 |
|
assertFalse(q.contains(I)); |
331 |
|
} |
332 |
|
} |
333 |
|
|
334 |
< |
public void testToArray(){ |
335 |
< |
LinkedList q = fullQueue(N); |
334 |
> |
/** |
335 |
> |
* toArray contains all elements |
336 |
> |
*/ |
337 |
> |
public void testToArray() { |
338 |
> |
LinkedList q = populatedQueue(SIZE); |
339 |
|
Object[] o = q.toArray(); |
340 |
|
Arrays.sort(o); |
341 |
|
for(int i = 0; i < o.length; i++) |
342 |
|
assertEquals(o[i], q.poll()); |
343 |
|
} |
344 |
|
|
345 |
< |
public void testToArray2(){ |
346 |
< |
LinkedList q = fullQueue(N); |
347 |
< |
Integer[] ints = new Integer[N]; |
345 |
> |
/** |
346 |
> |
* toArray(a) contains all elements |
347 |
> |
*/ |
348 |
> |
public void testToArray2() { |
349 |
> |
LinkedList q = populatedQueue(SIZE); |
350 |
> |
Integer[] ints = new Integer[SIZE]; |
351 |
|
ints = (Integer[])q.toArray(ints); |
352 |
|
Arrays.sort(ints); |
353 |
|
for(int i = 0; i < ints.length; i++) |
354 |
|
assertEquals(ints[i], q.poll()); |
355 |
|
} |
356 |
+ |
|
357 |
+ |
/** |
358 |
+ |
* toArray(null) throws NPE |
359 |
+ |
*/ |
360 |
+ |
public void testToArray_BadArg() { |
361 |
+ |
try { |
362 |
+ |
LinkedList l = new LinkedList(); |
363 |
+ |
l.add(new Object()); |
364 |
+ |
Object o[] = l.toArray(null); |
365 |
+ |
shouldThrow(); |
366 |
+ |
} catch(NullPointerException success){} |
367 |
+ |
} |
368 |
+ |
|
369 |
+ |
/** |
370 |
+ |
* toArray with incompatable aray type throws CCE |
371 |
+ |
*/ |
372 |
+ |
public void testToArray1_BadArg() { |
373 |
+ |
try { |
374 |
+ |
LinkedList l = new LinkedList(); |
375 |
+ |
l.add(new Integer(5)); |
376 |
+ |
Object o[] = l.toArray(new String[10] ); |
377 |
+ |
shouldThrow(); |
378 |
+ |
} catch(ArrayStoreException success){} |
379 |
+ |
} |
380 |
|
|
381 |
< |
public void testIterator(){ |
382 |
< |
LinkedList q = fullQueue(N); |
381 |
> |
/** |
382 |
> |
* iterator iterates through all elements |
383 |
> |
*/ |
384 |
> |
public void testIterator() { |
385 |
> |
LinkedList q = populatedQueue(SIZE); |
386 |
|
int i = 0; |
387 |
|
Iterator it = q.iterator(); |
388 |
|
while(it.hasNext()) { |
389 |
|
assertTrue(q.contains(it.next())); |
390 |
|
++i; |
391 |
|
} |
392 |
< |
assertEquals(i, N); |
392 |
> |
assertEquals(i, SIZE); |
393 |
|
} |
394 |
|
|
395 |
+ |
/** |
396 |
+ |
* iterator ordering is FIFO |
397 |
+ |
*/ |
398 |
|
public void testIteratorOrdering() { |
280 |
– |
|
399 |
|
final LinkedList q = new LinkedList(); |
282 |
– |
|
400 |
|
q.add(new Integer(1)); |
401 |
|
q.add(new Integer(2)); |
402 |
|
q.add(new Integer(3)); |
286 |
– |
|
403 |
|
int k = 0; |
404 |
|
for (Iterator it = q.iterator(); it.hasNext();) { |
405 |
|
int i = ((Integer)(it.next())).intValue(); |
406 |
< |
assertEquals("items should come out in order", ++k, i); |
406 |
> |
assertEquals(++k, i); |
407 |
|
} |
408 |
|
|
409 |
< |
assertEquals("should go through 3 elements", 3, k); |
409 |
> |
assertEquals(3, k); |
410 |
|
} |
411 |
|
|
412 |
+ |
/** |
413 |
+ |
* iterator.remove removes current element |
414 |
+ |
*/ |
415 |
|
public void testIteratorRemove () { |
416 |
|
final LinkedList q = new LinkedList(); |
298 |
– |
|
417 |
|
q.add(new Integer(1)); |
418 |
|
q.add(new Integer(2)); |
419 |
|
q.add(new Integer(3)); |
302 |
– |
|
420 |
|
Iterator it = q.iterator(); |
421 |
|
it.next(); |
422 |
|
it.remove(); |
306 |
– |
|
423 |
|
it = q.iterator(); |
424 |
|
assertEquals(it.next(), new Integer(2)); |
425 |
|
assertEquals(it.next(), new Integer(3)); |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
< |
public void testToString(){ |
431 |
< |
LinkedList q = fullQueue(N); |
430 |
> |
/** |
431 |
> |
* toString contains toStrings of elements |
432 |
> |
*/ |
433 |
> |
public void testToString() { |
434 |
> |
LinkedList q = populatedQueue(SIZE); |
435 |
|
String s = q.toString(); |
436 |
< |
for (int i = 0; i < N; ++i) { |
436 |
> |
for (int i = 0; i < SIZE; ++i) { |
437 |
|
assertTrue(s.indexOf(String.valueOf(i)) >= 0); |
438 |
|
} |
439 |
|
} |
440 |
|
|
441 |
< |
public void testAddFirst(){ |
442 |
< |
LinkedList q = fullQueue(3); |
443 |
< |
q.addFirst(new Integer(4)); |
444 |
< |
assertEquals(new Integer(4),q.get(0)); |
445 |
< |
} |
446 |
< |
|
447 |
< |
public void testAddLast(){ |
329 |
< |
LinkedList q = fullQueue(3); |
330 |
< |
q.addLast(new Integer(3)); |
331 |
< |
assertEquals(new Integer(3),q.get(3)); |
332 |
< |
} |
333 |
< |
|
334 |
< |
public void testGetFirst() { |
335 |
< |
LinkedList q = fullQueue(3); |
336 |
< |
assertEquals(new Integer(0),q.getFirst()); |
441 |
> |
/** |
442 |
> |
* peek returns element inserted with addFirst |
443 |
> |
*/ |
444 |
> |
public void testAddFirst() { |
445 |
> |
LinkedList q = populatedQueue(3); |
446 |
> |
q.addFirst(four); |
447 |
> |
assertEquals(four,q.peek()); |
448 |
|
} |
338 |
– |
|
339 |
– |
public void testGetLast() { |
340 |
– |
LinkedList q = fullQueue(3); |
341 |
– |
assertEquals(new Integer(2),q.getLast()); |
342 |
– |
} |
343 |
– |
|
344 |
– |
public void testIndexOf(){ |
345 |
– |
LinkedList q = fullQueue(3); |
346 |
– |
assertEquals(0,q.indexOf(new Integer(0))); |
347 |
– |
assertEquals(1,q.indexOf(new Integer(1))); |
348 |
– |
assertEquals(2,q.indexOf(new Integer(2))); |
349 |
– |
assertEquals(-1, q.indexOf("not there")); |
350 |
– |
} |
351 |
– |
|
352 |
– |
public void testLastIndexOf(){ |
353 |
– |
LinkedList q = fullQueue(3); |
354 |
– |
q.add(new Integer(2)); |
355 |
– |
assertEquals(3,q.lastIndexOf(new Integer(2))); |
356 |
– |
assertEquals(-1, q.lastIndexOf("not there")); |
357 |
– |
} |
358 |
– |
|
359 |
– |
public void testSet(){ |
360 |
– |
LinkedList q = fullQueue(3); |
361 |
– |
q.set(0,(new Integer(1))); |
362 |
– |
assertFalse(q.contains(new Integer(0))); |
363 |
– |
assertEquals(new Integer(1), q.get(0)); |
364 |
– |
} |
365 |
– |
|
366 |
– |
|
367 |
– |
public void testGetFirst_NoSuchElementException(){ |
368 |
– |
try { |
369 |
– |
LinkedList l = new LinkedList(); |
370 |
– |
l.getFirst(); |
371 |
– |
fail("First Element"); |
372 |
– |
} |
373 |
– |
catch(NoSuchElementException success) {} |
374 |
– |
} |
375 |
– |
|
376 |
– |
public void testRemoveFirst() { |
377 |
– |
try { |
378 |
– |
LinkedList l = new LinkedList(); |
379 |
– |
l.removeFirst(); |
380 |
– |
fail("R: First Element"); |
381 |
– |
} |
382 |
– |
catch(NoSuchElementException success) {} |
383 |
– |
} |
384 |
– |
|
385 |
– |
public void testRemoveLast() { |
386 |
– |
try { |
387 |
– |
LinkedList l = new LinkedList(); |
388 |
– |
l.removeLast(); |
389 |
– |
fail("R: Last Element"); |
390 |
– |
} |
391 |
– |
catch(NoSuchElementException success) {} |
392 |
– |
} |
393 |
– |
|
394 |
– |
public void testGetLast_NoSuchElementException(){ |
395 |
– |
try { |
396 |
– |
LinkedList l = new LinkedList(); |
397 |
– |
l.getLast(); |
398 |
– |
fail("Last Element"); |
399 |
– |
} |
400 |
– |
catch(NoSuchElementException success) {} |
401 |
– |
} |
402 |
– |
|
403 |
– |
|
404 |
– |
public void testAddAll_NullPointerException(){ |
405 |
– |
try { |
406 |
– |
LinkedList l = new LinkedList(); |
407 |
– |
l.addAll((Collection)null); |
408 |
– |
fail("Add All Failed"); |
409 |
– |
} |
410 |
– |
catch(NullPointerException success){} |
411 |
– |
} |
412 |
– |
|
413 |
– |
|
414 |
– |
public void testAddAll1_OutOfBounds() { |
415 |
– |
try { |
416 |
– |
LinkedList l = new LinkedList(); |
417 |
– |
l.addAll(4,new LinkedList()); |
418 |
– |
fail("boolean addAll(int, Collection) should throw IndexOutOfBoundsException"); |
419 |
– |
} |
420 |
– |
catch(IndexOutOfBoundsException success) {} |
421 |
– |
} |
422 |
– |
|
423 |
– |
|
424 |
– |
public void testAddAll2_IndexOutOfBoundsException() { |
425 |
– |
try { |
426 |
– |
LinkedList l = new LinkedList(); |
427 |
– |
l.add(new Object()); |
428 |
– |
LinkedList m = new LinkedList(); |
429 |
– |
m.add(new Object()); |
430 |
– |
l.addAll(4,m); |
431 |
– |
fail("Add All Failed " + l.size()); |
432 |
– |
}catch(IndexOutOfBoundsException success) {} |
433 |
– |
} |
434 |
– |
|
435 |
– |
public void testAddAll4_BadIndex() { |
436 |
– |
try { |
437 |
– |
LinkedList l = new LinkedList(); |
438 |
– |
l.add(new Object()); |
439 |
– |
LinkedList m = new LinkedList(); |
440 |
– |
m.add(new Object()); |
441 |
– |
l.addAll(-1,m); |
442 |
– |
fail("Add All Failed " + l.size()); |
443 |
– |
}catch(IndexOutOfBoundsException success){} |
444 |
– |
} |
445 |
– |
|
446 |
– |
public void testget1() { |
447 |
– |
try { |
448 |
– |
LinkedList l = new LinkedList(); |
449 |
– |
l.add(new Object()); |
450 |
– |
l.get(-1); |
451 |
– |
fail("get Failed - l.get(-1)"); |
452 |
– |
}catch(IndexOutOfBoundsException success) {} |
453 |
– |
} |
454 |
– |
|
455 |
– |
public void testget2() { |
456 |
– |
try { |
457 |
– |
LinkedList l = new LinkedList(); |
458 |
– |
l.add(new Object()); |
459 |
– |
l.get(5); |
460 |
– |
fail("get Failed - l.get(5) l.size(): " + l.size()); |
461 |
– |
}catch(IndexOutOfBoundsException success){} |
462 |
– |
} |
463 |
– |
|
464 |
– |
public void testset1() { |
465 |
– |
try { |
466 |
– |
LinkedList l = new LinkedList(); |
467 |
– |
l.add(new Object()); |
468 |
– |
l.set(-1,new Object()); |
469 |
– |
fail("set failed - l.set(-1,...)" + l.size()); |
470 |
– |
}catch(IndexOutOfBoundsException success){} |
471 |
– |
} |
472 |
– |
|
473 |
– |
public void testset2() { |
474 |
– |
try { |
475 |
– |
LinkedList l = new LinkedList(); |
476 |
– |
l.add(new Object()); |
477 |
– |
l.set(5,new Object()); |
478 |
– |
fail("set failed = l.set(5,..) l.size():" + l.size()); |
479 |
– |
}catch(IndexOutOfBoundsException success){} |
480 |
– |
} |
481 |
– |
|
482 |
– |
public void testadd1() { |
483 |
– |
try { |
484 |
– |
LinkedList l = new LinkedList(); |
485 |
– |
l.add(new Object()); |
486 |
– |
l.add(-1,new Object()); |
487 |
– |
fail("Add Failed - l.add(-1) l.size(): " + l.size()); |
488 |
– |
}catch(IndexOutOfBoundsException success){} |
489 |
– |
} |
490 |
– |
|
491 |
– |
public void add2(){ |
492 |
– |
try { |
493 |
– |
LinkedList l = new LinkedList(); |
494 |
– |
l.add(new Object()); |
495 |
– |
l.add(5,new Object()); |
496 |
– |
fail("Add Failed l.add(f,...)"); |
497 |
– |
}catch(IndexOutOfBoundsException success) {} |
498 |
– |
} |
499 |
– |
|
500 |
– |
public void testremove(){ |
501 |
– |
try { |
502 |
– |
LinkedList l = new LinkedList(); |
503 |
– |
l.add(new Object()); |
504 |
– |
l.remove(-1); |
505 |
– |
fail("Remove Failed l.remove(-1); l.size():" + l.size()); |
506 |
– |
}catch(IndexOutOfBoundsException success){} |
507 |
– |
} |
508 |
– |
|
509 |
– |
public void testremove1(){ |
510 |
– |
try { |
511 |
– |
LinkedList l = new LinkedList(); |
512 |
– |
l.add(new Object()); |
513 |
– |
l.remove(5); |
514 |
– |
fail("Remove Failed l.remove(5); l.size():" + l.size()); |
515 |
– |
}catch(IndexOutOfBoundsException success){} |
516 |
– |
} |
517 |
– |
|
518 |
– |
|
519 |
– |
public void testremove2(){ |
520 |
– |
try{ |
521 |
– |
LinkedList l = new LinkedList(); |
522 |
– |
l.remove(); |
523 |
– |
fail("LinkedList - Object remove() should throw a NoSuchElementException"); |
524 |
– |
}catch(NoSuchElementException e){} |
525 |
– |
} |
526 |
– |
|
527 |
– |
public void testlistIt1() { |
528 |
– |
try { |
529 |
– |
LinkedList l = new LinkedList(); |
530 |
– |
l.add(new Object()); |
531 |
– |
l.listIterator(5); |
532 |
– |
fail("l.listIterator(5) l.size():" + l.size()); |
533 |
– |
}catch(IndexOutOfBoundsException success){} |
534 |
– |
} |
535 |
– |
|
536 |
– |
public void testlistIt2() { |
537 |
– |
try { |
538 |
– |
LinkedList l = new LinkedList(); |
539 |
– |
l.add(new Object()); |
540 |
– |
l.listIterator(-1); |
541 |
– |
fail("l.listIterator(-1) l.size():" + l.size()); |
542 |
– |
}catch(IndexOutOfBoundsException success){} |
543 |
– |
} |
544 |
– |
|
545 |
– |
public void testlistIt3() { |
546 |
– |
try { |
547 |
– |
LinkedList l = new LinkedList(); |
548 |
– |
l.add(new Object()); |
549 |
– |
ListIterator a = l.listIterator(0); |
550 |
– |
l.removeFirst(); |
551 |
– |
a.next(); |
552 |
– |
fail("l.listIterator(-1) l.size():" + l.size()); |
553 |
– |
}catch(ConcurrentModificationException success){} |
554 |
– |
} |
555 |
– |
|
556 |
– |
public void testToArray_BadArg() { |
557 |
– |
try { |
558 |
– |
LinkedList l = new LinkedList(); |
559 |
– |
l.add(new Object()); |
560 |
– |
Object o[] = l.toArray(null); |
561 |
– |
fail("l.toArray(null) did not throw an exception"); |
562 |
– |
}catch(NullPointerException success){} |
563 |
– |
} |
564 |
– |
|
565 |
– |
public void testToArray1_BadArg() { |
566 |
– |
try { |
567 |
– |
LinkedList l = new LinkedList(); |
568 |
– |
l.add(new Integer(5)); |
569 |
– |
Object o[] = l.toArray(new String[10] ); |
570 |
– |
fail("l.toArray(String[] f) did not throw an exception, an Integer was added"); |
571 |
– |
}catch(ArrayStoreException success){} |
572 |
– |
} |
449 |
|
|
450 |
|
} |