-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice_test.go
More file actions
71 lines (66 loc) · 1.69 KB
/
Copy pathvoice_test.go
File metadata and controls
71 lines (66 loc) · 1.69 KB
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
package ultrastar
import (
"testing"
"time"
)
func TestVoice_LastNote(t *testing.T) {
last := Note{NoteTypeRegular, 120, 40, 0, ""}
v := &Voice{Notes: []Note{
last,
{NoteTypeEndOfPhrase, 140, 0, 0, ""},
}}
actual, found := v.LastNote()
if !found {
t.Errorf("v.LastNote() = _, false, expected true")
}
if actual != last {
t.Errorf("v.LastNote() = %q, expected %q", actual, last)
}
}
func TestVoice_Duration(t *testing.T) {
v := &Voice{Notes: []Note{
{NoteTypeRegular, 120, 20, 0, "text"}},
}
expected := 1*time.Minute + 10*time.Second
actual := v.Duration(120)
if actual != expected {
t.Errorf("ns.Duration() = %s, expected %s", actual, expected)
}
}
func TestVoice_IsEmpty(t *testing.T) {
tests := map[string]struct {
Voice
empty bool
}{
"empty": {Voice: Voice{}, empty: true},
"end of phrase": {Voice: Voice{Notes: []Note{
{NoteTypeEndOfPhrase, 120, 0, 0, ""},
}}, empty: true},
"not empty": {Voice: Voice{Notes: []Note{
{NoteTypeRegular, 120, 0, 0, ""},
}}, empty: false},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if got := tt.Voice.IsEmpty(); got != tt.empty {
t.Errorf("v.IsEmpty() = %t, expected %t", got, tt.empty)
}
})
}
}
func TestVoice_FitBPM(t *testing.T) {
v := &Voice{Notes: []Note{
{NoteTypeRegular, 4, 3, 0, ""},
{NoteTypeRegular, 8, 1, 0, ""},
{NoteTypeRegular, 15, 4, 0, ""},
{NoteTypeRegular, 28, 10, 0, ""},
{NoteTypeRegular, 40, 6, 0, ""},
{NoteTypeRegular, 56, 4, 0, ""},
}}
oldDuration := v.Duration(15)
v.ScaleBPM(15, 30)
newDuration := v.Duration(30)
if oldDuration != newDuration {
t.Errorf("ns.Duration() changed from %s to %s, expected to stay the same", oldDuration, newDuration)
}
}