-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdispatch_test.go
85 lines (71 loc) · 1.38 KB
/
dispatch_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 snd
import "testing"
func BenchmarkDispatchSerial(b *testing.B) {
sd := mksound()
inps := GetInputs(sd)
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
tc := uint64(n)
for _, inp := range inps {
inp.sd.Prepare(tc)
}
}
}
func TestDispatch(t *testing.T) {
sd := mksound()
inps := GetInputs(sd)
tc := uint64(1)
dp := new(Dispatcher)
// TODO better test than "does it hang?"
dp.Dispatch(tc, inps...)
}
func BenchmarkDispatch(b *testing.B) {
sd := mksound()
inps := GetInputs(sd)
dp := new(Dispatcher)
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
dp.Dispatch(uint64(n), inps...)
}
}
func TestGetInputs(t *testing.T) {
sd := mksound()
inps := GetInputs(sd)
if len(inps) <= 1 {
t.Fatal("getinps did not produce a result")
}
last := inps[0].wt
for i, inp := range inps {
if inp.wt > last {
t.Fatal("inputs are not sorted highest to lowest")
}
last = inp.wt
t.Log(i, inp)
}
}
func BenchmarkGetInputs(b *testing.B) {
sd := mksound()
var inps []*Input
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
inps = GetInputs(sd)
}
_ = inps
}
func TestByWTSlice(t *testing.T) {
sd := mksound()
inps := GetInputs(sd)
sl := ByWT(inps).Slice()
want := len(inps)
total := 0
for i, p := range sl {
total += len(p)
t.Log(i, len(p))
}
if total != want {
t.Fatalf("Have length %v, want %v", total, want)
}
}