-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_test.go
67 lines (56 loc) · 1.15 KB
/
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
56
57
58
59
60
61
62
63
64
65
package gonuts
import (
"testing"
"rand"
"sort"
"fmt"
)
func generateRandomIntData(num int) Comparable {
data := make(sort.IntArray, num)
for i := 0; i < len(data); i++ {
data[i] = rand.Intn(num)
}
return data
}
func TestInsertionSort(t *testing.T) {
data := generateRandomIntData(1000)
InsertionSort(data)
if ! sort.IsSorted(data) {
t.Error("Not sorted")
}
}
func BenchmarkInsertionSort(b *testing.B) {
b.StopTimer()
fmt.Printf("running %d\n", b.N)
data := generateRandomIntData(b.N)
b.StartTimer()
InsertionSort(data)
}
func TestQuickSort(t *testing.T) {
data := generateRandomIntData(1000)
QuickSort(data)
if ! sort.IsSorted(data) {
t.Error("Not sorted")
}
}
func BenchmarkQuickSort(b *testing.B) {
b.StopTimer()
fmt.Printf("running %d\n", b.N)
data := generateRandomIntData(b.N)
b.StartTimer()
QuickSort(data)
}
func TestSelectionSort(t *testing.T) {
data := generateRandomIntData(1000)
SelectionSort(data)
if ! sort.IsSorted(data) {
t.Error("Not sorted")
}
}
func BenchmarkSelectionSort(b *testing.B) {
b.StopTimer()
fmt.Printf("running %d\n", b.N)
data := generateRandomIntData(b.N)
b.StartTimer()
SelectionSort(data)
}