forked from tardate/jtab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jtab-unittest.html
321 lines (246 loc) · 9.73 KB
/
jtab-unittest.html
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
314
315
316
317
318
319
320
321
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>jTab - Unit Tests</title>
<script src="unit_test_assets/jsunittest.js" type="text/javascript"></script>
<link rel="stylesheet" href="unit_test_assets/unittest.css" type="text/css" />
<!-- START: for jtab -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link type="text/css" rel="stylesheet" href="css/jtab-helper.css"/>
<script src="javascripts/prototype.js" type="text/javascript"></script>
<script src="javascripts/raphael.js" type="text/javascript"></script>
<script src="javascripts/jtab.js" type="text/javascript"></script>
<!-- END: for jtab -->
</head>
<body>
<div id="content">
<div id="header">
<h1>jTab - Unit Tests</h1>
<p>
This file tests the core algirithms in <strong>jtab.js</strong>.
</p>
</div>
<!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
<div id="testlog"></div>
<!-- Put sample/test html here -->
<div id="sample">
</div>
</div>
<script type="text/javascript">
// <![CDATA[
new Test.Unit.Runner({
setup: function() {
},
teardown: function() {
},
testUnitTestFrameworkOperational: function() { with(this) {
assert(true);
}},
/*
The western scale is commonly found in 'western pop' music.
It consists of 12 notes that are 1 intervals apart to form an octave.
Eg. C, C#, D, Eb, E, F, F#, G, G#, A, Bb, C
Other notable scales such as the Pentatonic scale which consists of only 5 notes and
the Indian scale which has 24 notes.
We need to normalize the notes available to our western scale into base notes because
the following pairs are equivalent.
C# = Db
D# = Eb
F# = Gb
G# = Ab
A# = Bb
It is just a matter of convention when we favoured C#, Eb, F#, G#, Bb over their
equivalents in rendering our base notes.
*/
testWesternScale: function() { with(this) {
var scale = jtab.WesternScale;
assertNotUndefined( scale, "jtab.WesternScale should be valid" );
}},
testWesternScaleBaseNotes: function() { with(this) {
var baseNotes = jtab.WesternScale.BaseNotes;
assertNotUndefined( baseNotes, "jtab.WesternScale.BaseNotes should be valid" );
var validBaseNotes = {
'C' : 'C',
'C#': 'C#',
'Db': 'C#',
'D' : 'D',
'D#': 'Eb',
'Eb': 'Eb',
'E' : 'E',
'F' : 'F',
'F#': 'F#',
'Gb': 'F#',
'G' : 'G',
'G#': 'G#',
'Ab': 'G#',
'A' : 'A',
'A#': 'Bb',
'Bb': 'Bb',
'B' : 'B'
};
assertHashEqual( validBaseNotes, baseNotes, "jtab.WesternScale.BaseNotes should have correct mappings" );
}},
testWesternScaleBaseIntervals: function() { with(this) {
var baseIntervals = jtab.WesternScale.BaseIntervals;
assertNotUndefined( baseIntervals, "jtab.WesternScale.BaseIntervals should be valid" );
var validBaseIntervals = ['C', 'C#', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'G#', 'A', 'Bb', 'B'];
assertHashEqual( validBaseIntervals, baseIntervals, "jtab.WesternScale.BaseIntervals should have correct 12 notes" );
}},
testChordsAreBasedOnWesternScale: function() { with(this) {
var msg = "Chords should be based on the western scale";
var chord = new jtabChord('C');
assertEqual( jtab.WesternScale, chord.scale, msg );
assertEqual( jtab.WesternScale.BaseNotes, chord.baseNotes, msg );
}},
/*
In our CAGED system, we'll be using positions as defined in the following matrix
C = position 1
A = position 2
G = position 3
E = position 4
D = position 5
As such position 1 can also be called the 'C shape' position, position 2 the
'A shape' position, etc.
Playing different chord voicings then becomes nothing more than just shifting the
appropriate shapes around to coincide the shape's root note with the desired chord's
root note on the fretboard.
Eg.
Fret 0 X_R_______O
|_|_|_|_|_|
|_|_1_2_3_|
Fret 3 |_|_|_|_|_|
|_|_|_|_|_|
An 'A shaped' A major where its root note is at 'R'
Fret 0 X__________
|_|_|_|_|_|
|_R_|_|_|_1
Fret 3 |_|_|_|_|_|
|_|_2_3_4_|
An 'A shaped' B major with root of A shape over B note on 5th string
Position/shape can be defined in our chord token,
Eg. C:1, Cmaj7:3, etc.
where the numbers 1-5 after the ':' in token reflects the desired position/shape.
If in the absence of specified position/shape in token, we'll use the most playable
shape as the desired chord's position/shape. In general,
- Chords with root note within C, A, G, E, D will take the shape of it's root note except
* major 7ths
* minor chords
* dominants above 7ths, eg. C9, C11, etc.
* augmented chords
* diminished chords
- E & A shapes (good for barred chords) will be considered for exceptions above
- Chords with root note that falls within B, Bb, C#, Eb will use A shape
- Chords with root note that falls within F, F#, G# will take E shape
*/
testRecognizingRootNoteOfChordFromToken: function() { with(this) {
var msg = "Root note of chord should be correct";
var chord = new jtabChord('C');
assertEqual( 'C', chord.rootNote, msg );
chord = new jtabChord('C#');
assertEqual( 'C#', chord.rootNote, msg );
chord = new jtabChord('C#m');
assertEqual( 'C#', chord.rootNote, msg );
chord = new jtabChord('C#maj7');
assertEqual( 'C#', chord.rootNote, msg );
chord = new jtabChord('C#maj7:1');
assertEqual( 'C#', chord.rootNote, msg );
chord = new jtabChord('Db');
assertEqual( 'C#', chord.rootNote, msg );
chord = new jtabChord('Dbmaj7');
assertEqual( 'C#', chord.rootNote, msg );
chord = new jtabChord('Dbmaj7:2');
assertEqual( 'C#', chord.rootNote, msg );
}},
testSettingCagedPositionBasedOnPositionInToken: function() { with(this) {
var msg = "Caged position should follow position found in token";
var chord = new jtabChord('C:1');
var cagedPos = chord.cagedPos;
assertNotUndefined( cagedPos );
assertEqual( 1, cagedPos, msg );
chord = new jtabChord('C:2');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg );
chord = new jtabChord('C:3');
cagedPos = chord.cagedPos;
assertEqual( 3, cagedPos, msg );
chord = new jtabChord('C:4');
cagedPos = chord.cagedPos;
assertEqual( 4, cagedPos, msg );
}},
testSettingCagedPositionBasedOnRootNoteInToken: function() { with(this) {
var msg = "Caged position should derived from root note if position is not found in token";
var chord = new jtabChord('C');
var cagedPos = chord.cagedPos;
assertNotUndefined( cagedPos );
assertEqual( 1, cagedPos, msg );
chord = new jtabChord('C#');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg);
chord = new jtabChord('D');
cagedPos = chord.cagedPos;
assertEqual( 5, cagedPos, msg);
chord = new jtabChord('D#');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg);
chord = new jtabChord('E');
cagedPos = chord.cagedPos;
assertEqual( 4, cagedPos, msg);
chord = new jtabChord('Eb');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg);
chord = new jtabChord('F');
cagedPos = chord.cagedPos;
assertEqual( 4, cagedPos, msg);
chord = new jtabChord('F#');
cagedPos = chord.cagedPos;
assertEqual( 4, cagedPos, msg);
chord = new jtabChord('G');
cagedPos = chord.cagedPos;
assertEqual( 3, cagedPos, msg);
chord = new jtabChord('G#');
cagedPos = chord.cagedPos;
assertEqual( 4, cagedPos, msg);
chord = new jtabChord('A');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg);
chord = new jtabChord('A#');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg);
chord = new jtabChord('Bb');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg);
chord = new jtabChord('B');
cagedPos = chord.cagedPos;
assertEqual( 2, cagedPos, msg);
}},
testChord_C_fingering: function() { with(this) {
var token = 'C';
var modelChordArray = [ 1, [-1 ], [3,3], [2,2], [0 ], [1,1], [0 ] ];
var c = new jtabChord(token);
assert( c.isValid, "jtabChord('" + token + "') should be valid" );
assert( ! c.isCaged, "jtabChord('" + token + "') should not be CAGED" );
assertHashEqual( modelChordArray, c.chordArray, "jtabChord('" + token + "') returned incorrect chordArray" );
}},
testChord_C1_fingering: function() { with(this) {
var token = 'C:1';
var modelChordArray = [ 1, [-1 ], [3,3], [2,2], [0 ], [1,1], [0 ] ];
var c = new jtabChord(token);
assert( c.isValid, "jtabChord('" + token + "') should be valid" );
assert( c.isCaged, "jtabChord('" + token + "') should be CAGED" );
assertHashEqual( modelChordArray, c.chordArray, "jtabChord('" + token + "') returned incorrect chordArray" );
}},
testChord_C2_fingering: function() { with(this) {
var token = 'C:2';
var modelChordArray = [ 3, [-1,-1 ], [3,1], [5,2], [5,3], [5,4], [3,1] ];
var c = new jtabChord(token);
assert( c.isValid, "jtabChord('" + token + "') should be valid" );
assert( c.isCaged, "jtabChord('" + token + "') should be CAGED" );
assertHashEqual( modelChordArray, c.chordArray, "jtabChord('" + token + "') returned incorrect chordArray" );
}},
});
// ]]>
</script>
</body>
</html>