forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heap_sort_test.go
46 lines (40 loc) · 1.04 KB
/
heap_sort_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
package heap
import (
"math"
"reflect"
"testing"
)
/*
TestSort tests solution(s) with the following signature and problem description:
func HeapSort(list []int) []int
Given a list of integers like {3,1,2}, return a sorted set like {1,2,3} using Heap Sort.
*/
func TestSort(t *testing.T) {
tests := []struct {
list []int
sorted []int
}{
{[]int{}, []int{}},
{[]int{1, 2}, []int{1, 2}},
{[]int{2, 1}, []int{1, 2}},
{[]int{1, 2, 3}, []int{1, 2, 3}},
{[]int{3, 2, 1}, []int{1, 2, 3}},
{[]int{1, 3, 2}, []int{1, 2, 3}},
{[]int{-1, 3, 2, 0, 4}, []int{-1, 0, 2, 3, 4}},
}
for i, test := range tests {
if got := Sort(test.list); !reflect.DeepEqual(got, test.sorted) {
t.Fatalf("Failed test case #%d. Want %v got %v", i, test.sorted, got)
}
}
}
func TestMinHeapImplementation(t *testing.T) {
heap := NewMinHeap()
if got := heap.Pop(); got != math.MinInt {
t.Fatalf("Failed test case. Want %v got %v", math.MinInt, got)
}
heap.Push(1)
if got := heap.Pop(); got != 1 {
t.Fatalf("Failed test case. Want %v got %v", 1, got)
}
}