File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
src/library/scala/collection/mutable
test/junit/scala/collection/mutable Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -200,9 +200,7 @@ sealed class PriorityQueue[A](implicit val ord: Ordering[A])
200200 * @return A reversed priority queue.
201201 */
202202 def reverse = {
203- val revq = new PriorityQueue [A ]()(new scala.math.Ordering [A ] {
204- def compare (x : A , y : A ) = ord.compare(y, x)
205- })
203+ val revq = new PriorityQueue [A ]()(ord.reverse)
206204 for (i <- 1 until resarr.length) revq += resarr(i)
207205 revq
208206 }
Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ class PriorityQueueTest {
1313 val elements = List .fill(1000 )(scala.util.Random .nextInt(Int .MaxValue ))
1414 priorityQueue.enqueue(elements :_* )
1515
16+ @ Test
17+ def orderingReverseReverse () {
18+ val pq = new mutable.PriorityQueue [Nothing ]()((_,_)=> 42 )
19+ assert(pq.ord eq pq.reverse.reverse.ord)
20+ }
21+
1622 @ Test
1723 def canSerialize () {
1824 val outputStream = new ByteArrayOutputStream ()
@@ -27,6 +33,7 @@ class PriorityQueueTest {
2733
2834 val objectInputStream = new ObjectInputStream (new ByteArrayInputStream (bytes))
2935 val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf [PriorityQueue [Int ]]
36+ // correct sequencing is also tested here:
3037 assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse)
3138 }
3239}
You can’t perform that action at this time.
0 commit comments