-
Notifications
You must be signed in to change notification settings - Fork 0
/
heaps_test.go
52 lines (49 loc) · 1.13 KB
/
heaps_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
package gaul
import (
"github.com/stretchr/testify/assert"
"sort"
"testing"
)
func TestPointHeap_InsertPop(t *testing.T) {
assert := assert.New(t)
maxHeap := NewMaxPointHeap()
minHeap := NewMinPointHeap()
metrics := []float64{5, 3, 2, 7, 20}
for _, m := range metrics {
p := MetricPoint{
Metric: m,
Index: 0,
Point: Point{X: 0, Y: 0},
}
maxHeap.Push(p)
minHeap.Push(p)
}
n := len(metrics)
sort.Float64s(metrics)
for i, m := range metrics {
assert.Equal(m, minHeap.Pop().Metric)
assert.Equal(metrics[n-i-1], maxHeap.Pop().Metric)
}
}
func TestPointHeap_Report(t *testing.T) {
assert := assert.New(t)
maxHeap := NewMaxPointHeap()
minHeap := NewMinPointHeap()
metrics := []float64{5, 3, 2, 7, 20}
for _, m := range metrics {
p := MetricPoint{
Metric: m,
Index: 0,
Point: Point{X: 0, Y: 0},
}
maxHeap.Push(p)
minHeap.Push(p)
}
sort.Float64s(metrics)
minHeapReport := minHeap.Report()
maxHeapReportReversed := maxHeap.ReportReversed()
for i := range minHeapReport {
assert.Equal(metrics[i], minHeapReport[i].Metric)
assert.Equal(minHeapReport[i].Metric, maxHeapReportReversed[i].Metric)
}
}