-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergesort_test.go
82 lines (71 loc) · 1.93 KB
/
mergesort_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package sorting
import (
"fmt"
"testing"
)
func TestMergeSort_merge(t *testing.T) {
left := []int32 {1}
right := []int32 {2}
result := merge(left, right)
if !isSorted(result) {
fmt.Println(result)
t.Error("merge fails with an sorted array.")
}
}
func TestMergeSort_merge_moreEntries(t *testing.T) {
left := []int32 {1, 2, 3}
right := []int32 {2, 5, 6}
result := merge(left, right)
if !isSorted(result) {
fmt.Println(result)
t.Error("merge fails with an sorted array.")
}
}
func TestMergeSort_10e1(t *testing.T) {
var integers []int32
for i:=1; i<4; i++ {
filename := fmt.Sprintf(FILENAME_TMPL, 1, i)
integers, _ = readFile(filename)
mergesort(integers)
if !isSorted(integers) {
t.Error("mergesort fails with an sorted array.")
}
}
}
func TestMergeSort_10e2(t *testing.T) {
var integers []int32
for i:=1; i<4; i++ {
filename := fmt.Sprintf(FILENAME_TMPL, 2, i)
integers, _ = readFile(filename)
mergesort(integers)
if !isSorted(integers) {
t.Error("mergesort fails with an sorted array.")
}
}
}
func TestMergeSort_10e3(t *testing.T) {
var integers []int32
for i:=1; i<4; i++ {
filename := fmt.Sprintf(FILENAME_TMPL, 3, i)
integers, _ = readFile(filename)
mergesort(integers)
if !isSorted(integers) {
t.Error("mergesort fails with an sorted array.")
}
}
}
func BenchmarkMergeSort_10e1(b *testing.B) {
benchmark_algorithm(mergesort, 1, b)
}
func BenchmarkMergeSort_10e2(b *testing.B) {
benchmark_algorithm(mergesort, 2, b)
}
func BenchmarkMergeSort_10e3(b *testing.B) {
benchmark_algorithm(mergesort, 3, b)
}
func BenchmarkMergeSort_10e4(b *testing.B) {
benchmark_algorithm(mergesort, 4, b)
}
func BenchmarkMergeSort_10e5(b *testing.B) {
benchmark_algorithm(mergesort, 5, b)
}