38 |
|
} |
39 |
|
|
40 |
|
public static void main(String[] args) { |
41 |
< |
junit.textui.TestRunner.run(suite()); |
41 |
> |
main(suite(), args); |
42 |
|
} |
43 |
|
|
44 |
|
public static Test suite() { |
47 |
|
new InitialCapacity().testSuite()); |
48 |
|
} |
49 |
|
|
50 |
– |
private static final int NOCAP = Integer.MAX_VALUE; |
51 |
– |
|
50 |
|
/** Sample Comparator */ |
51 |
|
static class MyReverseComparator implements Comparator { |
52 |
|
public int compare(Object x, Object y) { |
67 |
|
for (int i = (n & 1); i < n; i += 2) |
68 |
|
assertTrue(q.offer(new Integer(i))); |
69 |
|
assertFalse(q.isEmpty()); |
70 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
70 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
71 |
|
assertEquals(n, q.size()); |
72 |
|
return q; |
73 |
|
} |
76 |
|
* A new queue has unbounded capacity |
77 |
|
*/ |
78 |
|
public void testConstructor1() { |
79 |
< |
assertEquals(NOCAP, new PriorityBlockingQueue(SIZE).remainingCapacity()); |
79 |
> |
assertEquals(Integer.MAX_VALUE, |
80 |
> |
new PriorityBlockingQueue(SIZE).remainingCapacity()); |
81 |
|
} |
82 |
|
|
83 |
|
/** |
158 |
|
public void testEmpty() { |
159 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(2); |
160 |
|
assertTrue(q.isEmpty()); |
161 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
161 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
162 |
|
q.add(one); |
163 |
|
assertFalse(q.isEmpty()); |
164 |
|
q.add(two); |
168 |
|
} |
169 |
|
|
170 |
|
/** |
171 |
< |
* remainingCapacity does not change when elements added or removed, |
173 |
< |
* but size does |
171 |
> |
* remainingCapacity() always returns Integer.MAX_VALUE |
172 |
|
*/ |
173 |
|
public void testRemainingCapacity() { |
174 |
< |
PriorityBlockingQueue q = populatedQueue(SIZE); |
174 |
> |
BlockingQueue q = populatedQueue(SIZE); |
175 |
|
for (int i = 0; i < SIZE; ++i) { |
176 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
177 |
< |
assertEquals(SIZE-i, q.size()); |
178 |
< |
q.remove(); |
176 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
177 |
> |
assertEquals(SIZE - i, q.size()); |
178 |
> |
assertEquals(i, q.remove()); |
179 |
|
} |
180 |
|
for (int i = 0; i < SIZE; ++i) { |
181 |
< |
assertEquals(NOCAP, q.remainingCapacity()); |
181 |
> |
assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); |
182 |
|
assertEquals(i, q.size()); |
183 |
< |
q.add(new Integer(i)); |
183 |
> |
assertTrue(q.add(i)); |
184 |
|
} |
185 |
|
} |
186 |
|
|
197 |
|
* Offer of non-Comparable throws CCE |
198 |
|
*/ |
199 |
|
public void testOfferNonComparable() { |
200 |
+ |
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
201 |
|
try { |
203 |
– |
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
204 |
– |
q.offer(new Object()); |
202 |
|
q.offer(new Object()); |
203 |
|
q.offer(new Object()); |
204 |
|
shouldThrow(); |
220 |
|
* addAll(this) throws IAE |
221 |
|
*/ |
222 |
|
public void testAddAllSelf() { |
223 |
+ |
PriorityBlockingQueue q = populatedQueue(SIZE); |
224 |
|
try { |
227 |
– |
PriorityBlockingQueue q = populatedQueue(SIZE); |
225 |
|
q.addAll(q); |
226 |
|
shouldThrow(); |
227 |
|
} catch (IllegalArgumentException success) {} |
232 |
|
* possibly adding some elements |
233 |
|
*/ |
234 |
|
public void testAddAll3() { |
235 |
+ |
PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); |
236 |
+ |
Integer[] ints = new Integer[SIZE]; |
237 |
+ |
for (int i = 0; i < SIZE-1; ++i) |
238 |
+ |
ints[i] = new Integer(i); |
239 |
|
try { |
239 |
– |
PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); |
240 |
– |
Integer[] ints = new Integer[SIZE]; |
241 |
– |
for (int i = 0; i < SIZE-1; ++i) |
242 |
– |
ints[i] = new Integer(i); |
240 |
|
q.addAll(Arrays.asList(ints)); |
241 |
|
shouldThrow(); |
242 |
|
} catch (NullPointerException success) {} |