forked from tonaljs/tonal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
234 lines (218 loc) · 7.74 KB
/
test.ts
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import Chord from "./index";
const $ = (str: string) => str.split(" ");
describe("tonal-chord", () => {
test("tokenize", () => {
expect(Chord.tokenize("Cmaj7")).toEqual(["C", "maj7"]);
expect(Chord.tokenize("c7")).toEqual(["C", "7"]);
expect(Chord.tokenize("maj7")).toEqual(["", "maj7"]);
expect(Chord.tokenize("c#4 m7b5")).toEqual(["C#4", "m7b5"]);
expect(Chord.tokenize("c#4m7b5")).toEqual(["C#4", "m7b5"]);
expect(Chord.tokenize("Cb7b5")).toEqual(["Cb", "7b5"]);
expect(Chord.tokenize("Eb7add6")).toEqual(["Eb", "7add6"]);
expect(Chord.tokenize("Bb6b5")).toEqual(["Bb", "6b5"]);
expect(Chord.tokenize("aug")).toEqual(["", "aug"]);
expect(Chord.tokenize("C11")).toEqual(["C", "11"]);
expect(Chord.tokenize("C13no5")).toEqual(["C", "13no5"]);
expect(Chord.tokenize("C64")).toEqual(["C", "64"]);
// see: https://github.com/tonaljs/tonal/issues/70
expect(Chord.tokenize("C5")).toEqual(["C", "5"]);
expect(Chord.tokenize("C4")).toEqual(["C", "4"]);
});
describe("getChord", () => {
test("Chord properites", () => {
expect(Chord.getChord("maj7", "G4", "G4")).toEqual({
empty: false,
name: "G major seventh",
symbol: "Gmaj7",
tonic: "G4",
root: "G4",
rootDegree: 1,
setNum: 2193,
type: "major seventh",
aliases: ["maj7", "Δ", "ma7", "M7", "Maj7", "^7"],
chroma: "100010010001",
intervals: ["1P", "3M", "5P", "7M"],
normalized: "100010010001",
notes: ["G4", "B4", "D5", "F#5"],
quality: "Major",
});
});
test("first inversion", () => {
expect(Chord.getChord("maj7", "G4", "B4")).toEqual({
empty: false,
name: "G major seventh over B",
symbol: "Gmaj7/B",
tonic: "G4",
root: "B4",
rootDegree: 2,
setNum: 2193,
type: "major seventh",
aliases: ["maj7", "Δ", "ma7", "M7", "Maj7", "^7"],
chroma: "100010010001",
intervals: ["3M", "5P", "7M", "8P"],
normalized: "100010010001",
notes: ["B4", "D5", "F#5", "G5"],
quality: "Major",
});
});
test("first inversion without octave", () => {
expect(Chord.getChord("maj7", "G", "B")).toEqual({
empty: false,
name: "G major seventh over B",
symbol: "Gmaj7/B",
tonic: "G",
root: "B",
rootDegree: 2,
setNum: 2193,
type: "major seventh",
aliases: ["maj7", "Δ", "ma7", "M7", "Maj7", "^7"],
chroma: "100010010001",
intervals: ["3M", "5P", "7M", "8P"],
normalized: "100010010001",
notes: ["B", "D", "F#", "G"],
quality: "Major",
});
});
test("second inversion", () => {
expect(Chord.getChord("maj7", "G4", "D5")).toEqual({
empty: false,
name: "G major seventh over D",
symbol: "Gmaj7/D",
tonic: "G4",
root: "D5",
rootDegree: 3,
setNum: 2193,
type: "major seventh",
aliases: ["maj7", "Δ", "ma7", "M7", "Maj7", "^7"],
chroma: "100010010001",
intervals: ["5P", "7M", "8P", "10M"],
normalized: "100010010001",
notes: ["D5", "F#5", "G5", "B5"],
quality: "Major",
});
});
test("without root", () => {
expect(Chord.getChord("M7", "G")).toMatchObject({
symbol: "GM7",
name: "G major seventh",
notes: ["G", "B", "D", "F#"],
});
});
test("rootDegrees", () => {
expect(Chord.getChord("maj7", "C", "C").rootDegree).toBe(1);
expect(Chord.getChord("maj7", "C", "D").empty).toBe(true);
});
test("without tonic nor root", () => {
expect(Chord.getChord("dim")).toEqual({
symbol: "dim",
name: "diminished",
tonic: "",
root: "",
rootDegree: 0,
type: "diminished",
aliases: ["dim", "°", "o"],
chroma: "100100100000",
empty: false,
intervals: ["1P", "3m", "5d"],
normalized: "100000100100",
notes: [],
quality: "Diminished",
setNum: 2336,
});
});
});
test("chord", () => {
expect(Chord.get("Cmaj7")).toEqual({
empty: false,
symbol: "Cmaj7",
name: "C major seventh",
tonic: "C",
root: "",
rootDegree: 0,
setNum: 2193,
type: "major seventh",
aliases: ["maj7", "Δ", "ma7", "M7", "Maj7", "^7"],
chroma: "100010010001",
intervals: ["1P", "3M", "5P", "7M"],
normalized: "100010010001",
notes: ["C", "E", "G", "B"],
quality: "Major",
});
expect(Chord.get("hello").empty).toBe(true);
expect(Chord.get("").empty).toBe(true);
expect(Chord.get("C").name).toEqual("C major");
});
test("chord without tonic", () => {
expect(Chord.get("dim")).toMatchObject({ name: "diminished" });
expect(Chord.get("dim7")).toMatchObject({ name: "diminished seventh" });
expect(Chord.get("alt7")).toMatchObject({ name: "altered" });
});
test("notes", () => {
expect(Chord.get("Cmaj7").notes).toEqual(["C", "E", "G", "B"]);
expect(Chord.get("Eb7add6").notes).toEqual(["Eb", "G", "Bb", "Db", "C"]);
expect(Chord.get("C4 maj7").notes).toEqual(["C4", "E4", "G4", "B4"]);
expect(Chord.get("C7").notes).toEqual(["C", "E", "G", "Bb"]);
expect(Chord.get("Cmaj7#5").notes).toEqual(["C", "E", "G#", "B"]);
expect(Chord.get("blah").notes).toEqual([]);
});
test("notes with two params", () => {
expect(Chord.get(["C", "maj7"]).notes).toEqual(["C", "E", "G", "B"]);
// see: https://github.com/danigb/tonal/issues/82
expect(Chord.get(["C6", "maj7"]).notes).toEqual(["C6", "E6", "G6", "B6"]);
});
// see: https://github.com/danigb/tonal/issues/52
test("augmented chords (issue #52)", () => {
expect(Chord.get("Caug").notes).toEqual(["C", "E", "G#"]);
expect(Chord.get(["C", "aug"]).notes).toEqual(["C", "E", "G#"]);
});
test("intervals", () => {
expect(Chord.get("maj7").intervals).toEqual(["1P", "3M", "5P", "7M"]);
expect(Chord.get("Cmaj7").intervals).toEqual(["1P", "3M", "5P", "7M"]);
expect(Chord.get("aug").intervals).toEqual(["1P", "3M", "5A"]);
expect(Chord.get("C13no5").intervals).toEqual([
"1P",
"3M",
"7m",
"9M",
"13M",
]);
expect(Chord.get("major").intervals).toEqual(["1P", "3M", "5P"]);
});
test("exists", () => {
expect(Chord.get("maj7").empty).toBe(false);
expect(Chord.get("Cmaj7").empty).toBe(false);
expect(Chord.get("mixolydian").empty).toBe(true);
});
test("chordScales", () => {
const names =
"phrygian dominant,flamenco,spanish heptatonic,half-whole diminished,chromatic";
expect(Chord.chordScales("C7b9")).toEqual(names.split(","));
});
it("transpose chord names", () => {
expect(Chord.transpose("Eb7b9", "5P")).toEqual("Bb7b9");
expect(Chord.transpose("7b9", "5P")).toEqual("7b9");
});
test("extended", () => {
const chords =
"Cmaj#4 Cmaj7#9#11 Cmaj9 CM7add13 Cmaj13 Cmaj9#11 CM13#11 CM7b9";
expect(Chord.extended("CMaj7").sort()).toEqual($(chords).sort());
});
test("reduced", () => {
expect(Chord.reduced("CMaj7")).toEqual(["C5", "CM"]);
});
/*
test.skip("position", () => {
expect(Chord.position("g2 c3 e4 b")).toEqual(2);
expect(Chord.position("b e c g")).toEqual(3);
});
test.skip("inversion", () => {
expect(Chord.inversion(1, "C4 maj7")).toEqual(["E", "G", "B", "C"]);
expect(Chord.inversion(0, "e g c")).toEqual(["C", "E", "G"]);
expect(Chord.inversion(1, "e g c")).toEqual(["E", "G", "C"]);
expect(Chord.inversion(2, "e g c")).toEqual(["G", "C", "E"]);
expect(Chord.inversion(0)("b g e d c")).toEqual(["C", "E", "G", "B", "D"]);
expect(Chord.inversion(3, "CMaj7#5")).toEqual(["B", "C", "E", "G#"]);
expect(Chord.inversion(1, "c d e")).toEqual([]);
});
*/
});