-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathinsertion_test.go
51 lines (44 loc) · 1.54 KB
/
insertion_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
package insertion
import (
"github.com/stretchr/testify/assert"
"github.com/xiaomeng79/go-algorithm/algorithms/sort/testdata"
"github.com/xiaomeng79/go-algorithm/algorithms/sort/utils"
"testing"
)
func TestInsertionSort(t *testing.T) {
for _, v := range testdata.Values {
assert.Exactly(t, v.Sort, InsertionSort(v.Nosort), "no eq")
}
}
func TestInsertionSort3(t *testing.T) {
for _, v := range testdata.Values {
InsertionSort3(v.Nosort)
assert.Exactly(t, v.Sort, v.Nosort, "no eq")
}
}
func benchmarkInsertionSort(n int, b *testing.B) {
b.StopTimer()
list := utils.GetArrayOfSize(n)
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
InsertionSort(list)
}
}
func BenchmarkInsertionSort100(b *testing.B) { benchmarkInsertionSort(100, b) }
func BenchmarkInsertionSort1000(b *testing.B) { benchmarkInsertionSort(1000, b) }
func BenchmarkInsertionSort10000(b *testing.B) { benchmarkInsertionSort(10000, b) }
func BenchmarkInsertionSort100000(b *testing.B) { benchmarkInsertionSort(100000, b) }
func benchmarkInsertionSort3(n int, b *testing.B) {
b.StopTimer()
list := utils.GetArrayOfSize(n)
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
InsertionSort3(list)
}
}
func BenchmarkInsertionSort3_100(b *testing.B) { benchmarkInsertionSort3(100, b) }
func BenchmarkInsertionSort3_1000(b *testing.B) { benchmarkInsertionSort3(1000, b) }
func BenchmarkInsertionSort3_10000(b *testing.B) { benchmarkInsertionSort3(10000, b) }
func BenchmarkInsertionSort3_100000(b *testing.B) { benchmarkInsertionSort3(100000, b) }