This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
options_test.go
237 lines (201 loc) · 6.93 KB
/
options_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package waveform
import (
"fmt"
"image/color"
"testing"
)
// TestOptionsError verifies that the format of OptionsError.Error does
// not change.
func TestOptionsError(t *testing.T) {
var tests = []struct {
option string
reason string
}{
{"foo", "bar"},
{"baz", "qux"},
{"one", "two"},
}
for _, test := range tests {
// Generate options error
opErr := &OptionsError{
Option: test.option,
Reason: test.reason,
}
// Verify correct format
if opErr.Error() != fmt.Sprintf("%s: %s", test.option, test.reason) {
t.Fatalf("unexpected Error string: %v", opErr.Error())
}
}
}
// TestOptionBGColorFunctionOK verifies that BGColorFunction returns no error
// with acceptable input.
func TestOptionBGColorFunctionOK(t *testing.T) {
testWaveformOptionFunc(t, BGColorFunction(SolidColor(color.Black)), nil)
}
// TestOptionBGColorFunctionNil verifies that BGColorFunction does not accept
// a nil ColorReduceFunc.
func TestOptionBGColorFunctionNil(t *testing.T) {
testWaveformOptionFunc(t, BGColorFunction(nil), errBGColorFunctionNil)
}
// TestOptionFGColorFunctionOK verifies that FGColorFunction returns no error
// with acceptable input.
func TestOptionFGColorFunctionOK(t *testing.T) {
testWaveformOptionFunc(t, FGColorFunction(SolidColor(color.Black)), nil)
}
// TestOptionFGColorFunctionNil verifies that FGColorFunction does not accept
// a nil ColorReduceFunc.
func TestOptionFGColorFunctionNil(t *testing.T) {
testWaveformOptionFunc(t, FGColorFunction(nil), errFGColorFunctionNil)
}
// TestOptionSampleFunctionOK verifies that SampleFunction returns no error
// with acceptable input.
func TestOptionSampleFunctionOK(t *testing.T) {
testWaveformOptionFunc(t, SampleFunction(RMSF64Samples), nil)
}
// TestOptionSampleFunctionNil verifies that SampleFunction does not accept
// a nil SampleReduceFunc.
func TestOptionSampleFunctionNil(t *testing.T) {
testWaveformOptionFunc(t, SampleFunction(nil), errSampleFunctionNil)
}
// TestOptionResolutionOK verifies that Resolution returns no error with acceptable input.
func TestOptionResolutionOK(t *testing.T) {
testWaveformOptionFunc(t, Resolution(1), nil)
}
// TestOptionResolutionZero verifies that Resolution does not accept integer 0.
func TestOptionResolutionZero(t *testing.T) {
testWaveformOptionFunc(t, Resolution(0), errResolutionZero)
}
// TestOptionScaleOK verifies that Scale returns no error with acceptable input.
func TestOptionScaleOK(t *testing.T) {
testWaveformOptionFunc(t, Scale(1, 1), nil)
}
// TestOptionScaleXZero verifies that Scale does not accept an X value integer 0.
func TestOptionScaleXZero(t *testing.T) {
testWaveformOptionFunc(t, Scale(0, 1), errScaleXZero)
}
// TestOptionScaleYZero verifies that Scale does not accept an Y value integer 0.
func TestOptionScaleYZero(t *testing.T) {
testWaveformOptionFunc(t, Scale(1, 0), errScaleYZero)
}
// TestOptionScaleClippingOK verifies that ScaleClipping returns no error.
func TestOptionScaleClippingOK(t *testing.T) {
testWaveformOptionFunc(t, ScaleClipping(), nil)
}
// TestOptionSharpnessOK verifies that Sharpness returns no error.
func TestOptionSharpnessOK(t *testing.T) {
testWaveformOptionFunc(t, Sharpness(0), nil)
}
// TestWaveformSetOptionsNil verifies that Waveform.SetOptions ignores any
// nil OptionsFunc arguments.
func TestWaveformSetOptionsNil(t *testing.T) {
testWaveformOptionFunc(t, nil, nil)
}
// TestWaveformSetBGColorFunction verifies that the Waveform.SetBGColorFunction
// method properly modifies struct members.
func TestWaveformSetBGColorFunction(t *testing.T) {
// Generate empty Waveform, apply parameters
w := &Waveform{}
if err := w.SetBGColorFunction(SolidColor(color.Black)); err != nil {
t.Fatal(err)
}
// Validate that struct members are set properly
if w.bgColorFn == nil {
t.Fatalf("SetBGColorFunction failed, nil function member")
}
}
// TestWaveformSetFGColorFunction verifies that the Waveform.SetFGColorFunction
// method properly modifies struct members.
func TestWaveformSetFGColorFunction(t *testing.T) {
// Generate empty Waveform, apply parameters
w := &Waveform{}
if err := w.SetFGColorFunction(SolidColor(color.Black)); err != nil {
t.Fatal(err)
}
// Validate that struct members are set properly
if w.fgColorFn == nil {
t.Fatalf("SetFGColorFunction failed, nil function member")
}
}
// TestWaveformSetSampleFunction verifies that the Waveform.SetSampleFunction
// method properly modifies struct members.
func TestWaveformSetSampleFunction(t *testing.T) {
// Generate empty Waveform, apply parameters
w := &Waveform{}
if err := w.SetSampleFunction(RMSF64Samples); err != nil {
t.Fatal(err)
}
// Validate that struct members are set properly
if w.sampleFn == nil {
t.Fatalf("SetSampleFunction failed, nil function member")
}
}
// TestWaveformSetResolution verifies that the Waveform.SetResolution method properly
// modifies struct members.
func TestWaveformSetResolution(t *testing.T) {
// Predefined test values
res := uint(1)
// Generate empty Waveform, apply parameters
w := &Waveform{}
if err := w.SetResolution(res); err != nil {
t.Fatal(err)
}
// Validate that struct members are set properly
if w.resolution != res {
t.Fatalf("unexpected resolution: %v != %v", w.resolution, res)
}
}
// TestWaveformSetScale verifies that the Waveform.SetScale method properly
// modifies struct members.
func TestWaveformSetScale(t *testing.T) {
// Predefined test values
x := uint(1)
y := uint(1)
// Generate empty Waveform, apply parameters
w := &Waveform{}
if err := w.SetScale(x, y); err != nil {
t.Fatal(err)
}
// Validate that struct members are set properly
if w.scaleX != x {
t.Fatalf("unexpected scale X: %v != %v", w.scaleX, x)
}
if w.scaleY != y {
t.Fatalf("unexpected scale Y: %v != %v", w.scaleY, y)
}
}
// TestWaveformSetScaleClipping verifies that the Waveform.SetScaleClipping method properly
// modifies struct members.
func TestWaveformSetScaleClipping(t *testing.T) {
// Generate empty Waveform, apply function
w := &Waveform{}
if err := w.SetScaleClipping(); err != nil {
t.Fatal(err)
}
// Validate that struct members are set properly
if !w.scaleClipping {
t.Fatalf("SetScaleClipping failed, false scaleClipping member")
}
}
// TestWaveformSetSharpness verifies that the Waveform.SetSharpness method properly
// modifies struct members.
func TestWaveformSetSharpness(t *testing.T) {
// Predefined test values
sharpness := uint(1)
// Generate empty Waveform, apply parameters
w := &Waveform{}
if err := w.SetSharpness(sharpness); err != nil {
t.Fatal(err)
}
// Validate that struct members are set properly
if w.sharpness != sharpness {
t.Fatalf("unexpected sharpness: %v != %v", w.sharpness, sharpness)
}
}
// testWaveformOptionFunc is a test helper which verifies that applying the
// input OptionsFunc to a new Waveform struct generates the appropriate
// error output.
func testWaveformOptionFunc(t *testing.T, fn OptionsFunc, err error) {
if _, wErr := New(nil, fn); wErr != err {
t.Fatalf("unexpected error: %v != %v", wErr, err)
}
}