-
Notifications
You must be signed in to change notification settings - Fork 9
/
poi_test.go
58 lines (52 loc) · 1012 Bytes
/
poi_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
53
54
55
56
57
58
package highlight
import (
"container/heap"
"reflect"
"testing"
)
func TestPOIHeap(t *testing.T) {
pois := []poi{
{i: 100},
{i: 15, start: true},
{i: 15},
{i: 10},
{i: 5},
}
hp := &poiHeap{}
for _, p := range pois {
heap.Push(hp, p)
}
for i, p := range pois {
h := hp.Peek()
if !reflect.DeepEqual(p, h) {
t.Errorf("%d. Peek() expected %+v = %+v", i, p, h)
}
h = heap.Pop(hp).(poi)
if !reflect.DeepEqual(p, h) {
t.Errorf("%d. Pop() expected %+v = %+v", i, p, h)
}
}
}
func TestPOIHeapRemove(t *testing.T) {
h := &highlight{}
pois := []poi{
{i: 100},
{i: 10, highlight: h},
{i: 5},
}
hp := &poiHeap{}
for _, p := range pois {
heap.Push(hp, p)
}
if eq := reflect.DeepEqual([]poi(*hp), pois); !eq {
t.Fatalf("expected heap %+v to equal %+v", *hp, pois)
}
hp.Remove(poi{highlight: h})
poisWant := []poi{
{i: 100},
{i: 5},
}
if eq := reflect.DeepEqual([]poi(*hp), poisWant); !eq {
t.Fatalf("expected heap %+v to equal %+v", *hp, poisWant)
}
}