-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
176 lines (142 loc) · 5.3 KB
/
test.js
File metadata and controls
176 lines (142 loc) · 5.3 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
var s11 = require('sharp11');
var improv = require('./index.js');
var charts = require('./sample/charts');
var assert = require('assert');
describe('Improv', function () {
describe('#overChart', function () {
it('should generate an improvisation', function () {
var imp = improv.overChart(charts.myFunnyValentine);
assert(imp.data[0].scale);
assert(imp.data[0].chord);
assert.equal(imp.data[0].notes.length, 4);
assert.equal(imp.data[0].duration.beats, 4);
});
it.skip('should generate an improvisation within a given range', function () {
this.timeout(20000);
var imp;
var i;
for (i = 0; i < 25; i += 1) {
imp = improv.overChart(charts.myFunnyValentine, {range: ['C4', 'C5']});
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
arr.forEach(function (note) {
if (note) {
assert(!note.lowerThan('C4'));
assert(!note.higherThan('C5'));
}
});
});
});
}
});
it.skip('should terminate', function () {
this.timeout(20000);
var imp;
var i;
for (i = 0; i < 50; i += 1) {
imp = improv.overChart(charts.myFunnyValentine);
}
});
it('should obey the `rests` setting', function () {
var imp = improv.overChart(charts.myFunnyValentine, {rests: 1});
var foundRest = false;
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
arr.forEach(function (note) {
if (!note) foundRest = true;
});
});
});
assert(foundRest);
imp = improv.overChart(charts.myFunnyValentine, {cadence: false, rests: 0});
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
arr.forEach(function (note) {
assert(note);
});
});
});
});
it('should obey the `rhythmicVariety` setting', function () {
var imp = improv.overChart(charts.myFunnyValentine, {rhythmicVariety: 0.5});
var found = [false, false, false];
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
found[arr.length - 2] = true;
});
});
assert(found[0]);
assert(found[1]);
assert(found[2]);
imp = improv.overChart(charts.myFunnyValentine, {rhythmicVariety: 0});
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
assert.equal(arr.length, 2);
});
});
});
it('should obey the `useSixteenths` setting', function () {
var imp = improv.overChart(charts.myFunnyValentine, {useSixteenths: true, rhythmicVariety: 0.5});
var found4;
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
if (arr.length === 4) found4 = true;
});
});
assert(found4);
imp = improv.overChart(charts.myFunnyValentine, {useSixteenths: false, rhythmicVariety: 0.5});
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
assert.notEqual(arr.length, 4);
});
});
});
it('should obey the `onlyEighthRests` setting', function () {
var imp = improv.overChart(charts.myFunnyValentine, {onlyEighthRests: true});
var foundRest = false;
imp.data.forEach(function (obj) {
obj.notes.forEach(function (arr) {
if (arr.length !== 2) {
assert.equal(arr.indexOf(null), -1);
}
});
});
});
it('should obey the `sections` setting', function () {
var imp = improv.overChart(charts.myFunnyValentine, {cadence: false, sections: ['A']});
assert.equal(imp.data.length, 8);
});
it('should obey the `cadence` setting', function () {
var imp = improv.overChart(charts.takeTheATrain, {cadence: true});
assert.equal(imp.data.length, 8);
assert.equal(imp.data[7].chord.name, 'C6');
assert.equal(imp.data[7].notes.length, 1);
assert.equal(imp.data[7].notes[0][1], null);
});
it('should obey the `repeat` setting', function () {
var imp = improv.overChart(charts.takeTheATrain, {repeat: 2, cadence: false});
assert.equal(imp.data.length, 14);
imp = improv.overChart(charts.takeTheATrain, {repeat: 2, cadence: true});
assert.equal(imp.data.length, 15);
imp = improv.overChart(charts.myFunnyValentine, {cadence: true, sections: ['A'], repeat: 2});
assert.equal(imp.data.length, 17);
});
});
describe('ImprovChart', function () {
describe('#notesAndDurations', function () {
it('should return a list of notes and durations', function () {
var imp = improv.overChart(charts.myFunnyValentine, {rests: 0});
assert(s11.note.isNote(imp.notesAndDurations()[0].note));
assert(s11.duration.isDuration(imp.notesAndDurations()[0].duration));
});
});
describe('#chordsAndDurations', function () {
it('should return a list of chords and durations', function () {
var imp = improv.overChart(charts.takeTheATrain, {rests: 0});
assert(s11.chord.isChord(imp.chordsAndDurations()[0].chord));
assert(s11.duration.isDuration(imp.chordsAndDurations()[0].duration));
assert.equal(imp.chordsAndDurations().length, 8);
});
});
});
});