-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathsort_test.go
55 lines (46 loc) · 923 Bytes
/
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
47
48
49
50
51
52
53
54
55
package main
import (
"sort"
"testing"
utils "github.com/0xAX/go-algorithms"
)
var funcs = []struct {
name string
f Sort
}{
{"shell", ShellSort},
{"selection", SelectionSort},
{"oddeven", OddEvenSort},
{"insertion", InsertionSort},
{"heap", HeapSort},
{"gnome", GnomeSort},
{"counting", CountingSort},
{"comb", CombSort},
{"cocktail", CocktailSort},
{"bubble", BubbleSort},
{"bead", BeadSort},
}
func TestSort(t *testing.T) {
for _, tt := range funcs {
t.Run(tt.name, func(t *testing.T) {
arr := utils.RandArray(10)
tt.f(arr)
if !sort.IntsAreSorted(arr) {
t.Errorf("%v is not sorted", arr)
}
})
}
}
func BenchmarkSort(b *testing.B) {
for _, tt := range funcs {
arrs := make([][]int, 0)
for n := 0; n < b.N; n++ {
arrs = append(arrs, utils.RandArray(10))
}
b.Run(tt.name, func(b *testing.B) {
for n := 0; n < len(arrs); n++ {
tt.f(arrs[n])
}
})
}
}