8 |
|
import junit.framework.*; |
9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
+ |
import java.io.*; |
12 |
|
|
13 |
|
public class PriorityQueueTest extends TestCase { |
14 |
|
|
271 |
|
assertTrue(q.remove(new Integer(i))); |
272 |
|
assertFalse(q.remove(new Integer(i+1))); |
273 |
|
} |
274 |
< |
assert(q.isEmpty()); |
274 |
> |
assertTrue(q.isEmpty()); |
275 |
|
} |
276 |
|
|
277 |
|
public void testContains(){ |
389 |
|
} |
390 |
|
} |
391 |
|
|
392 |
+ |
public void testSerialization() { |
393 |
+ |
PriorityQueue q = fullQueue(N); |
394 |
+ |
try { |
395 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
396 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
397 |
+ |
out.writeObject(q); |
398 |
+ |
out.close(); |
399 |
+ |
|
400 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
401 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
402 |
+ |
PriorityQueue r = (PriorityQueue)in.readObject(); |
403 |
+ |
assertEquals(q.size(), r.size()); |
404 |
+ |
while (!q.isEmpty()) |
405 |
+ |
assertEquals(q.remove(), r.remove()); |
406 |
+ |
} catch(Exception e){ |
407 |
+ |
fail("unexpected exception"); |
408 |
+ |
} |
409 |
+ |
} |
410 |
|
} |