-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllist_test.go
58 lines (48 loc) · 1.28 KB
/
llist_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
package llist
import (
"testing"
"github.com/stretchr/testify/assert"
)
var savedSum int
func TestAdd(t *testing.T) {
ll := List{}
ll.Insert(3)
ll.Insert(1)
ll.Insert(2)
assert.Equal(t, "1 2 3 ", ll.String())
}
func TestSum(t *testing.T) {
ll := List{}
ll.Insert(3)
ll.Insert(1)
ll.Insert(2)
assert.Equal(t, 6, ll.Sum())
}
func benchmarkSum(num int, b *testing.B) {
ll := List{}
ll.Fill(num)
b.ResetTimer()
for i := 0; i < b.N; i++ {
savedSum = ll.Sum()
}
}
func benchmarkSumV(num int, b *testing.B) {
v := make([]int, num, num)
fillV(v)
b.ResetTimer()
for i := 0; i < b.N; i++ {
savedSum = sumV(v)
}
}
// STARTBENCH OMIT
func BenchmarkSumV10(b *testing.B) { benchmarkSumV(10, b) }
func BenchmarkSumV100(b *testing.B) { benchmarkSumV(100, b) }
func BenchmarkSumV1000(b *testing.B) { benchmarkSumV(1000, b) }
func BenchmarkSumV10000(b *testing.B) { benchmarkSumV(10000, b) }
func BenchmarkSumV100000(b *testing.B) { benchmarkSumV(100000, b) }
// ENDBENCH OMIT
func BenchmarkSum10(b *testing.B) { benchmarkSum(10, b) }
func BenchmarkSum100(b *testing.B) { benchmarkSum(100, b) }
func BenchmarkSum1000(b *testing.B) { benchmarkSum(1000, b) }
func BenchmarkSum10000(b *testing.B) { benchmarkSum(10000, b) }
func BenchmarkSum100000(b *testing.B) { benchmarkSum(100000, b) }