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/src/test/note.mjs DELETED
@@ -1,367 +0,0 @@
1
- // articulationset.mjs
2
- //
3
- // Tests for articulationset.mjs.
4
-
5
- import { expect, expectException } from './testing.mjs'
6
-
7
- import { Instruments } from '../instrument.mjs'
8
- import { Articulations } from '../articulation.mjs'
9
- import { ArticulationSet } from '../articulationset.mjs'
10
- import { Note } from '../note.mjs'
11
-
12
- export const test = {
13
- tests: [
14
- {
15
- title: "default constructor results in correct set",
16
- test: () => {
17
- let note = new Note();
18
-
19
- expect(note.instrument === undefined, true);
20
- expect(note.articulations === undefined, true);
21
- },
22
- },
23
- {
24
- title: "constructor correctly constructs from instrument",
25
- test: () => {
26
- let note = new Note({ add: Instruments.Snare });
27
-
28
- expect(note.instrument === Instruments.Snare, true);
29
- expect(note.articulations === undefined, true);
30
- },
31
- },
32
- {
33
- title: "constructor correctly constructs from articulation set",
34
- test: () => {
35
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
36
- let note = new Note({ add: [ undefined, articulations ] });
37
-
38
- expect(note.instrument === undefined, true);
39
- expect(note.articulations === articulations, true);
40
- },
41
- },
42
- {
43
- title: "constructor correctly constructs from instrument and articulation set",
44
- test: () => {
45
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
46
- let note = new Note({ add: [ Instruments.Snare, articulations ] });
47
-
48
- expect(note.instrument === Instruments.Snare, true);
49
- expect(note.articulations === articulations, true);
50
- },
51
- },
52
- {
53
- title: "constructor correctly constructs from instrument and articulation (promoted to set)",
54
- test: () => {
55
- let note = new Note({ add: [ Instruments.Snare, Articulations.Accent ] });
56
-
57
- expect(note.instrument === Instruments.Snare, true);
58
- expect(note.articulations instanceof ArticulationSet, true);
59
- expect(note.articulations.size, 1);
60
- expect(note.articulations.elementAt(0) === Articulations.Accent, true);
61
- },
62
- },
63
- {
64
- title: "constructor throws error if instrument wrong type",
65
- test: () => {
66
- let note;
67
-
68
- expectException(() => { note = new Note({ add: Articulations.Accent }); }, Error);
69
- },
70
- },
71
- {
72
- title: "constructor throws error if articulation set wrong type",
73
- test: () => {
74
- let note;
75
-
76
- expectException(() => { note = new Note({ add: [ undefined, new Error() ] }); }, Error);
77
- },
78
- },
79
-
80
- {
81
- title: "clone correctly clones note (shallow)",
82
- test: () => {
83
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
84
- const note = new Note({ add: [ Instruments.Snare, articulations ] });
85
-
86
- let other = note.clone(false);
87
-
88
- expect(other !== note, true);
89
- expect(other.instrument === Instruments.Snare, true);
90
- expect(other.articulations === articulations, true);
91
- },
92
- },
93
- {
94
- title: "clone correctly clones note (deep)",
95
- test: () => {
96
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
97
- const note = new Note({ add: [ Instruments.Snare, articulations ] });
98
-
99
- let other = note.clone(true);
100
-
101
- expect(other !== note, true);
102
- expect(other.instrument === Instruments.Snare, true);
103
- expect(other.articulations !== articulations, true);
104
- },
105
- },
106
-
107
- {
108
- title: "elementAt returns instrument at 0",
109
- test: () => {
110
- const note = new Note({ add: Instruments.Snare });
111
-
112
- expect(note.elementAt(0) === Instruments.Snare, true);
113
- },
114
- },
115
- {
116
- title: "elementAt returns articulation set at 1",
117
- test: () => {
118
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
119
- const note = new Note({ add: [ undefined, articulations ] });
120
-
121
- expect(note.elementAt(1) === articulations, true);
122
- },
123
- },
124
-
125
- {
126
- title: "promote returns argument if passed another note",
127
- test: () => {
128
- const note = new Note();
129
-
130
- expect((new Note()).promote(note) === note, true);
131
- },
132
- },
133
- {
134
- title: "promote correctly promotes instrument",
135
- test: () => {
136
- const note = new Note();
137
-
138
- expect(note.promote(Instruments.Snare) === note, true);
139
- expect(note.instrument === Instruments.Snare, true);
140
- expect(note.articulations === undefined, true);
141
- },
142
- },
143
- {
144
- title: "promote correctly promotes articulation set",
145
- test: () => {
146
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
147
- const note = new Note();
148
-
149
- expect(note.promote(articulations) === note, true);
150
- expect(note.instrument === undefined, true);
151
- expect(note.articulations === articulations, true);
152
- },
153
- },
154
- {
155
- title: "promote correctly promotes articulation",
156
- test: () => {
157
- const note = new Note();
158
-
159
- expect(note.promote(Articulations.Accent) === note, true);
160
- expect(note.instrument === undefined, true);
161
- expect(note.articulations !== undefined, true);
162
- expect(note.articulations.elementAt(0) === Articulations.Accent, true);
163
- },
164
- },
165
- {
166
- title: "promote returns undefined for unknown promotion",
167
- test: () => {
168
- const note = new Note();
169
-
170
- expect(note.promote(Error) === undefined, true);
171
- expect(note.instrument === undefined, true);
172
- expect(note.articulations === undefined, true);
173
- },
174
- },
175
-
176
- {
177
- title: "isEqual fails comparing note with not-note",
178
- test: () => {
179
- const note = new Note();
180
-
181
- expect(note.isEqual(Instruments.Snare), false);
182
- },
183
- },
184
- {
185
- title: "isEqual succeeds comparing undefined notes (loose)",
186
- test: () => {
187
- const note = new Note();
188
-
189
- expect(note.isEqual(new Note(), false), true);
190
- },
191
- },
192
- {
193
- title: "isEqual succeeds comparing undefined notes (strict)",
194
- test: () => {
195
- const note = new Note();
196
-
197
- expect(note.isEqual(new Note(), true), true);
198
- },
199
- },
200
- {
201
- title: "isEqual succeeds comparing notes with same instrument and no articulations (loose)",
202
- test: () => {
203
- const note = new Note({ add: Instruments.Snare });
204
-
205
- expect(note.isEqual(new Note({ add: Instruments.Snare }), false), true);
206
- },
207
- },
208
- {
209
- title: "isEqual succeeds comparing notes with same instrument and no articulations (strict)",
210
- test: () => {
211
- const note = new Note({ add: Instruments.Snare });
212
-
213
- expect(note.isEqual(new Note({ add: Instruments.Snare }), true), true);
214
- },
215
- },
216
- {
217
- title: "isEqual fails comparing notes with different instrument and no articulations (loose)",
218
- test: () => {
219
- const note = new Note({ add: Instruments.Snare });
220
-
221
- expect(note.isEqual(new Note({ add: Instruments.Bass1 }), false), false);
222
- },
223
- },
224
- {
225
- title: "isEqual fails comparing notes with different instrument and no articulations (strict)",
226
- test: () => {
227
- const note = new Note({ add: Instruments.Snare });
228
-
229
- expect(note.isEqual(new Note({ add: Instruments.Bass1 }), true), false);
230
- },
231
- },
232
- {
233
- title: "isEqual succeeds comparing notes with no instrument and same articulations (loose)",
234
- test: () => {
235
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
236
- const note = new Note({ add: [ undefined, articulations] });
237
-
238
- expect(note.isEqual(new Note({ add: [ undefined, articulations ] }), false), true);
239
- },
240
- },
241
- {
242
- title: "isEqual succeeds comparing notes with no instrument and same articulations (strict)",
243
- test: () => {
244
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
245
- const note = new Note({ add: [ undefined, articulations] });
246
-
247
- expect(note.isEqual(new Note({ add: [ undefined, articulations ] }), true), true);
248
- },
249
- },
250
- {
251
- title: "isEqual succeeds comparing notes with same instrument and same articulations (loose)",
252
- test: () => {
253
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
254
- const note = new Note({ add: [ Instruments.Snare, articulations] });
255
-
256
- expect(note.isEqual(new Note({ add: [ Instruments.Snare, articulations ] }), false), true);
257
- },
258
- },
259
- {
260
- title: "isEqual succeeds comparing notes with same instrument and same articulations (strict)",
261
- test: () => {
262
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
263
- const note = new Note({ add: [ Instruments.Snare, articulations] });
264
-
265
- expect(note.isEqual(new Note({ add: [ Instruments.Snare, articulations ] }), true), true);
266
- },
267
- },
268
- {
269
- title: "isEqual succeeds comparing notes with same instrument and different articulations (loose)",
270
- test: () => {
271
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
272
- const note = new Note({ add: [ Instruments.Snare, articulations] });
273
-
274
- expect(note.isEqual(new Note({ add: [ Instruments.Snare, articulations ] }), false), true);
275
- },
276
- },
277
- {
278
- title: "isEqual fails comparing notes with same instrument and different articulations (strict)",
279
- test: () => {
280
- const note = new Note(
281
- { add: [
282
- Instruments.Snare,
283
- new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] })
284
- ] }
285
- );
286
-
287
- expect(
288
- note.isEqual(
289
- new Note(
290
- { add: [
291
- Instruments.Snare,
292
- new ArticulationSet({ add: [ Articulations.Accent, Articulations.Staccato ] })
293
- ] }
294
- ),
295
- true
296
- ),
297
- false
298
- );
299
- },
300
- },
301
-
302
- {
303
- title: "merge throws error if passed non-note",
304
- test: () => {
305
- const note = new Note();
306
-
307
- expectException(() => { note.merge(Instruments.Snare)}, Error);
308
- },
309
- },
310
- {
311
- title: "merge throws error if instruments don't match",
312
- test: () => {
313
- const note = new Note({ add: Instruments.Snare });
314
-
315
- expectException(() => { note.merge(new Note({ add: Instruments.Bass1 }))}, Error);
316
- },
317
- },
318
- {
319
- title: "merge correctly merges if neither note has articulations",
320
- test: () => {
321
- const note = new Note({ add: Instruments.Snare });
322
-
323
- expect(note.merge(new Note({ add: Instruments.Snare })), (result) => { return result === note; });
324
- expect(note.instrument === Instruments.Snare, true);
325
- expect(note.articulations === undefined, true);
326
- },
327
- },
328
- {
329
- title: "merge correctly merges if target has no articulations",
330
- test: () => {
331
- const note = new Note({ add: Instruments.Snare });
332
-
333
- expect(note.merge(new Note({ add: [ Instruments.Snare, Articulations.Accent ] })), (result) => { return result === note; });
334
- expect(note.instrument === Instruments.Snare, true);
335
- expect(note.articulations !== undefined, true);
336
- expect(note.articulations.elementAt(0) === Articulations.Accent, true);
337
- },
338
- },
339
- {
340
- title: "merge correctly merges if source has no articulations",
341
- test: () => {
342
- const note = new Note({ add: [ Instruments.Snare, Articulations.Accent ] });
343
-
344
- expect(note.merge(new Note({ add: Instruments.Snare })), (result) => { return result === note; });
345
- expect(note.instrument === Instruments.Snare, true);
346
- expect(note.articulations !== undefined, true);
347
- expect(note.articulations.elementAt(0) === Articulations.Accent, true);
348
- },
349
- },
350
- {
351
- title: "merge correctly merges if source and target have articulations",
352
- test: () => {
353
- const articulations = new ArticulationSet({ add: [ Articulations.Accent, Articulations.Fermata ] });
354
- const note = new Note({ add: [ Instruments.Snare, articulations ] });
355
-
356
- expect(note.merge(new Note({ add: [ Instruments.Snare, new ArticulationSet({ add: [ Articulations.Staccato, Articulations.Accent ] }) ] })), (result) => { return result === note; });
357
- expect(note.instrument === Instruments.Snare, true);
358
- expect(note.articulations !== undefined, true);
359
- expect(note.articulations.size, 3);
360
- expect(note.articulations.elementAt(0) === Articulations.Accent, true);
361
- expect(note.articulations.elementAt(1) === Articulations.Fermata, true);
362
- expect(note.articulations.elementAt(2) === Articulations.Staccato, true);
363
- },
364
- },
365
-
366
- ],
367
- }
@@ -1,43 +0,0 @@
1
- // noteset.mjs
2
- //
3
- // Tests for noteset.mjs.
4
-
5
- import { expect, expectException } from './testing.mjs'
6
-
7
- import { NoteSet } from '../noteset.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 NoteSet();
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-note",
25
- test: () => {
26
- let set = new NoteSet();
27
- let element = new Group(1, 1);
28
-
29
- expectException(() => { set.add(element); }, Error);
30
- },
31
- },
32
- {
33
- title: "add succeeds adding note",
34
- test: () => {
35
- let set = new NoteSet();
36
- let element = new Note();
37
-
38
- expect(set.add(element), (result) => { return result === set; });
39
- },
40
- },
41
-
42
- ],
43
- }
@@ -1,63 +0,0 @@
1
- // operator.mjs
2
- //
3
- // Tests for operator.mjs.
4
-
5
- import { expect, expectException } from "./testing.mjs";
6
-
7
- import { Set } from "../set.mjs";
8
- import { Instruments } from "../instrument.mjs";
9
- import { InstrumentSet } from "../instrumentset.mjs";
10
- import { ArticulationSet } from "../articulationset.mjs";
11
-
12
- export const test = {
13
- tests: [
14
- {
15
- title: "default constructor results in correct set",
16
- test: () => {
17
- let operator = new Set.Operator();
18
-
19
- expect(operator.isAbstract, true);
20
- },
21
- },
22
-
23
- {
24
- title:
25
- "size throws error (Operator not derived)",
26
- test: () => {
27
- const set1 = new InstrumentSet();
28
- const set2 = new InstrumentSet();
29
-
30
- const operator = new Set.Operator(set1, set2);
31
-
32
- expectException(() => operator.size, Error);
33
- },
34
- },
35
-
36
- {
37
- title:
38
- "elementAt throws error because size throws",
39
- test: () => {
40
- const set1 = new InstrumentSet();
41
- const set2 = new InstrumentSet();
42
-
43
- const operator = new Set.Operator(set1, set2);
44
-
45
- expectException(() => operator.elementAt(0), Error);
46
- },
47
- },
48
-
49
- {
50
- title:
51
- "has throws error (Operator not derived)",
52
- test: () => {
53
- const set1 = new InstrumentSet();
54
- const set2 = new InstrumentSet();
55
-
56
- const operator = new Set.Operator(set1, set2);
57
-
58
- expectException(() => operator.has(), Error);
59
- },
60
- },
61
-
62
- ],
63
- };
@@ -1,113 +0,0 @@
1
- // pattern.mjs
2
- //
3
- // Tests for pattern.mjs.
4
-
5
- import { expect, expectException } from "./testing.mjs";
6
-
7
- import { Pattern } from "../pattern.mjs";
8
- import { Instruments } from "../instrument.mjs";
9
- import { Chord } from "../chord.mjs";
10
- import { Note } from "../note.mjs";
11
- import { Group } from "../group.mjs";
12
-
13
- export const test = {
14
- tests: [
15
- {
16
- title: "default constructor results in correct set",
17
- test: () => {
18
- let set = new Pattern();
19
-
20
- expect(set.isAbstract, false);
21
- expect(set.allowDuplicates, true);
22
- expect(set.size, 0);
23
- },
24
- },
25
- {
26
- title: "add throws error when adding non-pattern",
27
- test: () => {
28
- let set = new Pattern();
29
- let element = new Group(1, 1);
30
-
31
- expectException(() => {
32
- set.add(element);
33
- }, Error);
34
- },
35
- },
36
- {
37
- title: "add succeeds adding note",
38
- test: () => {
39
- let set = new Pattern();
40
- let element = new Note();
41
-
42
- expect(set.add(element), (result) => {
43
- return result === set;
44
- });
45
- },
46
- },
47
-
48
- {
49
- title:
50
- "isEqual fails when compared with pattern with different numbers of chords",
51
- test: () => {
52
- const pattern = new Pattern({
53
- add: new Chord({ add: [Instruments.Snare] })
54
- });
55
- const other = new Pattern({
56
- add: [
57
- new Chord({add: Instruments.Snare}),
58
- new Chord({add: Instruments.Bass1})
59
- ]
60
- });
61
-
62
- expect(pattern.isEqual(other), false);
63
- },
64
- },
65
- {
66
- title:
67
- "isEqual succeeds when comparing chords with same chord",
68
- test: () => {
69
- const pattern = new Pattern({
70
- add: new Chord({ add: [Instruments.Snare] })
71
- });
72
- const other = new Pattern({
73
- add: new Chord({ add: [Instruments.Snare] })
74
- });
75
-
76
- expect(pattern.isEqual(other), true);
77
- },
78
- },
79
- {
80
- title:
81
- "isEqual succeeds when comparing chords with same chords",
82
- test: () => {
83
- const pattern = new Pattern({
84
- add: new Chord({ add: [Instruments.Snare] }),
85
- add: new Chord({ add: [Instruments.Bass1] })
86
- });
87
- const other = new Pattern({
88
- add: new Chord({ add: [Instruments.Snare] }),
89
- add: new Chord({ add: [Instruments.Bass1] })
90
- });
91
-
92
- expect(pattern.isEqual(other), true);
93
- },
94
- },
95
- {
96
- title:
97
- "isEqual fails when comparing chords with same chords but different order",
98
- test: () => {
99
- const pattern = new Pattern({
100
- add: new Chord({ add: [Instruments.Bass1] }),
101
- add: new Chord({ add: [Instruments.Snare] })
102
- });
103
- const other = new Pattern({
104
- add: new Chord({ add: [Instruments.Snare] }),
105
- add: new Chord({ add: [Instruments.Bass1] })
106
- });
107
-
108
- expect(pattern.isEqual(other), false);
109
- },
110
- },
111
-
112
- ],
113
- };
@@ -1,43 +0,0 @@
1
- // patternset.mjs
2
- //
3
- // Tests for patternset.mjs.
4
-
5
- import { expect, expectException } from './testing.mjs'
6
-
7
- import { PatternSet } from '../patternset.mjs'
8
- import { Pattern } from '../pattern.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 PatternSet();
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-pattern",
25
- test: () => {
26
- let set = new PatternSet();
27
- let element = new Group(1, 1);
28
-
29
- expectException(() => { set.add(element); }, Error);
30
- },
31
- },
32
- {
33
- title: "add succeeds adding pattern",
34
- test: () => {
35
- let set = new PatternSet();
36
- let element = new Pattern();
37
-
38
- expect(set.add(element), (result) => { return result === set; });
39
- },
40
- },
41
-
42
- ],
43
- }
@@ -1,43 +0,0 @@
1
- // patternsource.mjs
2
- //
3
- // Tests for patternsource.mjs.
4
-
5
- import { expect, expectException } from './testing.mjs'
6
-
7
- import { PatternSource } from '../patternsource.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 PatternSource();
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-note",
25
- test: () => {
26
- let set = new PatternSource();
27
- let element = new Group(1, 1);
28
-
29
- expectException(() => { set.add(element); }, Error);
30
- },
31
- },
32
- {
33
- title: "add succeeds adding note",
34
- test: () => {
35
- let set = new PatternSource();
36
- let element = new Note();
37
-
38
- expect(set.add(element), (result) => { return result === set; });
39
- },
40
- },
41
-
42
- ],
43
- }