diff options
author | rjfwhite <stuff@rjfw.co.uk> | 2013-11-11 12:34:21 +0000 |
---|---|---|
committer | rjfwhite <stuff@rjfw.co.uk> | 2013-11-11 12:39:28 +0000 |
commit | 1ca329e7f9795ae8256f010b94742417db6d4a55 (patch) | |
tree | d5af823718755bae1c2497bcca2170d5c8f36198 /test/junit | |
parent | 3127ec09783572cffe33238f80bcf5cca609b9ec (diff) | |
download | scala-1ca329e7f9795ae8256f010b94742417db6d4a55.tar.gz scala-1ca329e7f9795ae8256f010b94742417db6d4a55.tar.bz2 scala-1ca329e7f9795ae8256f010b94742417db6d4a55.zip |
SI-7568 Adding PriorityQueueTest
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/collection/PriorityQueueTest.scala | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/junit/scala/collection/PriorityQueueTest.scala b/test/junit/scala/collection/PriorityQueueTest.scala new file mode 100644 index 0000000000..a14f1bf4c8 --- /dev/null +++ b/test/junit/scala/collection/PriorityQueueTest.scala @@ -0,0 +1,32 @@ +package scala.collection.mutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import scala.collection.mutable +import java.io.{ObjectInputStream, ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream} + +@RunWith(classOf[JUnit4]) +/* Test for SI-7568 */ +class PriorityQueueTest { + val priorityQueue = new mutable.PriorityQueue[Int]() + val elements = List.fill(1000)(scala.util.Random.nextInt(Int.MaxValue)) + priorityQueue.enqueue(elements :_*) + + @Test + def canSerialize() { + val outputStream = new ByteArrayOutputStream() + new ObjectOutputStream(outputStream).writeObject(priorityQueue) + } + + @Test + def maintainsStateWhenDeserialized() { + val outputStream = new ByteArrayOutputStream() + new ObjectOutputStream(outputStream).writeObject(priorityQueue) + val bytes = outputStream.toByteArray + + val objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) + val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf[PriorityQueue[Int]] + assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse) + } +} |