-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathkey_test.go
48 lines (38 loc) · 1.16 KB
/
key_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
// The key of a piece is a group of pitches, or scale upon which a music composition is created in classical, Western art, and Western pop music.
package key
import (
"io/ioutil"
"testing"
"gopkg.in/stretchr/testify.v1/assert"
"gopkg.in/yaml.v2"
"fmt"
"gopkg.in/music-theory.v0/note"
)
func TestKeys(t *testing.T) {
testExpectations := testExpectationManifest{}
file, err := ioutil.ReadFile("testdata/expectations.yaml")
assert.Nil(t, err)
err = yaml.Unmarshal(file, &testExpectations)
assert.Nil(t, err)
assert.True(t, len(testExpectations.Keys) > 0)
for name, expect := range testExpectations.Keys {
actual := Of(name)
expectMode := modeOf(expect.Mode)
assert.Equal(t, note.ClassNamed(expect.Root), actual.Root, fmt.Sprintf("name:%v expect.Root=%v actual.Root=%v", name, expect.Root, actual.Root))
assert.Equal(t, expectMode, actual.Mode, fmt.Sprintf("name:%v expect.Mode=%v actual.Mode==%v", name, expectMode, actual.Mode))
}
}
func TestOf_Invalid(t *testing.T) {
k := Of("P-funk")
assert.Equal(t, note.Nil, k.Root)
}
//
// Private
//
type testKey struct {
Root string
Mode string
}
type testExpectationManifest struct {
Keys map[string]testKey
}