-
Notifications
You must be signed in to change notification settings - Fork 50
/
heap_test.go
57 lines (49 loc) · 1.23 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package stl4go
import (
"testing"
)
func TestMakeMinHeap(t *testing.T) {
data := []int{5, 4, 3, 2, 1}
expectFalse(t, IsMinHeap(data))
MakeMinHeap(data)
expectTrue(t, IsMinHeap(data))
}
func TestIsMinHeap(t *testing.T) {
heap := []int{}
expectTrue(t, IsMinHeap(heap))
heap = append(heap, 1)
expectTrue(t, IsMinHeap(heap))
}
func TestMakeHeapFunc(t *testing.T) {
data := []int{1, 2, 3, 4, 5}
expectFalse(t, IsHeapFunc(data, Greater[int]))
MakeHeapFunc(data, Greater[int])
expectTrue(t, IsHeapFunc(data, Greater[int]))
}
func Test_MinHeap_PushPop(t *testing.T) {
heap := []int{}
PushMinHeap(&heap, 1)
expectEq(t, PopMinHeap(&heap), 1)
expectTrue(t, IsMinHeap(heap))
}
func Test_HeapFunc_PushPop(t *testing.T) {
heap := []int{}
cmp := Greater[int]
PushHeapFunc(&heap, 1, cmp)
expectTrue(t, IsHeapFunc(heap, cmp))
expectEq(t, PopHeapFunc(&heap, cmp), 1)
expectTrue(t, IsHeapFunc(heap, cmp))
}
func Test_MinHeap_Remove(t *testing.T) {
heap := []int{5, 4, 3, 2, 1}
MakeMinHeap(heap)
RemoveMinHeap(&heap, 1)
expectTrue(t, IsMinHeap(heap))
}
func Test_HeapFunc_Remove(t *testing.T) {
heap := []int{1, 2, 3, 4, 5}
cmp := Greater[int]
MakeHeapFunc(heap, cmp)
RemoveHeapFunc(&heap, 1, cmp)
expectTrue(t, IsHeapFunc(heap, cmp))
}