108 |
|
* Set contains all elements of collection used to initialize |
109 |
|
*/ |
110 |
|
public void testConstructor6() { |
111 |
< |
try { |
112 |
< |
Integer[] ints = new Integer[SIZE]; |
113 |
< |
for (int i = 0; i < SIZE; ++i) |
114 |
< |
ints[i] = new Integer(i); |
115 |
< |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
116 |
< |
for (int i = 0; i < SIZE; ++i) |
117 |
< |
assertEquals(ints[i], q.pollFirst()); |
118 |
< |
} |
119 |
< |
finally {} |
111 |
> |
Integer[] ints = new Integer[SIZE]; |
112 |
> |
for (int i = 0; i < SIZE; ++i) |
113 |
> |
ints[i] = new Integer(i); |
114 |
> |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
115 |
> |
for (int i = 0; i < SIZE; ++i) |
116 |
> |
assertEquals(ints[i], q.pollFirst()); |
117 |
|
} |
118 |
|
|
119 |
|
/** |
120 |
|
* The comparator used in constructor is used |
121 |
|
*/ |
122 |
|
public void testConstructor7() { |
123 |
< |
try { |
124 |
< |
MyReverseComparator cmp = new MyReverseComparator(); |
125 |
< |
TreeSet q = new TreeSet(cmp); |
126 |
< |
assertEquals(cmp, q.comparator()); |
127 |
< |
Integer[] ints = new Integer[SIZE]; |
128 |
< |
for (int i = 0; i < SIZE; ++i) |
129 |
< |
ints[i] = new Integer(i); |
130 |
< |
q.addAll(Arrays.asList(ints)); |
131 |
< |
for (int i = SIZE-1; i >= 0; --i) |
135 |
< |
assertEquals(ints[i], q.pollFirst()); |
136 |
< |
} |
137 |
< |
finally {} |
123 |
> |
MyReverseComparator cmp = new MyReverseComparator(); |
124 |
> |
TreeSet q = new TreeSet(cmp); |
125 |
> |
assertEquals(cmp, q.comparator()); |
126 |
> |
Integer[] ints = new Integer[SIZE]; |
127 |
> |
for (int i = 0; i < SIZE; ++i) |
128 |
> |
ints[i] = new Integer(i); |
129 |
> |
q.addAll(Arrays.asList(ints)); |
130 |
> |
for (int i = SIZE-1; i >= 0; --i) |
131 |
> |
assertEquals(ints[i], q.pollFirst()); |
132 |
|
} |
133 |
|
|
134 |
|
/** |
242 |
|
* Set contains all elements of successful addAll |
243 |
|
*/ |
244 |
|
public void testAddAll5() { |
245 |
< |
try { |
246 |
< |
Integer[] empty = new Integer[0]; |
247 |
< |
Integer[] ints = new Integer[SIZE]; |
248 |
< |
for (int i = 0; i < SIZE; ++i) |
249 |
< |
ints[i] = new Integer(SIZE-1-i); |
250 |
< |
TreeSet q = new TreeSet(); |
251 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
252 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
253 |
< |
for (int i = 0; i < SIZE; ++i) |
260 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
261 |
< |
} |
262 |
< |
finally {} |
245 |
> |
Integer[] empty = new Integer[0]; |
246 |
> |
Integer[] ints = new Integer[SIZE]; |
247 |
> |
for (int i = 0; i < SIZE; ++i) |
248 |
> |
ints[i] = new Integer(SIZE-1-i); |
249 |
> |
TreeSet q = new TreeSet(); |
250 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
251 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
252 |
> |
for (int i = 0; i < SIZE; ++i) |
253 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
254 |
|
} |
255 |
|
|
256 |
|
/** |
669 |
|
/** |
670 |
|
* Subsets of subsets subdivide correctly |
671 |
|
*/ |
672 |
< |
public void testRecursiveSubSets() { |
672 |
> |
public void testRecursiveSubSets() throws Exception { |
673 |
|
int setSize = 1000; |
674 |
|
Class cl = TreeSet.class; |
675 |
|
|
688 |
|
0, setSize - 1, true); |
689 |
|
} |
690 |
|
|
691 |
< |
static NavigableSet<Integer> newSet(Class cl) { |
692 |
< |
NavigableSet<Integer> result = null; |
702 |
< |
try { |
703 |
< |
result = (NavigableSet<Integer>) cl.newInstance(); |
704 |
< |
} catch (Exception e) { |
705 |
< |
fail(); |
706 |
< |
} |
691 |
> |
static NavigableSet<Integer> newSet(Class cl) throws Exception { |
692 |
> |
NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance(); |
693 |
|
assertEquals(result.size(), 0); |
694 |
|
assertFalse(result.iterator().hasNext()); |
695 |
|
return result; |
752 |
|
} else { |
753 |
|
try { |
754 |
|
set.add(element); |
755 |
< |
fail(); |
756 |
< |
} catch (IllegalArgumentException e) { |
771 |
< |
// expected |
772 |
< |
} |
755 |
> |
shouldThrow(); |
756 |
> |
} catch (IllegalArgumentException success) {} |
757 |
|
} |
758 |
|
} |
759 |
|
} |
952 |
|
assertEq(rs.last(), -1); |
953 |
|
try { |
954 |
|
set.first(); |
955 |
< |
fail(); |
956 |
< |
} catch (NoSuchElementException e) { |
973 |
< |
// expected |
974 |
< |
} |
955 |
> |
shouldThrow(); |
956 |
> |
} catch (NoSuchElementException success) {} |
957 |
|
try { |
958 |
|
set.last(); |
959 |
< |
fail(); |
960 |
< |
} catch (NoSuchElementException e) { |
979 |
< |
// expected |
980 |
< |
} |
959 |
> |
shouldThrow(); |
960 |
> |
} catch (NoSuchElementException success) {} |
961 |
|
} |
962 |
|
} |
963 |
|
|