-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
75 lines (72 loc) · 1.65 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
71
72
73
74
75
package main
import (
"testing"
"time"
)
func TestCalculateBeats(t *testing.T) {
tests := []struct {
name string
elapsed time.Duration
bpm float64
beatsPerBar int
expectedBeat int
expectedBar int
expectedTotal int
}{
{
name: "Test 1",
elapsed: time.Duration(0),
bpm: 120.0,
beatsPerBar: 4,
expectedBeat: 0,
expectedBar: 0,
expectedTotal: 0,
},
{
name: "Test 2",
elapsed: time.Duration(time.Minute),
bpm: 60.0,
beatsPerBar: 4,
expectedBeat: 0,
expectedBar: 15,
expectedTotal: 60,
},
{
name: "Test 3",
elapsed: time.Duration(time.Second * 30),
bpm: 120.0,
beatsPerBar: 4,
expectedBeat: 0,
expectedBar: 15,
expectedTotal: 60,
},
{
name: "Test 4",
elapsed: time.Duration(time.Second * 15),
bpm: 120.0,
beatsPerBar: 4,
expectedBeat: 2,
expectedBar: 7,
expectedTotal: 30,
},
{
name: "Test 5",
elapsed: time.Duration(time.Second * 75),
bpm: 120.0,
beatsPerBar: 4,
expectedBeat: 2,
expectedBar: 37,
expectedTotal: 150,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
beatNo, barNo, totalNo := calculateBeats(tt.elapsed, tt.bpm, tt.beatsPerBar)
if beatNo != tt.expectedBeat || barNo != tt.expectedBar || totalNo != tt.expectedTotal {
t.Errorf("calculateBeats(%v, %v, %v) = %v, %v, %v; want %v, %v, %v",
tt.elapsed, tt.bpm, tt.beatsPerBar, beatNo, barNo, totalNo,
tt.expectedBeat, tt.expectedBar, tt.expectedTotal)
}
})
}
}