-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
85 lines (65 loc) · 1.87 KB
/
main_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
package main
import (
"testing"
"./bhs"
"./bhs/algorithms"
)
func runTest(hasWhiteBoards bool, algo func(r bhs.Ring) (bhs.NodeID, uint64, uint64), t *testing.T) {
var size uint64 = 100
for i := bhs.NodeID(1); i < bhs.NodeID(size); i++ {
r := bhs.BuildRing(i, size, hasWhiteBoards)
if result, _, _ := algo(r); result != i {
t.Errorf("Expected %v, got %d", i, result)
}
}
}
func TestOptAvgTime(t *testing.T) {
runTest(false, algorithms.OptAvgTime, t)
}
func benchmarkOptAvgTime(i uint64, b *testing.B) {
r := bhs.BuildRing(bhs.NodeID(i-1), i, false)
for n := 0; n < b.N; n++ {
algorithms.OptAvgTime(r)
}
}
func BenchmarkOptAvgTime10000(b *testing.B) { benchmarkOptAvgTime(1000, b) }
func TestOptTime(t *testing.T) {
runTest(false, algorithms.OptTime, t)
}
func benchmarkOptTime(i uint64, b *testing.B) {
r := bhs.BuildRing(bhs.NodeID(i-1), i, false)
for n := 0; n < b.N; n++ {
algorithms.OptTime(r)
}
}
func BenchmarkOptTime10000(b *testing.B) { benchmarkOptTime(1000, b) }
func TestOptTeamSize(t *testing.T) {
runTest(true, algorithms.OptTeamSize, t)
}
func benchmarkOptTeamSize(i uint64, b *testing.B) {
r := bhs.BuildRing(bhs.NodeID(i-1), i, true)
for n := 0; n < b.N; n++ {
algorithms.OptTeamSize(r)
}
}
func BenchmarkOptTeamSize10000(b *testing.B) { benchmarkOptTeamSize(1000, b) }
func TestDivide(t *testing.T) {
runTest(true, algorithms.Divide, t)
}
func benchmarkDivide(i uint64, b *testing.B) {
r := bhs.BuildRing(bhs.NodeID(i-1), i, true)
for n := 0; n < b.N; n++ {
algorithms.Divide(r)
}
}
func BenchmarkDivide10000(b *testing.B) { benchmarkDivide(1000, b) }
func TestGroup(t *testing.T) {
runTest(false, algorithms.Group, t)
}
func benchmarkGroup(i uint64, b *testing.B) {
r := bhs.BuildRing(bhs.NodeID(i-1), i, true)
for n := 0; n < b.N; n++ {
algorithms.Group(r)
}
}
func BenchmarkGroup10000(b *testing.B) { benchmarkGroup(1000, b) }