1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
13 |
|
import extra166y.*; |
14 |
|
import java.io.*; |
15 |
|
|
16 |
< |
public class ParallelArrayAsListTest extends JSR166TestCase{ |
16 |
> |
public class ParallelArrayAsListTest extends JSR166TestCase { |
17 |
|
|
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run (suite()); |
19 |
> |
junit.textui.TestRunner.run(suite()); |
20 |
|
} |
21 |
|
|
22 |
|
public static Test suite() { |
23 |
|
return new TestSuite(ParallelArrayAsListTest.class); |
24 |
|
} |
25 |
|
|
26 |
< |
static List populatedArray(int n){ |
26 |
> |
static List populatedArray(int n) { |
27 |
|
List a = ParallelArray.createEmpty(n, Object.class, ParallelArray.defaultExecutor()).asList(); |
28 |
|
assertTrue(a.isEmpty()); |
29 |
|
for (int i = 0; i < n; ++i) |
34 |
|
} |
35 |
|
|
36 |
|
|
37 |
< |
static List emptyArray(){ |
37 |
> |
static List emptyArray() { |
38 |
|
List a = ParallelArray.createEmpty(1, Object.class, ParallelArray.defaultExecutor()).asList(); |
39 |
|
return a; |
40 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
/** |
65 |
< |
* addAll adds each element from the given collection |
65 |
> |
* addAll adds each element from the given collection |
66 |
|
*/ |
67 |
|
public void testAddAll() { |
68 |
|
List full = populatedArray(3); |
75 |
|
} |
76 |
|
|
77 |
|
/** |
78 |
< |
* clear removes all elements from the list |
78 |
> |
* clear removes all elements from the list |
79 |
|
*/ |
80 |
|
public void testClear() { |
81 |
|
List full = populatedArray(SIZE); |
86 |
|
|
87 |
|
|
88 |
|
/** |
89 |
< |
* contains is true for added elements |
89 |
> |
* contains is true for added elements |
90 |
|
*/ |
91 |
|
public void testContains() { |
92 |
|
List full = populatedArray(3); |
130 |
|
|
131 |
|
|
132 |
|
/** |
133 |
< |
* containsAll returns true for collection with subset of elements |
133 |
> |
* containsAll returns true for collection with subset of elements |
134 |
|
*/ |
135 |
|
public void testContainsAll() { |
136 |
|
List full = populatedArray(3); |
143 |
|
} |
144 |
|
|
145 |
|
/** |
146 |
< |
* get returns the value at the given index |
146 |
> |
* get returns the value at the given index |
147 |
|
*/ |
148 |
|
public void testGet() { |
149 |
|
List full = populatedArray(3); |
151 |
|
} |
152 |
|
|
153 |
|
/** |
154 |
< |
* indexOf gives the index for the given object |
154 |
> |
* indexOf gives the index for the given object |
155 |
|
*/ |
156 |
|
public void testIndexOf() { |
157 |
|
List full = populatedArray(3); |
160 |
|
} |
161 |
|
|
162 |
|
/** |
163 |
< |
* isEmpty returns true when empty, else false |
163 |
> |
* isEmpty returns true when empty, else false |
164 |
|
*/ |
165 |
|
public void testIsEmpty() { |
166 |
|
List empty = emptyArray(); |
170 |
|
} |
171 |
|
|
172 |
|
/** |
173 |
< |
* iterator() returns an iterator containing the elements of the list |
173 |
> |
* iterator() returns an iterator containing the elements of the list |
174 |
|
*/ |
175 |
|
public void testIterator() { |
176 |
|
List full = populatedArray(SIZE); |
184 |
|
/** |
185 |
|
* iterator.remove removes element |
186 |
|
*/ |
187 |
< |
public void testIteratorRemove () { |
187 |
> |
public void testIteratorRemove() { |
188 |
|
List full = populatedArray(SIZE); |
189 |
|
Iterator it = full.iterator(); |
190 |
|
Object first = full.get(0); |
205 |
|
} |
206 |
|
|
207 |
|
/** |
208 |
< |
* lastIndexOf returns the index for the given object |
208 |
> |
* lastIndexOf returns the index for the given object |
209 |
|
*/ |
210 |
|
public void testLastIndexOf1() { |
211 |
|
List full = populatedArray(3); |
216 |
|
} |
217 |
|
|
218 |
|
/** |
219 |
< |
* listIterator traverses all elements |
219 |
> |
* listIterator traverses all elements |
220 |
|
*/ |
221 |
|
public void testListIterator1() { |
222 |
|
List full = populatedArray(SIZE); |
228 |
|
} |
229 |
|
|
230 |
|
/** |
231 |
< |
* listIterator only returns those elements after the given index |
231 |
> |
* listIterator only returns those elements after the given index |
232 |
|
*/ |
233 |
|
public void testListIterator2() { |
234 |
|
List full = populatedArray(3); |
240 |
|
} |
241 |
|
|
242 |
|
/** |
243 |
< |
* remove removes and returns the object at the given index |
243 |
> |
* remove removes and returns the object at the given index |
244 |
|
*/ |
245 |
|
public void testRemove() { |
246 |
|
List full = populatedArray(3); |
249 |
|
} |
250 |
|
|
251 |
|
/** |
252 |
< |
* removeAll removes all elements from the given collection |
252 |
> |
* removeAll removes all elements from the given collection |
253 |
|
*/ |
254 |
|
public void testRemoveAll() { |
255 |
|
List full = populatedArray(3); |
261 |
|
} |
262 |
|
|
263 |
|
/** |
264 |
< |
* set changes the element at the given index |
264 |
> |
* set changes the element at the given index |
265 |
|
*/ |
266 |
|
public void testSet() { |
267 |
|
List full = populatedArray(3); |
270 |
|
} |
271 |
|
|
272 |
|
/** |
273 |
< |
* size returns the number of elements |
273 |
> |
* size returns the number of elements |
274 |
|
*/ |
275 |
|
public void testSize() { |
276 |
|
List empty = emptyArray(); |
280 |
|
} |
281 |
|
|
282 |
|
/** |
283 |
< |
* toArray returns an Object array containing all elements from the list |
283 |
> |
* toArray returns an Object array containing all elements from the list |
284 |
|
*/ |
285 |
|
public void testToArray() { |
286 |
|
List full = populatedArray(3); |
292 |
|
} |
293 |
|
|
294 |
|
/** |
295 |
< |
* toArray returns an Integer array containing all elements from |
296 |
< |
* the list |
295 |
> |
* toArray returns an Integer array containing all elements from |
296 |
> |
* the list |
297 |
|
*/ |
298 |
|
public void testToArray2() { |
299 |
|
List full = populatedArray(3); |
300 |
|
Integer[] i = new Integer[3]; |
301 |
< |
i = (Integer[])full.toArray(i); |
302 |
< |
assertEquals(3, i.length); |
301 |
> |
assertSame(i, full.toArray(i)); |
302 |
|
assertEquals(0, i[0].intValue()); |
303 |
|
assertEquals(1, i[1].intValue()); |
304 |
|
assertEquals(2, i[2].intValue()); |
321 |
|
} |
322 |
|
|
323 |
|
List s = a.subList(2, 5); |
324 |
< |
assertEquals(s.size(), 3); |
324 |
> |
assertEquals(3, s.size()); |
325 |
|
s.set(2, m1); |
326 |
|
assertEquals(a.get(4), m1); |
327 |
|
s.clear(); |
328 |
< |
assertEquals(a.size(), 7); |
328 |
> |
assertEquals(7, a.size()); |
329 |
|
} |
330 |
|
|
331 |
|
// Exception tests |
332 |
|
|
333 |
|
/** |
334 |
< |
* toArray throws an ArrayStoreException when the given array |
335 |
< |
* can not store the objects inside the list |
334 |
> |
* toArray throws an ArrayStoreException when the given array |
335 |
> |
* can not store the objects inside the list |
336 |
|
*/ |
337 |
|
public void testToArray_ArrayStoreException() { |
338 |
|
try { |
341 |
|
c.add("asdadasd"); |
342 |
|
c.toArray(new Long[5]); |
343 |
|
shouldThrow(); |
344 |
< |
} catch (ArrayStoreException e){} |
344 |
> |
} catch (ArrayStoreException e) {} |
345 |
|
} |
346 |
|
|
347 |
|
/** |
348 |
< |
* get throws an IndexOutOfBoundsException on a negative index |
348 |
> |
* get throws an IndexOutOfBoundsException on a negative index |
349 |
|
*/ |
350 |
|
public void testGet1_IndexOutOfBoundsException() { |
351 |
|
try { |
352 |
|
List c = emptyArray(); |
353 |
|
c.get(-1); |
354 |
|
shouldThrow(); |
355 |
< |
} catch (IndexOutOfBoundsException e){} |
355 |
> |
} catch (IndexOutOfBoundsException e) {} |
356 |
|
} |
357 |
|
|
358 |
|
/** |
359 |
< |
* get throws an IndexOutOfBoundsException on a too high index |
359 |
> |
* get throws an IndexOutOfBoundsException on a too high index |
360 |
|
*/ |
361 |
|
public void testGet2_IndexOutOfBoundsException() { |
362 |
|
try { |
365 |
|
c.add("asdad"); |
366 |
|
c.get(100); |
367 |
|
shouldThrow(); |
368 |
< |
} catch (IndexOutOfBoundsException e){} |
368 |
> |
} catch (IndexOutOfBoundsException e) {} |
369 |
|
} |
370 |
|
|
371 |
|
/** |
372 |
< |
* set throws an IndexOutOfBoundsException on a negative index |
372 |
> |
* set throws an IndexOutOfBoundsException on a negative index |
373 |
|
*/ |
374 |
|
public void testSet1_IndexOutOfBoundsException() { |
375 |
|
try { |
376 |
|
List c = emptyArray(); |
377 |
|
c.set(-1,"qwerty"); |
378 |
|
shouldThrow(); |
379 |
< |
} catch (IndexOutOfBoundsException e){} |
379 |
> |
} catch (IndexOutOfBoundsException e) {} |
380 |
|
} |
381 |
|
|
382 |
|
/** |
383 |
< |
* set throws an IndexOutOfBoundsException on a too high index |
383 |
> |
* set throws an IndexOutOfBoundsException on a too high index |
384 |
|
*/ |
385 |
|
public void testSet2() { |
386 |
|
try { |
389 |
|
c.add("asdad"); |
390 |
|
c.set(100, "qwerty"); |
391 |
|
shouldThrow(); |
392 |
< |
} catch (IndexOutOfBoundsException e){} |
392 |
> |
} catch (IndexOutOfBoundsException e) {} |
393 |
|
} |
394 |
|
|
395 |
|
/** |
396 |
< |
* add throws an IndexOutOfBoundsException on a negative index |
396 |
> |
* add throws an IndexOutOfBoundsException on a negative index |
397 |
|
*/ |
398 |
|
public void testAdd1_IndexOutOfBoundsException() { |
399 |
|
try { |
400 |
|
List c = emptyArray(); |
401 |
|
c.add(-1,"qwerty"); |
402 |
|
shouldThrow(); |
403 |
< |
} catch (IndexOutOfBoundsException e){} |
403 |
> |
} catch (IndexOutOfBoundsException e) {} |
404 |
|
} |
405 |
|
|
406 |
|
/** |
407 |
< |
* add throws an IndexOutOfBoundsException on a too high index |
407 |
> |
* add throws an IndexOutOfBoundsException on a too high index |
408 |
|
*/ |
409 |
|
public void testAdd2_IndexOutOfBoundsException() { |
410 |
|
try { |
413 |
|
c.add("asdasdasd"); |
414 |
|
c.add(100, "qwerty"); |
415 |
|
shouldThrow(); |
416 |
< |
} catch (IndexOutOfBoundsException e){} |
416 |
> |
} catch (IndexOutOfBoundsException e) {} |
417 |
|
} |
418 |
|
|
419 |
|
/** |
420 |
< |
* remove throws an IndexOutOfBoundsException on a negative index |
420 |
> |
* remove throws an IndexOutOfBoundsException on a negative index |
421 |
|
*/ |
422 |
|
public void testRemove1_IndexOutOfBounds() { |
423 |
|
try { |
424 |
|
List c = emptyArray(); |
425 |
|
c.remove(-1); |
426 |
|
shouldThrow(); |
427 |
< |
} catch (IndexOutOfBoundsException e){} |
427 |
> |
} catch (IndexOutOfBoundsException e) {} |
428 |
|
} |
429 |
|
|
430 |
|
/** |
431 |
< |
* remove throws an IndexOutOfBoundsException on a too high index |
431 |
> |
* remove throws an IndexOutOfBoundsException on a too high index |
432 |
|
*/ |
433 |
|
public void testRemove2_IndexOutOfBounds() { |
434 |
|
try { |
437 |
|
c.add("adasdasd"); |
438 |
|
c.remove(100); |
439 |
|
shouldThrow(); |
440 |
< |
} catch (IndexOutOfBoundsException e){} |
440 |
> |
} catch (IndexOutOfBoundsException e) {} |
441 |
|
} |
442 |
|
|
443 |
|
/** |
444 |
< |
* addAll throws an IndexOutOfBoundsException on a negative index |
444 |
> |
* addAll throws an IndexOutOfBoundsException on a negative index |
445 |
|
*/ |
446 |
|
public void testAddAll1_IndexOutOfBoundsException() { |
447 |
|
try { |
448 |
|
List c = emptyArray(); |
449 |
|
c.addAll(-1,new LinkedList()); |
450 |
|
shouldThrow(); |
451 |
< |
} catch (IndexOutOfBoundsException e){} |
451 |
> |
} catch (IndexOutOfBoundsException e) {} |
452 |
|
} |
453 |
|
|
454 |
|
/** |
455 |
< |
* addAll throws an IndexOutOfBoundsException on a too high index |
455 |
> |
* addAll throws an IndexOutOfBoundsException on a too high index |
456 |
|
*/ |
457 |
|
public void testAddAll2_IndexOutOfBoundsException() { |
458 |
|
try { |
461 |
|
c.add("asdasdasd"); |
462 |
|
c.addAll(100, new LinkedList()); |
463 |
|
shouldThrow(); |
464 |
< |
} catch (IndexOutOfBoundsException e){} |
464 |
> |
} catch (IndexOutOfBoundsException e) {} |
465 |
|
} |
466 |
|
|
467 |
|
/** |
468 |
< |
* listIterator throws an IndexOutOfBoundsException on a negative index |
468 |
> |
* listIterator throws an IndexOutOfBoundsException on a negative index |
469 |
|
*/ |
470 |
|
public void testListIterator1_IndexOutOfBoundsException() { |
471 |
|
try { |
472 |
|
List c = emptyArray(); |
473 |
|
c.listIterator(-1); |
474 |
|
shouldThrow(); |
475 |
< |
} catch (IndexOutOfBoundsException e){} |
475 |
> |
} catch (IndexOutOfBoundsException e) {} |
476 |
|
} |
477 |
|
|
478 |
|
/** |
479 |
< |
* listIterator throws an IndexOutOfBoundsException on a too high index |
479 |
> |
* listIterator throws an IndexOutOfBoundsException on a too high index |
480 |
|
*/ |
481 |
|
public void testListIterator2_IndexOutOfBoundsException() { |
482 |
|
try { |
485 |
|
c.add("asdasdas"); |
486 |
|
c.listIterator(100); |
487 |
|
shouldThrow(); |
488 |
< |
} catch (IndexOutOfBoundsException e){} |
488 |
> |
} catch (IndexOutOfBoundsException e) {} |
489 |
|
} |
490 |
|
|
491 |
|
/** |
492 |
< |
* subList throws an IndexOutOfBoundsException on a negative index |
492 |
> |
* subList throws an IndexOutOfBoundsException on a negative index |
493 |
|
*/ |
494 |
|
public void testSubList1_IndexOutOfBoundsException() { |
495 |
|
try { |
497 |
|
c.subList(-1,100); |
498 |
|
|
499 |
|
shouldThrow(); |
500 |
< |
} catch (IndexOutOfBoundsException e){} |
500 |
> |
} catch (IndexOutOfBoundsException e) {} |
501 |
|
} |
502 |
|
|
503 |
|
/** |
504 |
< |
* subList throws an IndexOutOfBoundsException on a too high index |
504 |
> |
* subList throws an IndexOutOfBoundsException on a too high index |
505 |
|
*/ |
506 |
|
public void testSubList2_IndexOutOfBoundsException() { |
507 |
|
try { |
509 |
|
c.add("asdasd"); |
510 |
|
c.subList(1,100); |
511 |
|
shouldThrow(); |
512 |
< |
} catch (IndexOutOfBoundsException e){} |
512 |
> |
} catch (IndexOutOfBoundsException e) {} |
513 |
|
} |
514 |
|
|
515 |
|
/** |
516 |
< |
* subList throws IndexOutOfBoundsException when the second index |
517 |
< |
* is lower then the first |
516 |
> |
* subList throws IndexOutOfBoundsException when the second index |
517 |
> |
* is lower then the first |
518 |
|
*/ |
519 |
|
public void testSubList3_IndexOutOfBoundsException() { |
520 |
|
try { |
522 |
|
c.subList(3,1); |
523 |
|
|
524 |
|
shouldThrow(); |
525 |
< |
} catch (IndexOutOfBoundsException e){} |
525 |
> |
} catch (IndexOutOfBoundsException e) {} |
526 |
|
} |
527 |
|
|
528 |
|
|