38 |
|
* Integers 0 ... n - 1. |
39 |
|
*/ |
40 |
|
private static ConcurrentSkipListSet<Integer> populatedSet(int n) { |
41 |
< |
ConcurrentSkipListSet<Integer> q = |
42 |
< |
new ConcurrentSkipListSet<Integer>(); |
41 |
> |
ConcurrentSkipListSet<Integer> q = new ConcurrentSkipListSet<>(); |
42 |
|
assertTrue(q.isEmpty()); |
43 |
|
for (int i = n - 1; i >= 0; i -= 2) |
44 |
|
assertTrue(q.add(new Integer(i))); |
456 |
|
*/ |
457 |
|
public void testToArray() { |
458 |
|
ConcurrentSkipListSet q = populatedSet(SIZE); |
459 |
< |
Object[] o = q.toArray(); |
460 |
< |
for (int i = 0; i < o.length; i++) |
461 |
< |
assertSame(o[i], q.pollFirst()); |
459 |
> |
Object[] a = q.toArray(); |
460 |
> |
assertSame(Object[].class, a.getClass()); |
461 |
> |
for (Object o : a) |
462 |
> |
assertSame(o, q.pollFirst()); |
463 |
> |
assertTrue(q.isEmpty()); |
464 |
|
} |
465 |
|
|
466 |
|
/** |
470 |
|
ConcurrentSkipListSet<Integer> q = populatedSet(SIZE); |
471 |
|
Integer[] ints = new Integer[SIZE]; |
472 |
|
assertSame(ints, q.toArray(ints)); |
473 |
< |
for (int i = 0; i < ints.length; i++) |
474 |
< |
assertSame(ints[i], q.pollFirst()); |
473 |
> |
for (Integer o : ints) |
474 |
> |
assertSame(o, q.pollFirst()); |
475 |
> |
assertTrue(q.isEmpty()); |
476 |
|
} |
477 |
|
|
478 |
|
/** |
528 |
|
} |
529 |
|
|
530 |
|
/** |
531 |
< |
* A deserialized serialized set has same elements |
531 |
> |
* A cloned set equals original |
532 |
> |
*/ |
533 |
> |
public void testClone() { |
534 |
> |
ConcurrentSkipListSet x = populatedSet(SIZE); |
535 |
> |
ConcurrentSkipListSet y = x.clone(); |
536 |
> |
|
537 |
> |
assertNotSame(x, y); |
538 |
> |
assertEquals(x.size(), y.size()); |
539 |
> |
assertEquals(x, y); |
540 |
> |
assertEquals(y, x); |
541 |
> |
while (!x.isEmpty()) { |
542 |
> |
assertFalse(y.isEmpty()); |
543 |
> |
assertEquals(x.pollFirst(), y.pollFirst()); |
544 |
> |
} |
545 |
> |
assertTrue(y.isEmpty()); |
546 |
> |
} |
547 |
> |
|
548 |
> |
/** |
549 |
> |
* A deserialized/reserialized set equals original |
550 |
|
*/ |
551 |
|
public void testSerialization() throws Exception { |
552 |
|
NavigableSet x = populatedSet(SIZE); |