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); |
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); |
332 |
|
// Exception tests |
333 |
|
|
334 |
|
/** |
335 |
< |
* toArray throws an ArrayStoreException when the given array |
336 |
< |
* can not store the objects inside the list |
335 |
> |
* toArray throws an ArrayStoreException when the given array |
336 |
> |
* can not store the objects inside the list |
337 |
|
*/ |
338 |
|
public void testToArray_ArrayStoreException() { |
339 |
|
try { |
342 |
|
c.add("asdadasd"); |
343 |
|
c.toArray(new Long[5]); |
344 |
|
shouldThrow(); |
345 |
< |
} catch (ArrayStoreException e){} |
345 |
> |
} catch (ArrayStoreException e) {} |
346 |
|
} |
347 |
|
|
348 |
|
/** |
349 |
< |
* get throws an IndexOutOfBoundsException on a negative index |
349 |
> |
* get throws an IndexOutOfBoundsException on a negative index |
350 |
|
*/ |
351 |
|
public void testGet1_IndexOutOfBoundsException() { |
352 |
|
try { |
353 |
|
List c = emptyArray(); |
354 |
|
c.get(-1); |
355 |
|
shouldThrow(); |
356 |
< |
} catch (IndexOutOfBoundsException e){} |
356 |
> |
} catch (IndexOutOfBoundsException e) {} |
357 |
|
} |
358 |
|
|
359 |
|
/** |
360 |
< |
* get throws an IndexOutOfBoundsException on a too high index |
360 |
> |
* get throws an IndexOutOfBoundsException on a too high index |
361 |
|
*/ |
362 |
|
public void testGet2_IndexOutOfBoundsException() { |
363 |
|
try { |
366 |
|
c.add("asdad"); |
367 |
|
c.get(100); |
368 |
|
shouldThrow(); |
369 |
< |
} catch (IndexOutOfBoundsException e){} |
369 |
> |
} catch (IndexOutOfBoundsException e) {} |
370 |
|
} |
371 |
|
|
372 |
|
/** |
373 |
< |
* set throws an IndexOutOfBoundsException on a negative index |
373 |
> |
* set throws an IndexOutOfBoundsException on a negative index |
374 |
|
*/ |
375 |
|
public void testSet1_IndexOutOfBoundsException() { |
376 |
|
try { |
377 |
|
List c = emptyArray(); |
378 |
|
c.set(-1,"qwerty"); |
379 |
|
shouldThrow(); |
380 |
< |
} catch (IndexOutOfBoundsException e){} |
380 |
> |
} catch (IndexOutOfBoundsException e) {} |
381 |
|
} |
382 |
|
|
383 |
|
/** |
384 |
< |
* set throws an IndexOutOfBoundsException on a too high index |
384 |
> |
* set throws an IndexOutOfBoundsException on a too high index |
385 |
|
*/ |
386 |
|
public void testSet2() { |
387 |
|
try { |
390 |
|
c.add("asdad"); |
391 |
|
c.set(100, "qwerty"); |
392 |
|
shouldThrow(); |
393 |
< |
} catch (IndexOutOfBoundsException e){} |
393 |
> |
} catch (IndexOutOfBoundsException e) {} |
394 |
|
} |
395 |
|
|
396 |
|
/** |
397 |
< |
* add throws an IndexOutOfBoundsException on a negative index |
397 |
> |
* add throws an IndexOutOfBoundsException on a negative index |
398 |
|
*/ |
399 |
|
public void testAdd1_IndexOutOfBoundsException() { |
400 |
|
try { |
401 |
|
List c = emptyArray(); |
402 |
|
c.add(-1,"qwerty"); |
403 |
|
shouldThrow(); |
404 |
< |
} catch (IndexOutOfBoundsException e){} |
404 |
> |
} catch (IndexOutOfBoundsException e) {} |
405 |
|
} |
406 |
|
|
407 |
|
/** |
408 |
< |
* add throws an IndexOutOfBoundsException on a too high index |
408 |
> |
* add throws an IndexOutOfBoundsException on a too high index |
409 |
|
*/ |
410 |
|
public void testAdd2_IndexOutOfBoundsException() { |
411 |
|
try { |
414 |
|
c.add("asdasdasd"); |
415 |
|
c.add(100, "qwerty"); |
416 |
|
shouldThrow(); |
417 |
< |
} catch (IndexOutOfBoundsException e){} |
417 |
> |
} catch (IndexOutOfBoundsException e) {} |
418 |
|
} |
419 |
|
|
420 |
|
/** |
421 |
< |
* remove throws an IndexOutOfBoundsException on a negative index |
421 |
> |
* remove throws an IndexOutOfBoundsException on a negative index |
422 |
|
*/ |
423 |
|
public void testRemove1_IndexOutOfBounds() { |
424 |
|
try { |
425 |
|
List c = emptyArray(); |
426 |
|
c.remove(-1); |
427 |
|
shouldThrow(); |
428 |
< |
} catch (IndexOutOfBoundsException e){} |
428 |
> |
} catch (IndexOutOfBoundsException e) {} |
429 |
|
} |
430 |
|
|
431 |
|
/** |
432 |
< |
* remove throws an IndexOutOfBoundsException on a too high index |
432 |
> |
* remove throws an IndexOutOfBoundsException on a too high index |
433 |
|
*/ |
434 |
|
public void testRemove2_IndexOutOfBounds() { |
435 |
|
try { |
438 |
|
c.add("adasdasd"); |
439 |
|
c.remove(100); |
440 |
|
shouldThrow(); |
441 |
< |
} catch (IndexOutOfBoundsException e){} |
441 |
> |
} catch (IndexOutOfBoundsException e) {} |
442 |
|
} |
443 |
|
|
444 |
|
/** |
445 |
< |
* addAll throws an IndexOutOfBoundsException on a negative index |
445 |
> |
* addAll throws an IndexOutOfBoundsException on a negative index |
446 |
|
*/ |
447 |
|
public void testAddAll1_IndexOutOfBoundsException() { |
448 |
|
try { |
449 |
|
List c = emptyArray(); |
450 |
|
c.addAll(-1,new LinkedList()); |
451 |
|
shouldThrow(); |
452 |
< |
} catch (IndexOutOfBoundsException e){} |
452 |
> |
} catch (IndexOutOfBoundsException e) {} |
453 |
|
} |
454 |
|
|
455 |
|
/** |
456 |
< |
* addAll throws an IndexOutOfBoundsException on a too high index |
456 |
> |
* addAll throws an IndexOutOfBoundsException on a too high index |
457 |
|
*/ |
458 |
|
public void testAddAll2_IndexOutOfBoundsException() { |
459 |
|
try { |
462 |
|
c.add("asdasdasd"); |
463 |
|
c.addAll(100, new LinkedList()); |
464 |
|
shouldThrow(); |
465 |
< |
} catch (IndexOutOfBoundsException e){} |
465 |
> |
} catch (IndexOutOfBoundsException e) {} |
466 |
|
} |
467 |
|
|
468 |
|
/** |
469 |
< |
* listIterator throws an IndexOutOfBoundsException on a negative index |
469 |
> |
* listIterator throws an IndexOutOfBoundsException on a negative index |
470 |
|
*/ |
471 |
|
public void testListIterator1_IndexOutOfBoundsException() { |
472 |
|
try { |
473 |
|
List c = emptyArray(); |
474 |
|
c.listIterator(-1); |
475 |
|
shouldThrow(); |
476 |
< |
} catch (IndexOutOfBoundsException e){} |
476 |
> |
} catch (IndexOutOfBoundsException e) {} |
477 |
|
} |
478 |
|
|
479 |
|
/** |
480 |
< |
* listIterator throws an IndexOutOfBoundsException on a too high index |
480 |
> |
* listIterator throws an IndexOutOfBoundsException on a too high index |
481 |
|
*/ |
482 |
|
public void testListIterator2_IndexOutOfBoundsException() { |
483 |
|
try { |
486 |
|
c.add("asdasdas"); |
487 |
|
c.listIterator(100); |
488 |
|
shouldThrow(); |
489 |
< |
} catch (IndexOutOfBoundsException e){} |
489 |
> |
} catch (IndexOutOfBoundsException e) {} |
490 |
|
} |
491 |
|
|
492 |
|
/** |
493 |
< |
* subList throws an IndexOutOfBoundsException on a negative index |
493 |
> |
* subList throws an IndexOutOfBoundsException on a negative index |
494 |
|
*/ |
495 |
|
public void testSubList1_IndexOutOfBoundsException() { |
496 |
|
try { |
498 |
|
c.subList(-1,100); |
499 |
|
|
500 |
|
shouldThrow(); |
501 |
< |
} catch (IndexOutOfBoundsException e){} |
501 |
> |
} catch (IndexOutOfBoundsException e) {} |
502 |
|
} |
503 |
|
|
504 |
|
/** |
505 |
< |
* subList throws an IndexOutOfBoundsException on a too high index |
505 |
> |
* subList throws an IndexOutOfBoundsException on a too high index |
506 |
|
*/ |
507 |
|
public void testSubList2_IndexOutOfBoundsException() { |
508 |
|
try { |
510 |
|
c.add("asdasd"); |
511 |
|
c.subList(1,100); |
512 |
|
shouldThrow(); |
513 |
< |
} catch (IndexOutOfBoundsException e){} |
513 |
> |
} catch (IndexOutOfBoundsException e) {} |
514 |
|
} |
515 |
|
|
516 |
|
/** |
517 |
< |
* subList throws IndexOutOfBoundsException when the second index |
518 |
< |
* is lower then the first |
517 |
> |
* subList throws IndexOutOfBoundsException when the second index |
518 |
> |
* is lower then the first |
519 |
|
*/ |
520 |
|
public void testSubList3_IndexOutOfBoundsException() { |
521 |
|
try { |
523 |
|
c.subList(3,1); |
524 |
|
|
525 |
|
shouldThrow(); |
526 |
< |
} catch (IndexOutOfBoundsException e){} |
526 |
> |
} catch (IndexOutOfBoundsException e) {} |
527 |
|
} |
528 |
|
|
529 |
|
|