-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathheapSort_test.go
49 lines (43 loc) · 895 Bytes
/
heapSort_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
package sort
import (
"github.com/shady831213/algorithms/heap"
"testing"
)
func Test_heapSort(t *testing.T) {
testSort(t, heapSort)
}
func Benchmark_heapSort(b *testing.B) {
benchmarkSort(b, heapSort)
}
func Test_heapSort2(t *testing.T) {
testSort(t, heapSort2)
}
func Benchmark_heapSort2(b *testing.B) {
benchmarkSort(b, heapSort2)
}
func Test_heapPopAndAppend(t *testing.T) {
h := heap.NewHeapIntArray([]int{3, 2, 10, 1, 7})
max := h.Pop().(int)
if max != 10 {
t.Log("max value should be 10" + " but get " + string(max))
t.Fail()
}
h.Append(8)
h.Append(4)
max = h.Pop().(int)
if max != 8 {
t.Log("max value should be 8"+" but get ", max)
t.Fail()
}
h.Append(1)
max = h.Pop().(int)
if max != 7 {
t.Log("max value should be 7"+" but get ", max)
t.Fail()
}
max = h.Pop().(int)
if max != 4 {
t.Log("max value should be 4"+" but get ", max)
t.Fail()
}
}