-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal_test.go
56 lines (46 loc) · 865 Bytes
/
signal_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
package signal
import (
"testing"
)
func TestSample(t *testing.T) {
const n = 256
a := make(Discrete, n)
b := make(Discrete, n)
a.Sample(SineFunc, 1/n, 0)
b.Sample(a.At, 1/n, 0)
for i := range a {
if a[i] != b[i] {
t.Fail()
}
}
if t.Failed() {
for i := range a {
t.Logf("%v: a[%.4f] b[%.4f]\n", i, a[i], b[i])
}
}
}
var resf float64
func BenchmarkDiscreteInterp(b *testing.B) {
sig := Sine()
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
resf = sig.Interp(float64(n) / float64(len(sig)))
}
}
func BenchmarkDiscreteAt(b *testing.B) {
sig := Sine()
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
resf = sig.At(float64(n) / float64(len(sig)))
}
}
func BenchmarkDiscreteIndex(b *testing.B) {
sig := Sine()
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
resf = sig.Index(n)
}
}