discombobulator 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,275 +0,0 @@
1
- // schedule.mjs
2
- //
3
- // Tests for schedule.mjs.
4
-
5
- import { expect } from './testing.mjs'
6
-
7
- import { Schedule } from '../schedule.mjs'
8
- import { Pattern } from '../pattern.mjs'
9
- import { PatternSet } from '../patternset.mjs'
10
-
11
- export const test = {
12
- tests: [
13
- {
14
- title: "default constructor results in undefined symbol",
15
- test: () => {
16
- const set = new Schedule();
17
-
18
- expect(set.isAbstract, false);
19
- expect(set.allowDuplicates, true);
20
- expect(set.size, 0);
21
- },
22
- },
23
-
24
- {
25
- title: "length returns correct length when empty",
26
- test: () => {
27
- const set = new Schedule();
28
-
29
- expect(set.length, 0);
30
- },
31
- },
32
- {
33
- title: "length returns correct length with one pattern",
34
- test: () => {
35
- const set = new Schedule({
36
- add: new Pattern()
37
- });
38
-
39
- expect(set.length, 1);
40
- },
41
- },
42
- {
43
- title: "length returns correct length with two patterns",
44
- test: () => {
45
- const set = new Schedule({
46
- add: [ new Pattern(), new Pattern() ]
47
- });
48
-
49
- expect(set.length, 2);
50
- },
51
- },
52
- {
53
- title: "length returns correct length with one pattern set containing no patterns",
54
- test: () => {
55
- const set = new Schedule({
56
- add: new PatternSet()
57
- });
58
-
59
- expect(set.length, 0);
60
- },
61
- },
62
- {
63
- title: "length returns correct length with one pattern set containing one pattern",
64
- test: () => {
65
- const set = new Schedule({
66
- add: new PatternSet({
67
- add: new Pattern()
68
- })
69
- });
70
-
71
- expect(set.length, 1);
72
- },
73
- },
74
- {
75
- title: "length returns correct length with one pattern set containing two patterns",
76
- test: () => {
77
- const set = new Schedule({
78
- add: new PatternSet({
79
- add: [ new Pattern(), new Pattern() ],
80
- allowDuplicates: true // To make things a little easier for testing
81
- })
82
- });
83
-
84
- expect(set.length, 2);
85
- },
86
- },
87
- {
88
- title: "length returns correct length with one pattern and one pattern set containing no patterns",
89
- test: () => {
90
- const set = new Schedule({
91
- add: [ new Pattern(), new PatternSet()]
92
- });
93
-
94
- expect(set.length, 1);
95
- },
96
- },
97
- {
98
- title: "length returns correct length with one pattern and one pattern set containing one pattern",
99
- test: () => {
100
- const set = new Schedule({
101
- add: [ new Pattern(), new PatternSet({
102
- add: [ new Pattern() ]
103
- })]
104
- });
105
-
106
- expect(set.length, 2);
107
- },
108
- },
109
- {
110
- title: "length returns correct length with two pattern sets",
111
- test: () => {
112
- const set = new Schedule({
113
- add: [ new PatternSet({
114
- add: [ new Pattern(), new Pattern() ],
115
- allowDuplicates: true
116
- }),
117
- new PatternSet({
118
- add: [ new Pattern(), new Pattern() ],
119
- allowDuplicates: true
120
- }),
121
- ]
122
- });
123
-
124
- expect(set.length, 4);
125
- },
126
- },
127
-
128
- {
129
- title: "patterns yields nothing when empty",
130
- test: () => {
131
- const set = new Schedule();
132
-
133
- let count = 0;
134
-
135
- for (let pattern of set.patterns) {
136
- ++count;
137
- }
138
-
139
- expect(count, 0);
140
- },
141
- },
142
- {
143
- title: "patterns yields correct patterns with one pattern",
144
- test: () => {
145
- const patterns = [ new Pattern() ];
146
- const set = new Schedule({ add: patterns });
147
-
148
- let count = 0;
149
-
150
- for (let pattern of set.patterns) {
151
- expect(pattern === patterns[count], true);
152
- ++count;
153
- }
154
-
155
- expect(count, 1);
156
- },
157
- },
158
- {
159
- title: "patterns yields correct patterns with two patterns",
160
- test: () => {
161
- const patterns = [ new Pattern(), new Pattern() ];
162
- const set = new Schedule({ add: patterns });
163
-
164
- let count = 0;
165
-
166
- for (let pattern of set.patterns) {
167
- expect(pattern === patterns[count], true);
168
- ++count;
169
- }
170
-
171
- expect(count, 2);
172
- },
173
- },
174
- {
175
- title: "patterns yields correct patterns with one pattern set containing no patterns",
176
- test: () => {
177
- const patterns = [ new PatternSet() ];
178
- const set = new Schedule({ add: patterns });
179
-
180
- let count = 0;
181
-
182
- for (let pattern of set.patterns) {
183
- ++count;
184
- }
185
-
186
- expect(count, 0);
187
- },
188
- },
189
- {
190
- title: "patterns yields correct patterns with one pattern set containing one pattern",
191
- test: () => {
192
- const patterns = [ new PatternSet({
193
- add: new Pattern()
194
- }) ];
195
- const set = new Schedule({ add: patterns });
196
-
197
- let count = 0;
198
-
199
- for (let pattern of set.patterns) {
200
- expect(pattern === patterns[0].elementAt(count), true);
201
- ++count;
202
- }
203
-
204
- expect(count, 1);
205
- },
206
- },
207
- {
208
- title: "patterns yields correct patterns with one pattern set containing two patterns",
209
- test: () => {
210
- const patterns = [ new PatternSet({
211
- add: [ new Pattern(), new Pattern() ],
212
- allowDuplicates: true,
213
- }) ];
214
- const set = new Schedule({ add: patterns });
215
-
216
- let count = 0;
217
-
218
- for (let pattern of set.patterns) {
219
- expect(pattern === patterns[0].elementAt(count), true);
220
- ++count;
221
- }
222
-
223
- expect(count, 2);
224
- },
225
- },
226
- {
227
- title: "patterns yields correct patterns with two pattern sets containing one pattern each",
228
- test: () => {
229
- const patterns = [
230
- new PatternSet({
231
- add: [ new Pattern() ]
232
- }),
233
- new PatternSet({
234
- add: [ new Pattern() ]
235
- })
236
- ];
237
- const set = new Schedule({ add: patterns });
238
-
239
- let count = 0;
240
-
241
- for (let pattern of set.patterns) {
242
- expect(pattern === patterns[count].elementAt(0), true);
243
- ++count;
244
- }
245
-
246
- expect(count, 2);
247
- },
248
- },
249
- {
250
- title: "patterns yields correct patterns with two pattern sets containing two patterns each",
251
- test: () => {
252
- const patterns = [
253
- new PatternSet({
254
- add: [ new Pattern(), new Pattern() ],
255
- allowDuplicates: true,
256
- }),
257
- new PatternSet({
258
- add: [ new Pattern(), new Pattern() ],
259
- allowDuplicates: true,
260
- })
261
- ];
262
- const set = new Schedule({ add: patterns });
263
-
264
- let count = 0;
265
-
266
- for (let pattern of set.patterns) {
267
- expect(pattern === patterns[count >> 1].elementAt(count % 2), true);
268
- ++count;
269
- }
270
-
271
- expect(count, 4);
272
- },
273
- },
274
- ],
275
- }
@@ -1,333 +0,0 @@
1
- // schema.mjs
2
- //
3
- // Tests for schema.mjs.
4
-
5
- import { expect } from "./testing.mjs";
6
-
7
- import { Schema } from "../schema.mjs";
8
- import { Schedule } from "../schedule.mjs";
9
- import { Pattern } from "../pattern.mjs";
10
- import { Instruments } from "../instrument.mjs";
11
- import { Chord } from "../chord.mjs";
12
-
13
- export const test = {
14
- tests: [
15
- {
16
- title: "default constructor results in undefined symbol",
17
- test: () => {
18
- const set = new Schedule();
19
-
20
- expect(set.isAbstract, false);
21
- expect(set.allowDuplicates, true);
22
- expect(set.size, 0);
23
- },
24
- },
25
-
26
- {
27
- title: "length returns correct length with when empty",
28
- test: () => {
29
- const set = new Schema({
30
- add: new Schedule(),
31
- });
32
-
33
- expect(set.length, 0);
34
- },
35
- },
36
- {
37
- title: "length returns correct length with a single-pattern schedule",
38
- test: () => {
39
- const set = new Schema({
40
- add: new Schedule({
41
- add: new Pattern(),
42
- }),
43
- });
44
-
45
- expect(set.size, 1);
46
- expect(set.length, 1);
47
- },
48
- },
49
- {
50
- title: "length returns correct length with two one-pattern schedules",
51
- test: () => {
52
- const set = new Schema({
53
- add: [
54
- new Schedule({
55
- add: new Pattern(),
56
- }),
57
- new Schedule({
58
- add: new Pattern(),
59
- }),
60
- ],
61
- });
62
-
63
- expect(set.size, 2);
64
- expect(set.length, 1);
65
- },
66
- },
67
- {
68
- title: "length returns correct length with two two-pattern schedules",
69
- test: () => {
70
- const set = new Schema({
71
- add: [
72
- new Schedule({
73
- add: [new Pattern(), new Pattern()],
74
- }),
75
- new Schedule({
76
- add: [new Pattern(), new Pattern()],
77
- }),
78
- ],
79
- });
80
-
81
- expect(set.size, 2);
82
- expect(set.length, 4);
83
- },
84
- },
85
-
86
- {
87
- title: "expressions yields nothing when empty",
88
- test: () => {
89
- const set = new Schema();
90
-
91
- let count = 0;
92
-
93
- for (let expression of set.expressions) {
94
- ++count;
95
- }
96
-
97
- expect(count, 0);
98
- },
99
- },
100
- {
101
- title:
102
- "expressions yields nothing with one schedule containing no patterns",
103
- test: () => {
104
- const set = new Schema({
105
- add: new Schedule(),
106
- });
107
-
108
- let count = 0;
109
-
110
- for (let expression of set.expressions) {
111
- ++count;
112
- }
113
-
114
- expect(count, 0);
115
- },
116
- },
117
- {
118
- title:
119
- "expressions yields correct results with one schedule containing one pattern",
120
- test: () => {
121
- const chords = [
122
- [
123
- new Chord({ add: Instruments.Snare }),
124
- new Chord({ add: Instruments.Bass1 }),
125
- ],
126
- ];
127
-
128
- const set = new Schema({
129
- add: new Schedule({
130
- add: [
131
- new Pattern({
132
- add: chords[0],
133
- }),
134
- ],
135
- }),
136
- });
137
-
138
- let expressionCount = 0;
139
-
140
- for (let expression of set.expressions) {
141
- let chordCount = 0;
142
-
143
- for (let { chord, duration } of expression) {
144
- expect(chord === chords[expressionCount][chordCount], true);
145
-
146
- ++chordCount;
147
- }
148
-
149
- expect(chordCount, 2);
150
-
151
- ++expressionCount;
152
- }
153
-
154
- expect(expressionCount, 1);
155
- },
156
- },
157
- {
158
- title:
159
- "expressions yields correct results with one schedule containing two patterns",
160
- test: () => {
161
- const chords = [
162
- [
163
- new Chord({ add: Instruments.Snare }),
164
- new Chord({ add: Instruments.Bass1 }),
165
- ],
166
- [
167
- new Chord({ add: Instruments.Claves }),
168
- new Chord({ add: Instruments.Crash }),
169
- ],
170
- ];
171
-
172
- const set = new Schema({
173
- add: new Schedule({
174
- add: [
175
- new Pattern({
176
- add: chords[0],
177
- }),
178
- new Pattern({
179
- add: chords[1],
180
- }),
181
- ],
182
- }),
183
- });
184
-
185
- let expressionCount = 0;
186
-
187
- for (let expression of set.expressions) {
188
- let chordCount = 0;
189
-
190
- for (let { chord, duration } of expression) {
191
- expect(chord === chords[expressionCount][chordCount], true);
192
-
193
- ++chordCount;
194
- }
195
-
196
- expect(chordCount, 2);
197
-
198
- ++expressionCount;
199
- }
200
-
201
- expect(expressionCount, 2);
202
- },
203
- },
204
- {
205
- title:
206
- "expressions yields correct results with two schedules containing one pattern each",
207
- test: () => {
208
- const chords = [
209
- [
210
- new Chord({ add: Instruments.Snare }),
211
- new Chord({ add: Instruments.Bass1 }),
212
- ],
213
- [
214
- new Chord({ add: Instruments.Claves }),
215
- new Chord({ add: Instruments.Crash }),
216
- ],
217
- ];
218
-
219
- const set = new Schema({
220
- add: [
221
- new Schedule({
222
- add: [
223
- new Pattern({
224
- add: chords[0],
225
- }),
226
- ],
227
- }),
228
- new Schedule({
229
- add: [
230
- new Pattern({
231
- add: chords[1],
232
- }),
233
- ],
234
- }),
235
- ],
236
- });
237
-
238
- let expressionCount = 0;
239
-
240
- for (let expression of set.expressions) {
241
- let chordCount = 0;
242
-
243
- for (let { chord, duration } of expression) {
244
- expect(
245
- chord === chords[Math.floor(chordCount / 2)][chordCount % 2],
246
- true
247
- );
248
-
249
- ++chordCount;
250
- }
251
-
252
- expect(chordCount, 4);
253
-
254
- ++expressionCount;
255
- }
256
-
257
- expect(expressionCount, 1);
258
- },
259
- },
260
- {
261
- title:
262
- "expressions yields correct results with two schedules containing two patterns each",
263
- test: () => {
264
- const chords = [
265
- [
266
- new Chord({ add: Instruments.Snare }),
267
- new Chord({ add: Instruments.Bass1 }),
268
- ],
269
- [
270
- new Chord({ add: Instruments.Claves }),
271
- new Chord({ add: Instruments.Crash }),
272
- ],
273
- [
274
- new Chord({ add: Instruments.Casaba}),
275
- new Chord({ add: Instruments.China }),
276
- ],
277
- [
278
- new Chord({ add: Instruments.HandClap }),
279
- new Chord({ add: Instruments.HighHat }),
280
- ],
281
- ];
282
-
283
- const set = new Schema({
284
- add: [
285
- new Schedule({
286
- add: [
287
- new Pattern({
288
- add: chords[0],
289
- }),
290
- new Pattern({
291
- add: chords[1],
292
- }),
293
- ],
294
- }),
295
- new Schedule({
296
- add: [
297
- new Pattern({
298
- add: chords[2],
299
- }),
300
- new Pattern({
301
- add: chords[3],
302
- }),
303
- ],
304
- }),
305
- ],
306
- });
307
-
308
- let expressionCount = 0;
309
-
310
- for (let expression of set.expressions) {
311
- let chordCount = 0;
312
-
313
- for (let { chord, duration } of expression) {
314
- const index = chordCount < 2 ? Math.floor(expressionCount / 2) : expressionCount % 2 + 2;
315
-
316
- expect(
317
- chord === chords[index][chordCount % 2],
318
- true
319
- );
320
-
321
- ++chordCount;
322
- }
323
-
324
- expect(chordCount, 4);
325
-
326
- ++expressionCount;
327
- }
328
-
329
- expect(expressionCount, 4);
330
- },
331
- },
332
- ],
333
- };