blob: faedcf11f00241e1d641a4854ef0b032dca2e5e7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
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 orderingReverseReverse() {
val pq = new mutable.PriorityQueue[Nothing]()((_,_)=>42)
assert(pq.ord eq pq.reverse.reverse.ord)
}
@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]]
//correct sequencing is also tested here:
assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse)
}
}
|