-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpm_test.go
65 lines (61 loc) · 1.38 KB
/
bpm_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
package ultrastar
import (
"testing"
"time"
)
func TestBPM_IsValid(t *testing.T) {
cases := map[string]struct {
bpm BPM
expected bool
}{
"zero": {0, false},
"negative": {-1, false},
"positive": {120, true},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
actual := c.bpm.IsValid()
if actual != c.expected {
t.Errorf("BPM(%f).IsValid() = %t, expected %t", c.bpm, actual, c.expected)
}
})
}
}
func TestBPM_Beats(t *testing.T) {
cases := map[string]struct {
bpm BPM
duration time.Duration
expected Beat
}{
"zero": {120, 0, 0},
"regular": {60, 2 * time.Minute, 120},
"negative": {-60, -30 * time.Second, 30},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
actual := c.bpm.Beats(c.duration)
if actual != c.expected {
t.Errorf("BPM(%f).Beats(%s) = %d, expected %d", c.bpm, c.duration, actual, c.expected)
}
})
}
}
func TestBPM_Duration(t *testing.T) {
cases := map[string]struct {
bpm BPM
beats Beat
expected time.Duration
}{
"zero": {120, 0, 0},
"regular": {60, 120, 2 * time.Minute},
"negative": {-60, 30, -30 * time.Second},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
actual := c.bpm.Duration(c.beats)
if actual != c.expected {
t.Errorf("BPM(%f).Duration(%d) = %s, expected %s", c.bpm, c.beats, actual, c.expected)
}
})
}
}