-
Notifications
You must be signed in to change notification settings - Fork 0
/
heap_test.go
34 lines (28 loc) · 687 Bytes
/
heap_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
package sampling_test
import (
"container/heap"
"testing"
"github.com/epicchewy/sampling"
"github.com/stretchr/testify/assert"
)
func TestHeapPeek(t *testing.T) {
h := &sampling.MinHeap{
&sampling.Node{Key: 0.3, Obj: 3},
&sampling.Node{Key: 0.6, Obj: 4},
&sampling.Node{Key: 0.9, Obj: 5},
}
heap.Init(h)
heap.Push(h, &sampling.Node{Key: 0.1, Obj: 1})
top := h.Peek().(*sampling.Node)
assert.Equal(t, top.Key, 0.1)
}
func TestHeapPop(t *testing.T) {
h := &sampling.MinHeap{
&sampling.Node{Key: 0.3, Obj: 3},
&sampling.Node{Key: 0.6, Obj: 4},
&sampling.Node{Key: 0.9, Obj: 5},
}
heap.Init(h)
pop := h.Pop().(*sampling.Node)
assert.Equal(t, pop.Key, 0.3)
}