-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigo_test.go
142 lines (105 loc) · 3.01 KB
/
bigo_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package gosort_test
import (
"testing"
"time"
"github.com/sevagh/go-sort"
"github.com/sevagh/go-sort/bigO"
)
func TestBigOBitonicSort(t *testing.T) {
sizes := []int{10, 100, 1000, 10000, 100000, 10000000}
times := []float64{}
for _, size := range sizes {
timeTaken := 0.0
nums := RandomInt(size)
start := time.Now()
gosort.BitonicSort(nums)
timeTaken += time.Since(start).Seconds()
times = append(times, timeTaken)
}
complexity, _ := bigO.Estimate(sizes, times)
t.Logf(complexity.String())
}
func TestBigOTimSort1(t *testing.T) {
sizes := []int{10, 100, 1000, 10000, 100000, 10000000}
times := []float64{}
for _, size := range sizes {
timeTaken := 0.0
nums := RandomInt(size)
start := time.Now()
gosort.TimSort1(nums)
timeTaken += time.Since(start).Seconds()
times = append(times, timeTaken)
}
complexity, _ := bigO.Estimate(sizes, times)
t.Logf(complexity.String())
}
func TestBigOTimSort2(t *testing.T) {
sizes := []int{10, 100, 1000, 10000, 100000, 10000000}
times := []float64{}
for _, size := range sizes {
timeTaken := 0.0
nums := RandomInt(size)
start := time.Now()
gosort.TimSort2(nums)
timeTaken += time.Since(start).Seconds()
times = append(times, timeTaken)
}
complexity, _ := bigO.Estimate(sizes, times)
t.Logf(complexity.String())
}
func TestBigOQuickSort1WorstCase(t *testing.T) {
sizes := []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192}
times := []float64{}
for _, size := range sizes {
timeTaken := 0.0
nums := DescendingInt(size)
start := time.Now()
gosort.QuickSort1(nums)
timeTaken += time.Since(start).Seconds()
times = append(times, timeTaken)
}
complexity, _ := bigO.Estimate(sizes, times)
t.Logf(complexity.String())
}
func TestBigOInsertionSortAscending(t *testing.T) {
sizes := []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192}
times := []float64{}
for _, size := range sizes {
timeTaken := 0.0
nums := AscendingInt(size)
start := time.Now()
gosort.QuickSort1(nums)
timeTaken += time.Since(start).Seconds()
times = append(times, timeTaken)
}
complexity, _ := bigO.Estimate(sizes, times)
t.Logf(complexity.String())
}
func TestBigOInsertionSortRandom(t *testing.T) {
sizes := []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192}
times := []float64{}
for _, size := range sizes {
timeTaken := 0.0
nums := RandomInt(size)
start := time.Now()
gosort.QuickSort1(nums)
timeTaken += time.Since(start).Seconds()
times = append(times, timeTaken)
}
complexity, _ := bigO.Estimate(sizes, times)
t.Logf(complexity.String())
}
func TestBigOPdqSort1WorstCaseQuickSort(t *testing.T) {
sizes := []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192}
times := []float64{}
for _, size := range sizes {
timeTaken := 0.0
nums := DescendingInt(size)
start := time.Now()
gosort.PdqSort1(nums)
timeTaken += time.Since(start).Seconds()
times = append(times, timeTaken)
}
complexity, _ := bigO.Estimate(sizes, times)
t.Logf(complexity.String())
}