-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpitch_test.go
106 lines (99 loc) · 2.15 KB
/
pitch_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
package ultrastar
import (
"fmt"
"testing"
)
func TestPitch_NoteName(t *testing.T) {
cases := map[string]struct {
pitch Pitch
expected string
}{
"C4": {0, "C"},
"C#4": {1, "C#"},
"B3": {-1, "B"},
"C5": {12, "C"},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
actual := c.pitch.NoteName()
if actual != c.expected {
t.Errorf("%q.NoteName() = %q, expected %q", c.pitch, actual, c.expected)
}
})
}
}
func ExamplePitch_NoteName() {
fmt.Println(NamedPitch("Gb4").NoteName())
// Output: F#
}
func TestPitch_Octave(t *testing.T) {
cases := map[string]struct {
pitch Pitch
expected int
}{
"C4": {0, 4},
"B4": {11, 4},
"C5": {12, 5},
"C#5": {13, 5},
"B3": {-1, 3},
"C#3": {-11, 3},
"C2": {-12, 2},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
actual := c.pitch.Octave()
if actual != c.expected {
t.Errorf("%q.Octave() = %d, expected %d", c.pitch, actual, c.expected)
}
})
}
}
func ExamplePitch_Octave() {
fmt.Println(Pitch(0).Octave())
// Output: 4
}
func TestParsePitch(t *testing.T) {
cases := map[string]struct {
expected Pitch
expectError bool
}{
"C4": {0, false},
"C#4": {1, false},
"Db4": {1, false},
"A2": {-15, false},
"C#5": {13, false},
"Hello": {0, true},
}
for raw, c := range cases {
t.Run(raw, func(t *testing.T) {
actual, err := PitchFromString(raw)
if c.expectError && err == nil {
t.Errorf("PitchFromString(%q) did not cause an error", raw)
} else if !c.expectError && err != nil {
t.Errorf("PitchFromString(%q) caused an unexpected error: %s", raw, err)
}
if actual != c.expected {
t.Errorf("PitchFromString(%q) = %d, expected %d", raw, actual, c.expected)
}
})
}
}
func TestPitch_String(t *testing.T) {
cases := map[string]struct {
pitch Pitch
expected string
}{
"C4": {0, "C4"},
"C#4": {1, "C#4"},
"A2": {-15, "A2"},
"C#5": {13, "C#5"},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
actual := c.pitch.String()
if actual != c.expected {
t.Errorf("Pitch(%d).String() = %q, expected %q", c.pitch, actual, c.expected)
}
})
}
}