discombobulator 1.0.0 → 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.
- package/package.json +2 -2
- package/src/test/articulation.mjs +0 -66
- package/src/test/articulationset.mjs +0 -43
- package/src/test/binaryoperator.mjs +0 -210
- package/src/test/chord.mjs +0 -292
- package/src/test/concolour.mjs +0 -70
- package/src/test/difference.mjs +0 -492
- package/src/test/element.mjs +0 -66
- package/src/test/group.mjs +0 -79
- package/src/test/groupset.mjs +0 -43
- package/src/test/instrument.mjs +0 -66
- package/src/test/instrumentset.mjs +0 -43
- package/src/test/intersection.mjs +0 -493
- package/src/test/irregulargroupset.mjs +0 -461
- package/src/test/note.mjs +0 -367
- package/src/test/noteset.mjs +0 -43
- package/src/test/operator.mjs +0 -63
- package/src/test/pattern.mjs +0 -113
- package/src/test/patternset.mjs +0 -43
- package/src/test/patternsource.mjs +0 -43
- package/src/test/regulargroupset.mjs +0 -290
- package/src/test/repl.mjs +0 -63
- package/src/test/replinit.mjs +0 -134
- package/src/test/rotation.mjs +0 -753
- package/src/test/schedule.mjs +0 -275
- package/src/test/schema.mjs +0 -333
- package/src/test/set.mjs +0 -1081
- package/src/test/symmetricdifference.mjs +0 -495
- package/src/test/test.mjs +0 -208
- package/src/test/testing.mjs +0 -63
- package/src/test/union.mjs +0 -495
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
// irregulargroupset.mjs
|
|
2
|
-
//
|
|
3
|
-
// Tests for irregulargroupset.mjs.
|
|
4
|
-
|
|
5
|
-
import { expect, expectException } from "./testing.mjs";
|
|
6
|
-
|
|
7
|
-
import { bitCount } from "../util.mjs";
|
|
8
|
-
|
|
9
|
-
import { combinations, ithBinaryCombination } from "../permute.mjs";
|
|
10
|
-
|
|
11
|
-
import { IrregularGroupSet } from "../irregulargroupset.mjs";
|
|
12
|
-
import { Group } from "../group.mjs";
|
|
13
|
-
|
|
14
|
-
const quickIteratorTestGroupSizeMax = 20;
|
|
15
|
-
const quickElementAtTestGroupSizeMax = 20;
|
|
16
|
-
const quickHasTestGroupSizeMax = 20;
|
|
17
|
-
|
|
18
|
-
function testIterator(groupSizeMax) {
|
|
19
|
-
const actualMax = (groupSet, length) => {
|
|
20
|
-
return Math.max(
|
|
21
|
-
groupSet.min,
|
|
22
|
-
groupSet.max === undefined
|
|
23
|
-
? length
|
|
24
|
-
: groupSet.reverseMax
|
|
25
|
-
? length - groupSet.max
|
|
26
|
-
: Math.min(length, groupSet.max)
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
for (let stepping = 1; stepping <= Group.MAX_LENGTH; ++stepping) {
|
|
31
|
-
const set = new IrregularGroupSet({
|
|
32
|
-
start: 1,
|
|
33
|
-
end: groupSizeMax,
|
|
34
|
-
step: 1,
|
|
35
|
-
min: 1,
|
|
36
|
-
max: undefined,
|
|
37
|
-
stepping: stepping,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
let size = 0;
|
|
41
|
-
|
|
42
|
-
for (let length = set.start; length <= set.end; length += set.step) {
|
|
43
|
-
let max = actualMax(set, length);
|
|
44
|
-
|
|
45
|
-
for (let active = set.min; active <= max; active += set.stepping) {
|
|
46
|
-
size += combinations(length, active);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
expect(set.size, size);
|
|
51
|
-
|
|
52
|
-
let length = set.start;
|
|
53
|
-
let active = set.min;
|
|
54
|
-
let index = 0;
|
|
55
|
-
let test;
|
|
56
|
-
let count = 0;
|
|
57
|
-
|
|
58
|
-
let max = actualMax(set, length);
|
|
59
|
-
|
|
60
|
-
for (let group of set) {
|
|
61
|
-
test = ithBinaryCombination(length, active, index++);
|
|
62
|
-
|
|
63
|
-
while (test === undefined) {
|
|
64
|
-
active += set.stepping;
|
|
65
|
-
index = 0;
|
|
66
|
-
|
|
67
|
-
if (active > max) {
|
|
68
|
-
length += set.step;
|
|
69
|
-
|
|
70
|
-
if (length > set.end) {
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
max = actualMax(set, length);
|
|
75
|
-
active = set.min;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
test = ithBinaryCombination(length, active, index++);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (length > set.end) {
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
expect(group.group, test);
|
|
86
|
-
|
|
87
|
-
++count;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
expect(count, set.size);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function testElementAt(groupSize) {
|
|
95
|
-
for (let stepping = 1; stepping <= Group.MAX_LENGTH; ++stepping) {
|
|
96
|
-
const set = new IrregularGroupSet({
|
|
97
|
-
start: 1,
|
|
98
|
-
end: groupSize,
|
|
99
|
-
step: 1,
|
|
100
|
-
min: 1,
|
|
101
|
-
max: undefined,
|
|
102
|
-
stepping: stepping,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
let index = 0;
|
|
106
|
-
let elementAt;
|
|
107
|
-
|
|
108
|
-
for (let group of set) {
|
|
109
|
-
elementAt = set.elementAt(index++);
|
|
110
|
-
expect(elementAt.group === group.group, true);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
expect(index, set.size);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function testHas(groupSize) {
|
|
118
|
-
for (let stepping = 1; stepping < Group.MAX_LENGTH; ++stepping) {
|
|
119
|
-
let set = new IrregularGroupSet({
|
|
120
|
-
start: 1,
|
|
121
|
-
end: groupSize,
|
|
122
|
-
step: 1,
|
|
123
|
-
min: 1,
|
|
124
|
-
max: undefined,
|
|
125
|
-
stepping: stepping,
|
|
126
|
-
});
|
|
127
|
-
let other;
|
|
128
|
-
|
|
129
|
-
for (let length = 1; length < set.end; length += set.step) {
|
|
130
|
-
const upperLimit = 1 << length;
|
|
131
|
-
|
|
132
|
-
for (let group = 1; group < upperLimit; ++group) {
|
|
133
|
-
const active = bitCount(group);
|
|
134
|
-
|
|
135
|
-
if (((active-1) % set.stepping) === 0) {
|
|
136
|
-
other = new Group(group, length);
|
|
137
|
-
|
|
138
|
-
expect(set.has(other), true);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export const test = {
|
|
146
|
-
tests: [
|
|
147
|
-
{
|
|
148
|
-
title: "default constructor results in correct set",
|
|
149
|
-
test: () => {
|
|
150
|
-
let set = new IrregularGroupSet();
|
|
151
|
-
|
|
152
|
-
expect(set.isAbstract, true);
|
|
153
|
-
expect(set.allowDuplicates, false);
|
|
154
|
-
expect(set.size, 1);
|
|
155
|
-
expect(set.start, 1);
|
|
156
|
-
expect(set.end, 1);
|
|
157
|
-
expect(set.step, 1);
|
|
158
|
-
expect(set.min, 1);
|
|
159
|
-
expect(() => {
|
|
160
|
-
return set.max === undefined;
|
|
161
|
-
}, true);
|
|
162
|
-
expect(set.stepping, 1);
|
|
163
|
-
expect(set.reverseMax, false);
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
title: "constructor throws error when min < 1",
|
|
168
|
-
test: () => {
|
|
169
|
-
let set;
|
|
170
|
-
|
|
171
|
-
expectException(() => {
|
|
172
|
-
set = new IrregularGroupSet({ min: 0 });
|
|
173
|
-
}, Error);
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
title: `constructor throws error when max is defined but less than min > ${Group.MAX_LENGTH}`,
|
|
178
|
-
test: () => {
|
|
179
|
-
let set;
|
|
180
|
-
|
|
181
|
-
expectException(() => {
|
|
182
|
-
set = new IrregularGroupSet({ min: 2, max: 1 });
|
|
183
|
-
}, Error);
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
title: "constructor throws error when stepping < 1",
|
|
188
|
-
test: () => {
|
|
189
|
-
let set;
|
|
190
|
-
|
|
191
|
-
expectException(() => {
|
|
192
|
-
set = new IrregularGroupSet({ stepping: 0 });
|
|
193
|
-
}, Error);
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
title: `constructor throws error when stepping > ${Group.MAX_LENGTH}`,
|
|
198
|
-
test: () => {
|
|
199
|
-
let set;
|
|
200
|
-
|
|
201
|
-
expectException(() => {
|
|
202
|
-
set = new IrregularGroupSet({ stepping: Group.MAX_LENGTH + 1 });
|
|
203
|
-
}, Error);
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
title: `constructor succeeds when stepping in [1..${Group.MAX_LENGTH}]`,
|
|
208
|
-
test: () => {
|
|
209
|
-
let set;
|
|
210
|
-
|
|
211
|
-
for (let value = 1; value <= Group.MAX_LENGTH; ++value) {
|
|
212
|
-
set = new IrregularGroupSet({ stepping: value });
|
|
213
|
-
expect(set.stepping, value);
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
title: "clone correctly clones set",
|
|
220
|
-
test: () => {
|
|
221
|
-
const set = new IrregularGroupSet({
|
|
222
|
-
start: 1,
|
|
223
|
-
end: 2,
|
|
224
|
-
step: 3,
|
|
225
|
-
min: 4,
|
|
226
|
-
max: 5,
|
|
227
|
-
stepping: 6,
|
|
228
|
-
});
|
|
229
|
-
const clone = set.clone();
|
|
230
|
-
|
|
231
|
-
expect(clone !== undefined, true);
|
|
232
|
-
expect(clone.start, 1);
|
|
233
|
-
expect(clone.end, 2);
|
|
234
|
-
expect(clone.step, 3);
|
|
235
|
-
expect(clone.min, 4);
|
|
236
|
-
expect(clone.max, 5);
|
|
237
|
-
expect(clone.stepping, 6);
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
{
|
|
242
|
-
title: `iterator correctly returns groups with group size in [1..${quickIteratorTestGroupSizeMax}] (Quick)`,
|
|
243
|
-
test: () => {
|
|
244
|
-
testIterator(quickIteratorTestGroupSizeMax);
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
title: `iterator correctly returns groups with stepping in [1..${Group.MAX_LENGTH}] (Exhaustive)`,
|
|
249
|
-
slow: true,
|
|
250
|
-
test: () => {
|
|
251
|
-
testIterator(Group.MAX_LENGTH);
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
{
|
|
256
|
-
title: "elementAt throws error for index < 0",
|
|
257
|
-
test: () => {
|
|
258
|
-
let set = new IrregularGroupSet();
|
|
259
|
-
|
|
260
|
-
expectException(() => {
|
|
261
|
-
set.elementAt(-1);
|
|
262
|
-
}, Error);
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
title: "elementAt throws error for index higher than set size",
|
|
267
|
-
test: () => {
|
|
268
|
-
let set = new IrregularGroupSet({ start: 1, end: 1, step: 1 });
|
|
269
|
-
|
|
270
|
-
expect(set.size, 1);
|
|
271
|
-
|
|
272
|
-
expectException(() => {
|
|
273
|
-
set.elementAt(1);
|
|
274
|
-
}, Error);
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
title: `elementAt correctly returns groups with group size in [1..${quickElementAtTestGroupSizeMax}] (Quick)`,
|
|
279
|
-
test: () => {
|
|
280
|
-
testElementAt(quickElementAtTestGroupSizeMax);
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
title: `elementAt correctly returns groups with step in [1..${Group.MAX_LENGTH}] (Exhaustive)`,
|
|
285
|
-
slow: true,
|
|
286
|
-
test: () => {
|
|
287
|
-
testElementAt(Group.MAX_LENGTH);
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
|
|
291
|
-
{
|
|
292
|
-
title: "has throws error when argument is undefined",
|
|
293
|
-
test: () => {
|
|
294
|
-
let set = new IrregularGroupSet();
|
|
295
|
-
|
|
296
|
-
expectException(() => {
|
|
297
|
-
set.has();
|
|
298
|
-
}, Error);
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
title: "has throws error when argument is not a group",
|
|
303
|
-
test: () => {
|
|
304
|
-
let set = new IrregularGroupSet();
|
|
305
|
-
|
|
306
|
-
expectException(() => {
|
|
307
|
-
set.has(Instruments.Snare);
|
|
308
|
-
}, Error);
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
title: "has fails for group smaller than smallest in set",
|
|
313
|
-
test: () => {
|
|
314
|
-
let set = new IrregularGroupSet({ start: 2, end: 2, step: 1 });
|
|
315
|
-
let other = new Group(1, 1);
|
|
316
|
-
|
|
317
|
-
expect(set.has(other), false);
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
title: "has fails for group larger than largest in set",
|
|
322
|
-
test: () => {
|
|
323
|
-
let set = new IrregularGroupSet({ start: 2, end: 2, step: 1 });
|
|
324
|
-
let other = new Group(7, 3);
|
|
325
|
-
|
|
326
|
-
expect(set.has(other), false);
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
title: "has fails for group with fewer active chords than exist in set",
|
|
331
|
-
test: () => {
|
|
332
|
-
let set = new IrregularGroupSet({
|
|
333
|
-
start: 2,
|
|
334
|
-
end: 2,
|
|
335
|
-
step: 1,
|
|
336
|
-
min: 2,
|
|
337
|
-
max: 2,
|
|
338
|
-
stepping: 1,
|
|
339
|
-
});
|
|
340
|
-
let other = new Group(1, 2);
|
|
341
|
-
|
|
342
|
-
expect(set.has(other), false);
|
|
343
|
-
},
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
title: "has fails for group with more active chords than exist in set",
|
|
347
|
-
test: () => {
|
|
348
|
-
let set = new IrregularGroupSet({
|
|
349
|
-
start: 3,
|
|
350
|
-
end: 3,
|
|
351
|
-
step: 1,
|
|
352
|
-
min: 2,
|
|
353
|
-
max: 2,
|
|
354
|
-
stepping: 1,
|
|
355
|
-
});
|
|
356
|
-
let other = new Group(7, 3);
|
|
357
|
-
|
|
358
|
-
expect(set.has(other), false);
|
|
359
|
-
},
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
title: "has fails for groups with length missed by step",
|
|
363
|
-
test: () => {
|
|
364
|
-
for (let step = 1; step <= Group.MAX_LENGTH; ++step) {
|
|
365
|
-
let set = new IrregularGroupSet({
|
|
366
|
-
start: 1,
|
|
367
|
-
end: Group.MAX_LENGTH,
|
|
368
|
-
step: step,
|
|
369
|
-
min: 1,
|
|
370
|
-
max: undefined,
|
|
371
|
-
stepping: 1,
|
|
372
|
-
});
|
|
373
|
-
let other;
|
|
374
|
-
|
|
375
|
-
for (let length = 1; length < set.end; length += set.step) {
|
|
376
|
-
if (((length-1) % set.step) !== 0) {
|
|
377
|
-
other = new Group(1, length);
|
|
378
|
-
|
|
379
|
-
expect(set.has(other), false);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
},
|
|
385
|
-
{
|
|
386
|
-
title: "has fails for groups with active chords missed by stepping (Quick)",
|
|
387
|
-
test: () => {
|
|
388
|
-
for (let stepping = 2; stepping < Group.MAX_LENGTH; ++stepping) {
|
|
389
|
-
let set = new IrregularGroupSet({
|
|
390
|
-
start: 2,
|
|
391
|
-
end: quickHasTestGroupSizeMax,
|
|
392
|
-
step: 1,
|
|
393
|
-
min: 1,
|
|
394
|
-
max: undefined,
|
|
395
|
-
stepping: stepping,
|
|
396
|
-
});
|
|
397
|
-
let other;
|
|
398
|
-
|
|
399
|
-
for (let length = 2; length < set.end; length += set.step) {
|
|
400
|
-
const upperLimit = 1 << length;
|
|
401
|
-
|
|
402
|
-
for (let group = 1; group < upperLimit; ++group) {
|
|
403
|
-
const active = bitCount(group);
|
|
404
|
-
|
|
405
|
-
if (((active-1) % set.stepping) !== 0) {
|
|
406
|
-
other = new Group(group, length);
|
|
407
|
-
|
|
408
|
-
expect(set.has(other), false);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
},
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
title: "has fails for groups with active chords missed by stepping (Exhaustive)",
|
|
417
|
-
slow: true,
|
|
418
|
-
test: () => {
|
|
419
|
-
for (let stepping = 2; stepping < Group.MAX_LENGTH; ++stepping) {
|
|
420
|
-
let set = new IrregularGroupSet({
|
|
421
|
-
start: 2,
|
|
422
|
-
end: Group.MAX_LENGTH,
|
|
423
|
-
step: 1,
|
|
424
|
-
min: 1,
|
|
425
|
-
max: undefined,
|
|
426
|
-
stepping: stepping,
|
|
427
|
-
});
|
|
428
|
-
let other;
|
|
429
|
-
|
|
430
|
-
for (let length = 2; length < set.end; length += set.step) {
|
|
431
|
-
const upperLimit = 1 << length;
|
|
432
|
-
|
|
433
|
-
for (let group = 1; group < upperLimit; ++group) {
|
|
434
|
-
const active = bitCount(group);
|
|
435
|
-
|
|
436
|
-
if (((active-1) % set.stepping) !== 0) {
|
|
437
|
-
other = new Group(group, length);
|
|
438
|
-
|
|
439
|
-
expect(set.has(other), false);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
},
|
|
445
|
-
},
|
|
446
|
-
{
|
|
447
|
-
title: "has succeeds for groups with active chords hit by stepping (Quick)",
|
|
448
|
-
// slow: true,
|
|
449
|
-
test: () => {
|
|
450
|
-
testHas(quickHasTestGroupSizeMax);
|
|
451
|
-
},
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
title: "has succeeds for groups with active chords hit by stepping (Exhaustive)",
|
|
455
|
-
slow: true,
|
|
456
|
-
test: () => {
|
|
457
|
-
testHas(Group.MAX_LENGTH);
|
|
458
|
-
},
|
|
459
|
-
},
|
|
460
|
-
],
|
|
461
|
-
};
|