-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstereo_test.go
76 lines (71 loc) · 1.85 KB
/
stereo_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
package transforms
import (
"testing"
"reflect"
"github.com/go-audio/audio"
)
func TestMonoToStereoF32Validation(t *testing.T) {
type args struct {
}
tests := []struct {
name string
buf *audio.Float32Buffer
wantErr bool
}{
{
name: "valid blank",
buf: &audio.Float32Buffer{Format: &audio.Format{NumChannels: 1}},
wantErr: false,
},
{
name: "nil format",
buf: &audio.Float32Buffer{},
wantErr: true,
},
{
name: "stereo",
buf: &audio.Float32Buffer{Format: &audio.Format{NumChannels: 2}},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := MonoToStereoF32(tt.buf); (err != nil) != tt.wantErr {
t.Errorf("MonoToStereoF32() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestMonoToStereoF32(t *testing.T) {
type args struct {
}
tests := []struct {
name string
buf *audio.Float32Buffer
stereoData []float32
wantErr bool
}{
{
name: "valid blank",
buf: &audio.Float32Buffer{
Format: &audio.Format{NumChannels: 1},
Data: []float32{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0},
},
stereoData: []float32{1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0, 9.0, 9.0, 10.0, 10.0, 11.0, 11.0, 12.0, 12.0},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := MonoToStereoF32(tt.buf); (err != nil) != tt.wantErr {
t.Errorf("MonoToStereoF32() error = %v, wantErr %v", err, tt.wantErr)
}
if tt.buf.Format.NumChannels != 2 {
t.Errorf("Expected the buffer channel numbers to be 2 got %d", tt.buf.Format.NumChannels)
}
if !reflect.DeepEqual(tt.buf.Data, tt.stereoData) {
t.Errorf("Expected the conversion to match, got %#v expected:\n%#v", tt.buf.Data, tt.stereoData)
}
})
}
}