Skip to content

Commit ac088a9

Browse files
lhauspietheodesp
authored andcommitted
feat(fibonacci heap): add some tests (#34)
1 parent 693fd73 commit ac088a9

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

fibonacci/heap_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package fibonacci
2+
3+
import (
4+
"sort"
5+
"testing"
6+
7+
"github.com/theodesp/go-heaps"
8+
)
9+
10+
func TestFibonacciHeapInteger(t *testing.T) {
11+
heap := &FibonacciHeap{}
12+
13+
numbers := []int{4, 3, 2, 5}
14+
15+
for _, number := range numbers {
16+
heap.Insert(Int(number))
17+
}
18+
19+
sort.Ints(numbers)
20+
21+
for _, number := range numbers {
22+
i := heap.DeleteMin().(go_heaps.Integer)
23+
if Int(number) != i {
24+
t.Fail()
25+
}
26+
}
27+
}
28+
29+
func TestFibonacciHeapString(t *testing.T) {
30+
heap := &FibonacciHeap{}
31+
32+
strs := []string{"a", "ccc", "bb", "d"}
33+
34+
for _, str := range strs {
35+
heap.Insert(Str(str))
36+
}
37+
38+
sort.Strings(strs)
39+
40+
for _, str := range strs {
41+
if Str(str) != heap.DeleteMin().(go_heaps.String) {
42+
t.Fail()
43+
}
44+
}
45+
}
46+
47+
func TestFibonacciHeap(t *testing.T) {
48+
heap := &FibonacciHeap{}
49+
50+
numbers := []int{4, 3, -1, 5, 9}
51+
52+
for _, number := range numbers {
53+
heap.Insert(Int(number))
54+
}
55+
56+
if heap.FindMin() != Int(-1) {
57+
t.Fail()
58+
}
59+
60+
heap.Clear()
61+
if heap.FindMin() != nil {
62+
t.Fail()
63+
}
64+
}
65+
66+
func Int(value int) go_heaps.Integer {
67+
return go_heaps.Integer(value)
68+
}
69+
70+
func Str(value string) go_heaps.String {
71+
return go_heaps.String(value)
72+
}

0 commit comments

Comments
 (0)