-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcaged.test.js
More file actions
313 lines (260 loc) · 10.6 KB
/
Copy pathcaged.test.js
File metadata and controls
313 lines (260 loc) · 10.6 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import { describe, expect, it } from "vitest";
import { Scale } from "tonal";
import frets from "../index.js";
import caged from "./caged.js";
describe("CAGED system", () => {
describe("C major scale", () => {
it("assigns G shape (position 5) correctly - starts at fret 5 with A, B, C", () => {
const scale = Scale.get("C major");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const lowE = fb.strings[5]; // Low E string (reversed order)
// G shape pattern on low E has degrees [6, 7, 1] = A, B, C
expect(lowE[5].note.pc).toBe("A");
expect(lowE[5].positions.CAGED).toContain(5);
expect(lowE[7].note.pc).toBe("B");
expect(lowE[7].positions.CAGED).toContain(5);
expect(lowE[8].note.pc).toBe("C");
expect(lowE[8].positions.CAGED).toContain(5);
});
it("assigns E shape (position 1) correctly - starts at open position", () => {
const scale = Scale.get("C major");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const lowE = fb.strings[5];
// E shape pattern on low E has degrees [7, 1, 2] = B, C, D
expect(lowE[7].note.pc).toBe("B");
expect(lowE[7].positions.CAGED).toContain(1);
expect(lowE[8].note.pc).toBe("C");
expect(lowE[8].positions.CAGED).toContain(1);
expect(lowE[10].note.pc).toBe("D");
expect(lowE[10].positions.CAGED).toContain(1);
});
});
describe("C minor scale", () => {
it("assigns G shape (position 5) correctly - starts at fret 8 with C, D, Eb", () => {
const scale = Scale.get("C minor");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const lowE = fb.strings[5];
// For minor, G shape pattern rotates +2, so low E has degrees [1, 2, 3] = C, D, Eb
expect(lowE[8].note.pc).toBe("C");
expect(lowE[8].positions.CAGED).toContain(5);
expect(lowE[10].note.pc).toBe("D");
expect(lowE[10].positions.CAGED).toContain(5);
// Use label which reflects the scale's spelling (E♭ not D#)
expect(lowE[11].label).toBe("E♭");
expect(lowE[11].positions.CAGED).toContain(5);
});
});
describe("error handling", () => {
it("throws error for chromatic scale (12 notes)", () => {
const chromatic = Scale.get("C chromatic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16);
expect(() => caged(fb.strings, chromatic)).toThrow(
"CAGED system only works with 5-note pentatonic or 7-note scales"
);
});
it("throws error for 6-note scales", () => {
const blues = Scale.get("C blues");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16);
expect(() => caged(fb.strings, blues)).toThrow(
"CAGED system only works with 5-note pentatonic or 7-note scales"
);
});
});
describe("position assignment", () => {
it("assigns positions to all scale notes", () => {
const scale = Scale.get("G major");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
for (const string of fb.strings) {
for (const note of string) {
if (note.interval) {
expect(note.positions.CAGED).toBeDefined();
expect(Array.isArray(note.positions.CAGED)).toBe(true);
expect(note.positions.CAGED.length).toBeGreaterThan(0);
}
}
}
});
it("assigns positions between 1 and 5", () => {
const scale = Scale.get("A minor");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
for (const string of fb.strings) {
for (const note of string) {
if (note.positions.CAGED?.length > 0) {
for (const pos of note.positions.CAGED) {
expect(pos).toBeGreaterThanOrEqual(1);
expect(pos).toBeLessThanOrEqual(5);
}
}
}
}
});
it("does not assign positions to non-scale notes", () => {
const scale = Scale.get("C major");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
for (const string of fb.strings) {
for (const note of string) {
if (!note.interval) {
expect(
note.positions.CAGED === undefined ||
note.positions.CAGED.length === 0
).toBe(true);
}
}
}
});
});
describe("works with different keys", () => {
it("works with G major", () => {
const scale = Scale.get("G major");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const lowE = fb.strings[5];
// G is at fret 3, should be in position 5 (G shape starts on root)
expect(lowE[3].note.pc).toBe("G");
expect(lowE[3].positions.CAGED).toContain(5);
});
it("works with E minor", () => {
const scale = Scale.get("E minor");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const lowE = fb.strings[5];
// E is at fret 0 (open), should be in G shape (position 5) for minor
expect(lowE[0].note.pc).toBe("E");
expect(lowE[0].positions.CAGED).toContain(5);
});
});
describe("C major pentatonic", () => {
it("assigns positions using 7-degree mapping (1,2,3,5,6)", () => {
const scale = Scale.get("C major pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const lowE = fb.strings[5];
// C major pentatonic: C(1), D(2), E(3), G(5), A(6)
// On low E: E at fret 0, G at fret 3, A at fret 5, C at fret 8, D at fret 10
expect(lowE[0].note.pc).toBe("E");
expect(lowE[0].positions.CAGED).toBeDefined();
expect(lowE[0].positions.CAGED.length).toBeGreaterThan(0);
expect(lowE[3].note.pc).toBe("G");
expect(lowE[3].positions.CAGED).toBeDefined();
expect(lowE[5].note.pc).toBe("A");
expect(lowE[5].positions.CAGED).toBeDefined();
expect(lowE[8].note.pc).toBe("C");
expect(lowE[8].positions.CAGED).toBeDefined();
expect(lowE[10].note.pc).toBe("D");
expect(lowE[10].positions.CAGED).toBeDefined();
});
it("assigns all 5 positions across the fretboard", () => {
const scale = Scale.get("C major pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const allPositions = new Set();
for (const string of fb.strings) {
for (const note of string) {
if (note.positions.CAGED) {
note.positions.CAGED.forEach((p) => allPositions.add(p));
}
}
}
expect(allPositions.size).toBe(5);
expect([...allPositions].sort()).toEqual([1, 2, 3, 4, 5]);
});
it("assigns correct intervals to scale notes", () => {
const scale = Scale.get("C major pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
// C major pentatonic intervals: 1P, 2M, 3M, 5P, 6M
const expectedIntervals = ["1P", "2M", "3M", "5P", "6M"];
for (const string of fb.strings) {
for (const note of string) {
if (note.interval) {
expect(expectedIntervals).toContain(note.interval);
}
}
}
});
});
describe("C minor pentatonic", () => {
it("assigns positions with rotation for minor scale", () => {
const scale = Scale.get("C minor pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const lowE = fb.strings[5];
// C minor pentatonic: C(1), Eb(3), F(4), G(5), Bb(7)
// On low E: F at fret 1, G at fret 3, Bb at fret 6, C at fret 8
expect(lowE[1].note.pc).toBe("F");
expect(lowE[1].positions.CAGED).toBeDefined();
expect(lowE[1].positions.CAGED.length).toBeGreaterThan(0);
expect(lowE[3].note.pc).toBe("G");
expect(lowE[3].positions.CAGED).toBeDefined();
expect(lowE[6].note.pc).toBe("Bb");
expect(lowE[6].positions.CAGED).toBeDefined();
expect(lowE[8].note.pc).toBe("C");
expect(lowE[8].positions.CAGED).toBeDefined();
});
it("assigns all 5 positions across the fretboard", () => {
const scale = Scale.get("C minor pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const allPositions = new Set();
for (const string of fb.strings) {
for (const note of string) {
if (note.positions.CAGED) {
note.positions.CAGED.forEach((p) => allPositions.add(p));
}
}
}
expect(allPositions.size).toBe(5);
expect([...allPositions].sort()).toEqual([1, 2, 3, 4, 5]);
});
it("assigns correct intervals to scale notes", () => {
const scale = Scale.get("C minor pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
// C minor pentatonic intervals: 1P, 3m, 4P, 5P, 7m
const expectedIntervals = ["1P", "3m", "4P", "5P", "7m"];
for (const string of fb.strings) {
for (const note of string) {
if (note.interval) {
expect(expectedIntervals).toContain(note.interval);
}
}
}
});
});
describe("pentatonic position assignment", () => {
it("assigns positions to all pentatonic scale notes", () => {
const scale = Scale.get("A minor pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
for (const string of fb.strings) {
for (const note of string) {
if (note.interval) {
expect(note.positions.CAGED).toBeDefined();
expect(Array.isArray(note.positions.CAGED)).toBe(true);
expect(note.positions.CAGED.length).toBeGreaterThan(0);
}
}
}
});
it("assigns positions between 1 and 5 for pentatonic", () => {
const scale = Scale.get("G major pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
for (const string of fb.strings) {
for (const note of string) {
if (note.positions.CAGED?.length > 0) {
for (const pos of note.positions.CAGED) {
expect(pos).toBeGreaterThanOrEqual(1);
expect(pos).toBeLessThanOrEqual(5);
}
}
}
}
});
it("does not assign positions to non-scale notes for pentatonic", () => {
const scale = Scale.get("E minor pentatonic");
const fb = frets(["E2", "A2", "D3", "G3", "B3", "E4"], 16, scale);
const scaleNotes = scale.notes.map((n) => n.replace(/[0-9]/g, ""));
for (const string of fb.strings) {
for (const note of string) {
if (!scaleNotes.includes(note.note.pc)) {
expect(
note.positions.CAGED === undefined ||
note.positions.CAGED.length === 0
).toBe(true);
}
}
}
});
});
});