2013-04-03 20:33:32 +04:00
|
|
|
// Copyright (c) 2013, Prometheus Team
|
2013-02-12 05:36:06 +04:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2012-05-20 01:59:25 +04:00
|
|
|
|
2013-04-03 20:33:32 +04:00
|
|
|
package prometheus
|
2012-05-20 01:59:25 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"container/heap"
|
2013-01-18 19:29:47 +04:00
|
|
|
. "github.com/matttproud/gocheck"
|
2012-05-20 01:59:25 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *S) TestPriorityQueueSort(c *C) {
|
2013-04-03 20:33:32 +04:00
|
|
|
q := make(priorityQueue, 0, 6)
|
2012-05-20 01:59:25 +04:00
|
|
|
|
|
|
|
c.Check(len(q), Equals, 0)
|
|
|
|
|
2013-04-03 20:33:32 +04:00
|
|
|
heap.Push(&q, &item{Value: "newest", Priority: -100})
|
|
|
|
heap.Push(&q, &item{Value: "older", Priority: 90})
|
|
|
|
heap.Push(&q, &item{Value: "oldest", Priority: 100})
|
|
|
|
heap.Push(&q, &item{Value: "newer", Priority: -90})
|
|
|
|
heap.Push(&q, &item{Value: "new", Priority: -80})
|
|
|
|
heap.Push(&q, &item{Value: "old", Priority: 80})
|
2012-05-20 01:59:25 +04:00
|
|
|
|
|
|
|
c.Check(len(q), Equals, 6)
|
|
|
|
|
|
|
|
c.Check(heap.Pop(&q), ValueEquals, "oldest")
|
|
|
|
c.Check(heap.Pop(&q), ValueEquals, "older")
|
|
|
|
c.Check(heap.Pop(&q), ValueEquals, "old")
|
|
|
|
c.Check(heap.Pop(&q), ValueEquals, "new")
|
|
|
|
c.Check(heap.Pop(&q), ValueEquals, "newer")
|
|
|
|
c.Check(heap.Pop(&q), ValueEquals, "newest")
|
|
|
|
}
|