-
Notifications
You must be signed in to change notification settings - Fork 1
/
waveform_test.go
90 lines (81 loc) · 1.47 KB
/
waveform_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
package waveform
import (
"fmt"
"image/color"
"image/png"
"math/rand"
"os"
"testing"
)
type dummyWave []float32
func newDummyWave() dummyWave {
w := make([]float32, 48000)
src := rand.NewSource(0)
rnd := rand.New(src)
for n := 0; n < len(w); n++ {
w[n] = rnd.Float32()
}
return w
}
func (dw dummyWave) Len() uint64 {
return uint64(len(dw))
}
func (dw dummyWave) Rate() uint32 {
return 48000
}
func (dw dummyWave) Chans() uint16 {
return 1
}
func (dw dummyWave) At(ch uint, offset uint64) (float32, error) {
if ch != 0 {
return 0.0, fmt.Errorf("invalid channel")
}
return dw[offset], nil
}
func TestMax(t *testing.T) {
dw := newDummyWave()
im := MinMax(dw, &Options{
Width: 1800,
Front: &color.NRGBA{
R: 50,
G: 100,
B: 200,
A: 255,
},
Back: &color.NRGBA{
A: 0,
},
})
w, err := os.Create("test-max.png")
if err != nil {
t.Fatalf("create failed: %v", err)
}
err = png.Encode(w, im)
if err != nil {
t.Fatalf("png.Encode failed: %v", err)
}
}
func TestMaxHalf(t *testing.T) {
dw := newDummyWave()
im := MinMax(dw, &Options{
Width: 1800,
Half: true,
Front: &color.NRGBA{
R: 10,
G: 50,
B: 250,
A: 255,
},
Back: &color.NRGBA{
A: 0,
},
})
w, err := os.Create("test-max-half.png")
if err != nil {
t.Fatalf("create failed: %v", err)
}
err = png.Encode(w, im)
if err != nil {
t.Fatalf("png.Encode failed: %v", err)
}
}