discombobulator 1.0.0
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 +16 -0
- package/src/articulation.mjs +61 -0
- package/src/articulationset.mjs +20 -0
- package/src/chord.mjs +82 -0
- package/src/cross.mjs +133 -0
- package/src/disco.mjs +14 -0
- package/src/element.mjs +51 -0
- package/src/group.mjs +70 -0
- package/src/groupset.mjs +259 -0
- package/src/instrument.mjs +105 -0
- package/src/instrumentset.mjs +20 -0
- package/src/irregulargroupset.mjs +224 -0
- package/src/note.mjs +155 -0
- package/src/noteset.mjs +21 -0
- package/src/pattern.mjs +52 -0
- package/src/patternset.mjs +20 -0
- package/src/patternsource.mjs +21 -0
- package/src/permute.mjs +63 -0
- package/src/regulargroupset.mjs +120 -0
- package/src/schedule.mjs +88 -0
- package/src/schema.mjs +108 -0
- package/src/set.mjs +1159 -0
- package/src/test/articulation.mjs +66 -0
- package/src/test/articulationset.mjs +43 -0
- package/src/test/binaryoperator.mjs +210 -0
- package/src/test/chord.mjs +292 -0
- package/src/test/concolour.mjs +70 -0
- package/src/test/difference.mjs +492 -0
- package/src/test/element.mjs +66 -0
- package/src/test/group.mjs +79 -0
- package/src/test/groupset.mjs +43 -0
- package/src/test/instrument.mjs +66 -0
- package/src/test/instrumentset.mjs +43 -0
- package/src/test/intersection.mjs +493 -0
- package/src/test/irregulargroupset.mjs +461 -0
- package/src/test/note.mjs +367 -0
- package/src/test/noteset.mjs +43 -0
- package/src/test/operator.mjs +63 -0
- package/src/test/pattern.mjs +113 -0
- package/src/test/patternset.mjs +43 -0
- package/src/test/patternsource.mjs +43 -0
- package/src/test/regulargroupset.mjs +290 -0
- package/src/test/repl.mjs +63 -0
- package/src/test/replinit.mjs +134 -0
- package/src/test/rotation.mjs +753 -0
- package/src/test/schedule.mjs +275 -0
- package/src/test/schema.mjs +333 -0
- package/src/test/set.mjs +1081 -0
- package/src/test/symmetricdifference.mjs +495 -0
- package/src/test/test.mjs +208 -0
- package/src/test/testing.mjs +63 -0
- package/src/test/union.mjs +495 -0
- package/src/util.mjs +21 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
// difference.mjs
|
|
2
|
+
//
|
|
3
|
+
// Tests for difference.mjs.
|
|
4
|
+
|
|
5
|
+
import { expect, expectException } from "./testing.mjs";
|
|
6
|
+
|
|
7
|
+
import { Instruments } from "../instrument.mjs";
|
|
8
|
+
import { Set } from "../set.mjs";
|
|
9
|
+
import { InstrumentSet } from "../instrumentset.mjs";
|
|
10
|
+
|
|
11
|
+
export const test = {
|
|
12
|
+
tests: [
|
|
13
|
+
{
|
|
14
|
+
title: "default constructor results in correct set",
|
|
15
|
+
test: () => {
|
|
16
|
+
const set1 = new InstrumentSet();
|
|
17
|
+
const set2 = new InstrumentSet();
|
|
18
|
+
|
|
19
|
+
let operator = new Set.Difference(set1, set2);
|
|
20
|
+
|
|
21
|
+
expect(operator.isAbstract, true);
|
|
22
|
+
expect(operator.allowDuplicates, false);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
title: "add element fails because difference is an immutable set",
|
|
28
|
+
test: () => {
|
|
29
|
+
const set1 = new InstrumentSet();
|
|
30
|
+
const set2 = new InstrumentSet();
|
|
31
|
+
|
|
32
|
+
let operator = new Set.Difference(set1, set2);
|
|
33
|
+
|
|
34
|
+
expectException(() => {
|
|
35
|
+
operator.add(Instruments.Snare);
|
|
36
|
+
}, Error);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
title: "iterator yields nothing for an empty set",
|
|
42
|
+
test: () => {
|
|
43
|
+
const set1 = new InstrumentSet({ add: Instruments.Snare });
|
|
44
|
+
const set2 = new InstrumentSet({ add: Instruments.Snare });
|
|
45
|
+
|
|
46
|
+
const operator = new Set.Difference(set1, set2);
|
|
47
|
+
|
|
48
|
+
let count = 0;
|
|
49
|
+
|
|
50
|
+
for (const e of operator) { ++count; }
|
|
51
|
+
|
|
52
|
+
expect(count, 0);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
title: "iterator yields correct results for a non-empty set",
|
|
57
|
+
test: () => {
|
|
58
|
+
const instruments = [
|
|
59
|
+
Instruments.Snare,
|
|
60
|
+
Instruments.Crash,
|
|
61
|
+
Instruments.Claves,
|
|
62
|
+
Instruments.Bass1,
|
|
63
|
+
];
|
|
64
|
+
const set1 = new InstrumentSet({
|
|
65
|
+
add: instruments,
|
|
66
|
+
});
|
|
67
|
+
const set2 = new InstrumentSet({
|
|
68
|
+
add: [Instruments.Snare, Instruments.Bass1],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const operator = new Set.Difference(set1, set2);
|
|
72
|
+
let count = 0;
|
|
73
|
+
|
|
74
|
+
for (const e of operator) {
|
|
75
|
+
expect(e, (result) => { return result === instruments[1+count++]; });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
expect(count, 2);
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
{
|
|
83
|
+
title: "size returns correct size with no different elements",
|
|
84
|
+
test: () => {
|
|
85
|
+
const set1 = new InstrumentSet({ add: Instruments.Snare });
|
|
86
|
+
const set2 = new InstrumentSet({ add: Instruments.Snare });
|
|
87
|
+
|
|
88
|
+
const operator = new Set.Difference(set1, set2);
|
|
89
|
+
|
|
90
|
+
expect(operator.size === 0, true);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
title: "size returns correct size with a single different element",
|
|
95
|
+
test: () => {
|
|
96
|
+
const set1 = new InstrumentSet({
|
|
97
|
+
add: [Instruments.Snare, Instruments.Bass1],
|
|
98
|
+
});
|
|
99
|
+
const set2 = new InstrumentSet({ add: Instruments.Snare });
|
|
100
|
+
|
|
101
|
+
const operator = new Set.Difference(set1, set2);
|
|
102
|
+
|
|
103
|
+
expect(operator.size === 1, true);
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
title: "size returns correct size with multiple different elements",
|
|
108
|
+
test: () => {
|
|
109
|
+
const set1 = new InstrumentSet({
|
|
110
|
+
add: [
|
|
111
|
+
Instruments.Snare,
|
|
112
|
+
Instruments.Crash,
|
|
113
|
+
Instruments.Claves,
|
|
114
|
+
Instruments.Bass1,
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
const set2 = new InstrumentSet({
|
|
118
|
+
add: [Instruments.Snare, Instruments.Bass1],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const operator = new Set.Difference(set1, set2);
|
|
122
|
+
|
|
123
|
+
expect(operator.size === 2, true);
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
{
|
|
128
|
+
title: "has fails when empty",
|
|
129
|
+
test: () => {
|
|
130
|
+
const set1 = new InstrumentSet({ add: Instruments.Snare });
|
|
131
|
+
const set2 = new InstrumentSet({ add: Instruments.Snare });
|
|
132
|
+
|
|
133
|
+
const operator = new Set.Difference(set1, set2);
|
|
134
|
+
|
|
135
|
+
expect(operator.size === 0, true);
|
|
136
|
+
expect(operator.has(Instruments.Snare), false);
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
title: "has succeeds for element that is in difference",
|
|
141
|
+
test: () => {
|
|
142
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Bass1 ] });
|
|
143
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Bass1 ] });
|
|
144
|
+
|
|
145
|
+
const operator = new Set.Difference(set1, set2);
|
|
146
|
+
|
|
147
|
+
expect(operator.size === 1, true);
|
|
148
|
+
expect(operator.has(Instruments.Snare), true);
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
title: "has fails for element that is not in difference",
|
|
153
|
+
test: () => {
|
|
154
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Bass1 ] });
|
|
155
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Bass1 ] });
|
|
156
|
+
|
|
157
|
+
const operator = new Set.Difference(set1, set2);
|
|
158
|
+
|
|
159
|
+
expect(operator.size === 1, true);
|
|
160
|
+
expect(operator.has(Instruments.Bass1), false);
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
title: "has succeeds for set that is in difference",
|
|
165
|
+
test: () => {
|
|
166
|
+
let subset = new InstrumentSet({ add: [ Instruments.Bass1, Instruments.Snare ]});
|
|
167
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
168
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
169
|
+
|
|
170
|
+
const operator = new Set.Difference(set1, set2);
|
|
171
|
+
|
|
172
|
+
expect(operator.size === 2, true);
|
|
173
|
+
expect(operator.has(subset), true);
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
title: "has fails for other set that is not in difference",
|
|
178
|
+
test: () => {
|
|
179
|
+
let subset = new InstrumentSet({ add: [ Instruments.Claves, Instruments.Crash ]});
|
|
180
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
181
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
182
|
+
|
|
183
|
+
const operator = new Set.Difference(set1, set2);
|
|
184
|
+
|
|
185
|
+
expect(operator.size === 2, true);
|
|
186
|
+
expect(operator.has(subset), false);
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
{
|
|
191
|
+
title: "indexOf throws error for undefined element",
|
|
192
|
+
test: () => {
|
|
193
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
194
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
195
|
+
|
|
196
|
+
const operator = new Set.Difference(set1, set2);
|
|
197
|
+
|
|
198
|
+
expect(operator.size === 2, true);
|
|
199
|
+
expectException(() => { operator.indexOf(); }, Error);
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
title: "indexOf throws error for argument not derived from Element",
|
|
204
|
+
test: () => {
|
|
205
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
206
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
207
|
+
|
|
208
|
+
const operator = new Set.Difference(set1, set2);
|
|
209
|
+
|
|
210
|
+
expect(operator.size === 2, true);
|
|
211
|
+
expectException(() => { operator.indexOf(new Error()); }, Error);
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
title: "indexOf fails to find non-existant element",
|
|
216
|
+
test: () => {
|
|
217
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
218
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
219
|
+
|
|
220
|
+
const operator = new Set.Difference(set1, set2);
|
|
221
|
+
|
|
222
|
+
expect(operator.size === 2, true);
|
|
223
|
+
expect(operator.indexOf(Instruments.Claves), -1);
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
title: "indexOf fails for empty set",
|
|
228
|
+
test: () => {
|
|
229
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Claves, Instruments.Crash ] });
|
|
230
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
231
|
+
|
|
232
|
+
const operator = new Set.Difference(set1, set2);
|
|
233
|
+
|
|
234
|
+
expect(operator.size === 0, true);
|
|
235
|
+
expect(operator.indexOf(Instruments.Bass1), -1);
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
title: "indexOf succeeds for element in the set",
|
|
240
|
+
test: () => {
|
|
241
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
242
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
243
|
+
|
|
244
|
+
const operator = new Set.Difference(set1, set2);
|
|
245
|
+
|
|
246
|
+
expect(operator.size === 2, true);
|
|
247
|
+
expect(operator.indexOf(Instruments.Snare), 0);
|
|
248
|
+
expect(operator.indexOf(Instruments.Bass1), 1);
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
title: "indexOf fails for element in the set prior to after",
|
|
253
|
+
test: () => {
|
|
254
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
255
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
256
|
+
|
|
257
|
+
const operator = new Set.Difference(set1, set2);
|
|
258
|
+
|
|
259
|
+
expect(operator.size === 2, true);
|
|
260
|
+
expect(operator.indexOf(Instruments.Snare, 0), -1);
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
title: "indexOf succeeds for element in the set later than after",
|
|
265
|
+
test: () => {
|
|
266
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
267
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
268
|
+
|
|
269
|
+
const operator = new Set.Difference(set1, set2);
|
|
270
|
+
|
|
271
|
+
expect(operator.size === 2, true);
|
|
272
|
+
expect(operator.indexOf(Instruments.Bass1, 0), 1);
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
title: "indexOf fails if after >= size-1",
|
|
277
|
+
test: () => {
|
|
278
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
279
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
280
|
+
|
|
281
|
+
const operator = new Set.Difference(set1, set2);
|
|
282
|
+
|
|
283
|
+
expect(operator.size === 2, true);
|
|
284
|
+
expect(operator.indexOf(Instruments.Bass1, 1), -1);
|
|
285
|
+
expect(operator.indexOf(Instruments.Bass1, 2), -1);
|
|
286
|
+
expect(operator.indexOf(Instruments.Bass1, 3), -1);
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
{
|
|
291
|
+
title: "elementAt throws error for index < 0",
|
|
292
|
+
test: () => {
|
|
293
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
294
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
295
|
+
|
|
296
|
+
const operator = new Set.Difference(set1, set2);
|
|
297
|
+
|
|
298
|
+
expect(operator.size === 2, true);
|
|
299
|
+
expectException(() => { operator.elementAt(-1); }, Error);
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
title: "elementAt throws error for empty set",
|
|
304
|
+
test: () => {
|
|
305
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Claves ] });
|
|
306
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
307
|
+
|
|
308
|
+
const operator = new Set.Difference(set1, set2);
|
|
309
|
+
|
|
310
|
+
expect(operator.size === 0, true);
|
|
311
|
+
expectException(() => { operator.elementAt(0); }, Error);
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
title: "elementAt throws error for index >= set size",
|
|
316
|
+
test: () => {
|
|
317
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
318
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
319
|
+
|
|
320
|
+
const operator = new Set.Difference(set1, set2);
|
|
321
|
+
|
|
322
|
+
expect(operator.size === 2, true);
|
|
323
|
+
expectException(() => { operator.elementAt(2); }, Error);
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
title: "elementAt succeeds for element in valid index",
|
|
328
|
+
test: () => {
|
|
329
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
330
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
331
|
+
|
|
332
|
+
const operator = new Set.Difference(set1, set2);
|
|
333
|
+
|
|
334
|
+
expect(operator.size === 2, true);
|
|
335
|
+
expect(operator.elementAt(0), (result) => { return result === Instruments.Snare; });
|
|
336
|
+
expect(operator.elementAt(1), (result) => { return result === Instruments.Bass1; });
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
{
|
|
341
|
+
title: "clone succeeds a difference operator (Shallow)",
|
|
342
|
+
test: () => {
|
|
343
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
344
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
345
|
+
|
|
346
|
+
const operator = new Set.Difference(set1, set2);
|
|
347
|
+
|
|
348
|
+
expect(operator.size === 2, true);
|
|
349
|
+
|
|
350
|
+
const clone = operator.clone();
|
|
351
|
+
|
|
352
|
+
expect(clone.isAbstract, true);
|
|
353
|
+
expect(clone.allowDuplicates, false);
|
|
354
|
+
expect(clone.isStrict, true);
|
|
355
|
+
expect(clone.skipValidation, false);
|
|
356
|
+
expect(clone.elements[0] === set1, true);
|
|
357
|
+
expect(clone.elements[1] === set2, true);
|
|
358
|
+
|
|
359
|
+
let index = 0;
|
|
360
|
+
|
|
361
|
+
for (let e of operator) {
|
|
362
|
+
expect(e.isEqual(clone.elementAt(index++)), true);
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
title: "clone succeeds on a difference operator (Deep)",
|
|
368
|
+
test: () => {
|
|
369
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
370
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
371
|
+
|
|
372
|
+
const operator = new Set.Difference(set1, set2);
|
|
373
|
+
|
|
374
|
+
expect(operator.size === 2, true);
|
|
375
|
+
|
|
376
|
+
const clone = operator.clone(true);
|
|
377
|
+
|
|
378
|
+
expect(clone.isAbstract, true);
|
|
379
|
+
expect(clone.allowDuplicates, false);
|
|
380
|
+
expect(clone.isStrict, true);
|
|
381
|
+
expect(clone.skipValidation, false);
|
|
382
|
+
expect(clone.elements[0] !== set1, true);
|
|
383
|
+
expect(clone.elements[1] !== set2, true);
|
|
384
|
+
|
|
385
|
+
let index = 0;
|
|
386
|
+
|
|
387
|
+
for (let e of operator) {
|
|
388
|
+
expect(e.isEqual(clone.elementAt(index++)), true);
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
{
|
|
394
|
+
title: "isDisjointFrom fails for difference set that is not disjoint from another set",
|
|
395
|
+
test: () => {
|
|
396
|
+
let set = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Crash ]});
|
|
397
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
398
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
399
|
+
|
|
400
|
+
const operator = new Set.Difference(set1, set2);
|
|
401
|
+
|
|
402
|
+
expect(operator.isDisjointFrom(set), false);
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
title: "isDisjointFrom succeeds for difference set that is disjoint from another set",
|
|
407
|
+
test: () => {
|
|
408
|
+
let set = new InstrumentSet({ add: [ Instruments.Claves, Instruments.Crash ]});
|
|
409
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
410
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
411
|
+
|
|
412
|
+
const operator = new Set.Difference(set1, set2);
|
|
413
|
+
|
|
414
|
+
expect(operator.isDisjointFrom(set), true);
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
title: "isDisjointFrom fails for a set that is not disjoint from a difference set",
|
|
419
|
+
test: () => {
|
|
420
|
+
let set = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Crash ]});
|
|
421
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
422
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
423
|
+
|
|
424
|
+
const operator = new Set.Difference(set1, set2);
|
|
425
|
+
|
|
426
|
+
expect(set.isDisjointFrom(operator), false);
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
title: "isDisjointFrom succeeds for a set that is disjoint from a difference set",
|
|
431
|
+
test: () => {
|
|
432
|
+
let set = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves ]});
|
|
433
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Crash, Instruments.Bass1 ] });
|
|
434
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves ] });
|
|
435
|
+
|
|
436
|
+
const operator = new Set.Difference(set1, set2);
|
|
437
|
+
|
|
438
|
+
expect(set.isDisjointFrom(operator), true);
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
|
|
442
|
+
{
|
|
443
|
+
title: "isSubsetOf fails for difference set that is not a subset of another set",
|
|
444
|
+
test: () => {
|
|
445
|
+
let set = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Crash ]});
|
|
446
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
447
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
448
|
+
|
|
449
|
+
const operator = new Set.Difference(set1, set2);
|
|
450
|
+
|
|
451
|
+
expect(operator.isSubsetOf(set), false);
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
title: "isSubsetOf succeeds for difference set that is subset of another set",
|
|
456
|
+
test: () => {
|
|
457
|
+
let set = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Crash, Instruments.Bass1 ]});
|
|
458
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
459
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
460
|
+
|
|
461
|
+
const operator = new Set.Difference(set1, set2);
|
|
462
|
+
|
|
463
|
+
expect(operator.isSubsetOf(set), true);
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
title: "isSubsetOf fails for a set that is not a subset of a difference set",
|
|
468
|
+
test: () => {
|
|
469
|
+
let set = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Crash ]});
|
|
470
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves, Instruments.Bass1 ] });
|
|
471
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Crash, Instruments.Claves ] });
|
|
472
|
+
|
|
473
|
+
const operator = new Set.Difference(set1, set2);
|
|
474
|
+
|
|
475
|
+
expect(set.isSubsetOf(operator), false);
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
title: "isSubsetOf succeeds for a set that is a subset of a difference set",
|
|
480
|
+
test: () => {
|
|
481
|
+
let set = new InstrumentSet({ add: [ Instruments.Bass1, Instruments.Crash ]});
|
|
482
|
+
let set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Crash, Instruments.Bass1 ] });
|
|
483
|
+
let set2 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Claves ] });
|
|
484
|
+
|
|
485
|
+
const operator = new Set.Difference(set1, set2);
|
|
486
|
+
|
|
487
|
+
expect(set.isSubsetOf(operator), true);
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
],
|
|
492
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// element.mjs
|
|
2
|
+
//
|
|
3
|
+
// Tests for element.mjs.
|
|
4
|
+
|
|
5
|
+
import { expect } from './testing.mjs'
|
|
6
|
+
|
|
7
|
+
import { Element } from '../element.mjs'
|
|
8
|
+
import { Instrument } from '../instrument.mjs'
|
|
9
|
+
|
|
10
|
+
export const test = {
|
|
11
|
+
tests: [
|
|
12
|
+
{
|
|
13
|
+
title: "isEqual succeeds when comparing with self",
|
|
14
|
+
test: () => {
|
|
15
|
+
const element = new Element();
|
|
16
|
+
|
|
17
|
+
expect(element.isEqual(element), true);
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "isEqual succeeds when comparing two different element instances",
|
|
22
|
+
test: () => {
|
|
23
|
+
const element = new Element();
|
|
24
|
+
const other = new Element();
|
|
25
|
+
|
|
26
|
+
expect(element.isEqual(other), true);
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
title: "isEqual fails when comparing against a different (element-derived) class",
|
|
31
|
+
test: () => {
|
|
32
|
+
const element = new Element();
|
|
33
|
+
const other = new Instrument();
|
|
34
|
+
|
|
35
|
+
expect(element.isEqual(other), false);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
{
|
|
40
|
+
title: "promote succeeds for self",
|
|
41
|
+
test: () => {
|
|
42
|
+
const element = new Element();
|
|
43
|
+
|
|
44
|
+
expect(element.promote(element), (result) => { return result === element; });
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: "promote succeeds for two different element instances",
|
|
49
|
+
test: () => {
|
|
50
|
+
const element = new Element();
|
|
51
|
+
const other = new Element();
|
|
52
|
+
|
|
53
|
+
expect(element.promote(other), (result) => { return result === other; });
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: "promote fails for different (element-derived) classes",
|
|
58
|
+
test: () => {
|
|
59
|
+
const element = new Element();
|
|
60
|
+
const other = new Instrument();
|
|
61
|
+
|
|
62
|
+
expect(element.promote(other), (result) => { return result === undefined; });
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// group.mjs
|
|
2
|
+
//
|
|
3
|
+
// Tests for group.mjs.
|
|
4
|
+
|
|
5
|
+
import { expect, expectException } from './testing.mjs'
|
|
6
|
+
|
|
7
|
+
import { Group } from '../group.mjs'
|
|
8
|
+
import { Instrument } from '../instrument.mjs'
|
|
9
|
+
|
|
10
|
+
export const test = {
|
|
11
|
+
tests: [
|
|
12
|
+
{
|
|
13
|
+
title: "default constructor results in Error exception",
|
|
14
|
+
test: () => {
|
|
15
|
+
expectException(() => { new Group(); }, Error);
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: "constructor throws Error when length < 1",
|
|
20
|
+
test: () => {
|
|
21
|
+
expectException(() => { new Group(0); }, Error);
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: `constructor throws Error when length > ${Group.MAX_LENGTH}`,
|
|
26
|
+
test: () => {
|
|
27
|
+
expectException(() => { new Group(Group.MAX_LENGTH); }, Error);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title: `constructor succeeds when length in [1..${Group.MAX_LENGTH}]`,
|
|
32
|
+
test: () => {
|
|
33
|
+
const lengths = [...Array(Group.MAX_LENGTH).keys()];
|
|
34
|
+
|
|
35
|
+
lengths.forEach((length) => {
|
|
36
|
+
const group = new Group(0, length + 1);
|
|
37
|
+
|
|
38
|
+
expect(group.length, length + 1);
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
{
|
|
44
|
+
title: "isEqual succeeds when comparing with self",
|
|
45
|
+
test: () => {
|
|
46
|
+
const group = new Group(1, 1);
|
|
47
|
+
|
|
48
|
+
expect(group.isEqual(group), true);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
title: "isEqual succeeds when comparing identical groups",
|
|
53
|
+
test: () => {
|
|
54
|
+
const group = new Group(1, 1);
|
|
55
|
+
const other = new Group(1, 1);
|
|
56
|
+
|
|
57
|
+
expect(group.isEqual(other), true);
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
title: "isEqual fails when comparing articulations with different symbols",
|
|
62
|
+
test: () => {
|
|
63
|
+
const group = new Group(1, 1);
|
|
64
|
+
const other = new Group(3, 2);
|
|
65
|
+
|
|
66
|
+
expect(group.isEqual(other), false);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
title: "isEqual fails when comparing against a non-group class",
|
|
71
|
+
test: () => {
|
|
72
|
+
const group = new Group(1, 1);
|
|
73
|
+
const other = new Instrument();
|
|
74
|
+
|
|
75
|
+
expect(group.isEqual(other), false);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// groupset.mjs
|
|
2
|
+
//
|
|
3
|
+
// Tests for groupset.mjs.
|
|
4
|
+
|
|
5
|
+
import { expect, expectException } from './testing.mjs'
|
|
6
|
+
|
|
7
|
+
import { GroupSet } from '../groupset.mjs'
|
|
8
|
+
import { Note } from '../note.mjs'
|
|
9
|
+
import { Group } from '../group.mjs'
|
|
10
|
+
|
|
11
|
+
export const test = {
|
|
12
|
+
tests: [
|
|
13
|
+
{
|
|
14
|
+
title: "default constructor results in correct set",
|
|
15
|
+
test: () => {
|
|
16
|
+
let set = new GroupSet();
|
|
17
|
+
|
|
18
|
+
expect(set.isAbstract, false);
|
|
19
|
+
expect(set.allowDuplicates, false);
|
|
20
|
+
expect(set.size, 0);
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
title: "add throws error when adding non-group",
|
|
25
|
+
test: () => {
|
|
26
|
+
let set = new GroupSet();
|
|
27
|
+
let element = new Note();
|
|
28
|
+
|
|
29
|
+
expectException(() => { set.add(element); }, Error);
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: "add succeeds adding group",
|
|
34
|
+
test: () => {
|
|
35
|
+
let set = new GroupSet();
|
|
36
|
+
let element = new Group(1, 1);
|
|
37
|
+
|
|
38
|
+
expect(set.add(element), (result) => { return result === set; });
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
],
|
|
43
|
+
}
|