-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
70 lines (65 loc) · 1.24 KB
/
main_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
package main
import "testing"
func TestCalculateDelay(t *testing.T) {
cases := []struct {
name string
fps int
want int
wantErr bool
}{
{
name: "returns correct value with 1 fps",
fps: 1,
want: 100,
wantErr: false,
},
{
name: "returns correct value with 7 fps",
fps: 7,
want: 14,
wantErr: false,
},
{
name: "returns correct value with 10 fps",
fps: 10,
want: 10,
wantErr: false,
},
{
name: "returns correct value with 10 fps",
fps: 30,
want: 3,
wantErr: false,
},
{
name: "fails with negative fps",
fps: -10,
want: 0,
wantErr: true,
},
{
name: "fails with 0 fps",
fps: 0,
want: 0,
wantErr: true,
},
{
name: "fails with fps greater than maximum allowed",
fps: 35,
want: 0,
wantErr: true,
},
}
for _, c := range cases {
t.Run(c.name, func(s *testing.T) {
got, err := calculateDelay(c.fps)
if c.want != got {
t.Errorf("calculateDelay(%d) = %d; want %d", c.fps, got, c.want)
}
gotErr := err != nil
if c.wantErr != gotErr {
t.Errorf("expected error with calculateDelay(%d) = %v; got error = %v", c.fps, c.wantErr, gotErr)
}
})
}
}