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,290 +0,0 @@
1
- // regulargroupset.mjs
2
- //
3
- // Tests for regulargroupset.mjs.
4
-
5
- import { expect, expectException } from './testing.mjs'
6
-
7
- import { RegularGroupSet } from '../regulargroupset.mjs'
8
- import { Instruments } from '../instrument.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 RegularGroupSet();
17
-
18
- expect(set.isAbstract, true);
19
- expect(set.allowDuplicates, false);
20
- expect(set.size, 1);
21
- expect(set.start, 1);
22
- expect(set.end, 1);
23
- expect(set.step, 1);
24
- },
25
- },
26
- {
27
- title: "constructor throws error when start < 1",
28
- test: () => {
29
- let set;
30
-
31
- expectException(() => { set = new RegularGroupSet({ start: 0 }); }, Error);
32
- },
33
- },
34
- {
35
- title: `constructor throws error when start > ${Group.MAX_LENGTH}`,
36
- test: () => {
37
- let set;
38
-
39
- expectException(() => { set = new RegularGroupSet({ start: Group.MAX_LENGTH+1 }); }, Error);
40
- },
41
- },
42
- {
43
- title: `constructor succeeds when start in [1..${Group.MAX_LENGTH}]`,
44
- test: () => {
45
- let set;
46
-
47
- for (let value = 1; value <= Group.MAX_LENGTH; ++value) {
48
- set = new RegularGroupSet({ start: value });
49
- expect(set.start, value);
50
- }
51
- },
52
- },
53
- {
54
- title: "constructor throws error when end < 1",
55
- test: () => {
56
- let set;
57
-
58
- expectException(() => { set = new RegularGroupSet({ end: 0 }); }, Error);
59
- },
60
- },
61
- {
62
- title: `constructor throws error when end > ${Group.MAX_LENGTH}`,
63
- test: () => {
64
- let set;
65
-
66
- expectException(() => { set = new RegularGroupSet({ end: Group.MAX_LENGTH+1 }); }, Error);
67
- },
68
- },
69
- {
70
- title: `constructor succeeds when end in [1..${Group.MAX_LENGTH}]`,
71
- test: () => {
72
- let set;
73
-
74
- for (let value = 1; value <= Group.MAX_LENGTH; ++value) {
75
- set = new RegularGroupSet({ end: value });
76
- expect(set.end, value);
77
- }
78
- },
79
- },
80
- {
81
- title: `constructor throws error when end < start in [1..${Group.MAX_LENGTH-1}]`,
82
- test: () => {
83
- let set;
84
-
85
- for (let value = 1; value <= Group.MAX_LENGTH-1; ++value) {
86
- expectException(() => { set = new RegularGroupSet({ start: value+1, end: value }); }, Error);
87
- }
88
- },
89
- },
90
- {
91
- title: `constructor succeeds when end > start in [2..${Group.MAX_LENGTH}]`,
92
- test: () => {
93
- let set;
94
-
95
- for (let value = 2; value <= Group.MAX_LENGTH; ++value) {
96
- set = new RegularGroupSet({ start: value-1, end: value });
97
- expect(set.start, value-1);
98
- expect(set.end, value);
99
- }
100
- },
101
- },
102
- {
103
- title: "constructor throws error when step < 1",
104
- test: () => {
105
- let set;
106
-
107
- expectException(() => { set = new RegularGroupSet({ step: 0 }); }, Error);
108
- },
109
- },
110
- {
111
- title: `constructor throws error when step > ${Group.MAX_LENGTH}`,
112
- test: () => {
113
- let set;
114
-
115
- expectException(() => { set = new RegularGroupSet({ step: Group.MAX_LENGTH+1 }); }, Error);
116
- },
117
- },
118
- {
119
- title: `constructor succeeds when step in [1..${Group.MAX_LENGTH}]`,
120
- test: () => {
121
- let set;
122
-
123
- for (let value = 1; value <= Group.MAX_LENGTH; ++value) {
124
- set = new RegularGroupSet({ step: value });
125
- expect(set.step, value);
126
- }
127
- },
128
- },
129
-
130
- {
131
- title: "clone correctly clones set",
132
- test: () => {
133
- const set = new RegularGroupSet({ start: 1, end: 2, step: 3 });
134
- const clone = set.clone();
135
-
136
- expect(clone !== undefined, true);
137
- expect(clone.start, 1);
138
- expect(clone.end, 2);
139
- expect(clone.step, 3);
140
- },
141
- },
142
-
143
- {
144
- title: `iterator correctly returns groups with step in [1..${Group.MAX_LENGTH}]`,
145
- test: () => {
146
- for (let step = 1; step <= Group.MAX_LENGTH; ++step) {
147
- const set = new RegularGroupSet({ start: 1, end: Group.MAX_LENGTH, step: step });
148
-
149
- expect(set.size, Math.ceil(Group.MAX_LENGTH / step));
150
-
151
- let length = 1;
152
-
153
- for (let group of set) {
154
- expect(group.length, length);
155
-
156
- if (length < Group.MAX_LENGTH) {
157
- expect(group.group, 0xffffffff & ((1 << length) - 1));
158
- } else {
159
- expect(group.group, 0xffffffff);
160
- }
161
-
162
- length += step;
163
- }
164
- }
165
- },
166
- },
167
-
168
- {
169
- title: "elementAt throws error for index < 0",
170
- test: () => {
171
- let set = new RegularGroupSet();
172
-
173
- expectException(() => { set.elementAt(-1); }, Error);
174
- },
175
- },
176
- {
177
- title: "elementAt throws error for index higher than set size",
178
- test: () => {
179
- let set = new RegularGroupSet({ start: 1, end: 1, step: 1 });
180
-
181
- expect(set.size, 1);
182
-
183
- expectException(() => { set.elementAt(1); }, Error);
184
- },
185
- },
186
- {
187
- title: `elementAt correctly returns groups with step in [1..${Group.MAX_LENGTH}]`,
188
- test: () => {
189
- for (let step = 1; step <= Group.MAX_LENGTH; ++step) {
190
- const set = new RegularGroupSet({ start: 1, end: Group.MAX_LENGTH, step: step });
191
- const numGroups = Math.ceil(Group.MAX_LENGTH / step);
192
-
193
- expect(set.size, numGroups);
194
-
195
- let length = 1;
196
-
197
- for (let index = 0; index < numGroups; ++index) {
198
- let group = set.elementAt(index);
199
-
200
- expect(group.length, length);
201
-
202
- if (length < Group.MAX_LENGTH) {
203
- expect(group.group, 0xffffffff & ((1 << length) - 1));
204
- } else {
205
- expect(group.group, 0xffffffff);
206
- }
207
-
208
- length += step;
209
- }
210
- }
211
- },
212
- },
213
-
214
- {
215
- title: "has throws error when argument is undefined",
216
- test: () => {
217
- let set = new RegularGroupSet();
218
-
219
- expectException(() => { set.has(); }, Error);
220
- },
221
- },
222
- {
223
- title: "has throws error when argument is not a group",
224
- test: () => {
225
- let set = new RegularGroupSet();
226
-
227
- expectException(() => { set.has(Instruments.Snare); }, Error);
228
- },
229
- },
230
- {
231
- title: "has fails for group smaller than smallest in set",
232
- test: () => {
233
- let set = new RegularGroupSet({ start: 2, end: 2, step: 1});
234
- let other = new Group(1, 1);
235
-
236
- expect(set.has(other), false);
237
- },
238
- },
239
- {
240
- title: "has fails for group larger than largest in set",
241
- test: () => {
242
- let set = new RegularGroupSet({ start: 2, end: 2, step: 1});
243
- let other = new Group(7, 3);
244
-
245
- expect(set.has(other), false);
246
- },
247
- },
248
- {
249
- title: `has returns correct result for all length with step in [1..${Group.MAX_LENGTH}]`,
250
- test: () => {
251
- let set;
252
- let other;
253
- let length;
254
-
255
- for (let step = 1; step <= Group.MAX_LENGTH; ++step) {
256
- set = new RegularGroupSet({ start: 1, end: Group.MAX_LENGTH, step: step});
257
-
258
- length = 1;
259
-
260
- for (let group of set) {
261
- while (length < group.length) {
262
- other = new Group(0xffffffff, length);
263
-
264
- expect(set.has(other), false);
265
-
266
- ++length;
267
- }
268
-
269
- if (length === group.length) {
270
- let other = new Group(0xffffffff, length);
271
-
272
- expect(set.has(other), true);
273
-
274
- ++length;
275
- }
276
- }
277
-
278
- while (length <= Group.MAX_LENGTH) {
279
- other = new Group(0xffffffff, length);
280
-
281
- expect(set.has(other), false);
282
-
283
- ++length;
284
- }
285
- }
286
- },
287
- },
288
-
289
- ],
290
- }
package/src/test/repl.mjs DELETED
@@ -1,63 +0,0 @@
1
- // repl.mjs
2
- //
3
- // Script to initialise a repl context with exports from various modules
4
- // and enter the repl.
5
-
6
- (async (context, defs) => {
7
- defs.forEach(async (def) => {
8
- if (!Array.isArray(def)) {
9
- def = [def];
10
- }
11
-
12
- if (def.length < 1)
13
- throw new Error("Invalid import array - no module specified");
14
-
15
- if (def.length < 2) def[1] = def[0][0].toUpperCase() + def[0].substring(1);
16
-
17
- let module = def.shift();
18
-
19
- def.forEach(async (key) => {
20
- try {
21
- context[key] = (await import(`../${module}.mjs`))[key];
22
- } catch (e) {
23
- console.log("OUCH");
24
- context[key] = (await import(`./${module}.mjs`))[key];
25
- }
26
- });
27
- });
28
- })((await import("repl")).start("disco>").context, [
29
- // moduleName or [ moduleName, export1, export2, ... ]
30
- //
31
- // If only moduleName is provided, the exportName will be moduleName with
32
- // the first letter capitalised.
33
- //
34
- // Will import moduleName and place export1, export2, etc in the repl context
35
-
36
- ["instrument", "Instrument", "Instruments"],
37
-
38
- ["element"],
39
-
40
- ["articulation", "Articulation", "Articulations"],
41
- ["group"],
42
- ["set"],
43
-
44
- ["instrumentset", "InstrumentSet"],
45
- ["articulationset", "ArticulationSet"],
46
-
47
- ["note"],
48
-
49
- ["patternsource", "PatternSource"],
50
- ["chord"],
51
- ["noteset", "NoteSet"],
52
- ["pattern"],
53
- ["patternset", "PatternSet"],
54
- ["groupset", "GroupSet"],
55
- ["regulargroupset", "RegularGroupSet"],
56
- ["irregulargroupset", "IrregularGroupSet"],
57
- ["schedule"],
58
- ["schema"],
59
-
60
- // [ "factory" ],
61
-
62
- ["replinit", "init"],
63
- ]);
@@ -1,134 +0,0 @@
1
- // init.mjs
2
- //
3
- // Script to initialise a repl context with exports from various modules
4
- // and enter the repl.
5
- // import './disco.mjs'
6
- import { useDisco } from '../disco.mjs';
7
-
8
- import Fraction from 'fraction.js';
9
-
10
- import { Articulations } from '../articulation.mjs';
11
- import { ArticulationSet } from '../articulationset.mjs';
12
- import { Instruments } from '../instrument.mjs';
13
- import { InstrumentSet } from '../instrumentset.mjs';
14
- import { Note } from '../note.mjs';
15
- import { NoteSet } from '../noteset.mjs';
16
- import { Chord } from '../chord.mjs';
17
- import { Pattern } from '../pattern.mjs';
18
- import { PatternSet } from '../patternset.mjs';
19
- import { Schedule } from '../schedule.mjs';
20
- import { Schema } from '../schema.mjs';
21
-
22
- import { RegularGroupSet } from '../regulargroupset.mjs';
23
- import { IrregularGroupSet } from '../irregulargroupset.mjs';
24
-
25
- // Place any extra initialisation here...
26
-
27
- export function init() {
28
- useDisco();
29
-
30
- // let A = new ArticulationSet();
31
- // let B = new ArticulationSet();
32
-
33
- // const a_articulations = [
34
- // Articulations.Accent,
35
- // Articulations.Expressivo,
36
- // Articulations.Marcato,
37
- // Articulations.Portato,
38
- // Articulations.Ghost,
39
- // ];
40
-
41
- // const b_articulations = [
42
- // Articulations.Staccato,
43
- // Articulations.Expressivo,
44
- // Articulations.Marcato,
45
- // Articulations.Tenuto,
46
- // ];
47
-
48
- // for (let a of a_articulations) {
49
- // A.add(a);
50
- // }
51
-
52
- // for (let b of b_articulations) {
53
- // B.add(b);
54
- // }
55
-
56
- // let D = A.union(B);
57
-
58
- // return { A, B, D };
59
-
60
- const instruments = [ Instruments.Snare, Instruments.Bass1, Instruments.HighHat ];
61
- const instruments2 = [ Instruments.China, Instruments.Claves, Instruments.Crash ];
62
-
63
- let P = new Pattern();
64
-
65
- for (let instrument of instruments) {
66
- let chord = new Chord();
67
- chord.add(new Note({ add: instrument }));
68
- P.add(chord);
69
- }
70
-
71
- // let R = P.rotate({ rotateLeft: true });
72
-
73
- // return { P, R };
74
-
75
- let Q = new Pattern();
76
-
77
- for (let instrument of instruments2) {
78
- let chord = new NoteSet();
79
- chord.add(new Note({ add: instrument }));
80
- Q.add(chord);
81
- }
82
-
83
- let S = new PatternSet();
84
- S.add(P).add(Q);
85
-
86
- let T = new PatternSet();
87
- T.add(Q);
88
-
89
- // let X = new Schedule({ duration: new Fraction(1, 4), patterns: S });
90
- // let Y = new Schedule({ duration: new Fraction(1, 8), patterns: T });
91
-
92
- // let schema = new Schema();
93
- // schema.add(X).add(Y);
94
-
95
- return { P, Q, S, T };
96
- // return { P, Q, S, T, X, Y, schema };
97
-
98
- // let l = new Note(Instruments.Snare);
99
- // let m = new Note(Instruments.Bass1);
100
- // let n = new Note(Instruments.Snare, new ArticulationSet({ add: Articulations.Accent }));
101
-
102
- // return { l, m, n };
103
-
104
- // const instruments = [ Instruments.Snare, Instruments.Bass1, Instruments.HighHat ];
105
- // const instruments2 = [ Instruments.China, Instruments.Claves, Instruments.Crash ];
106
-
107
- // let P = new NoteSet();
108
-
109
- // for (let instrument of instruments) {
110
- // P.add(new Note(instrument));
111
- // }
112
-
113
- // let Q = new NoteSet();
114
-
115
- // for (let instrument of instruments2) {
116
- // Q.add(new Note(instrument));
117
- // }
118
-
119
- // return { P, Q };
120
-
121
- // let A = new InstrumentSet();
122
-
123
- // for (let instrument of instruments) {
124
- // A.add(instrument);
125
- // }
126
-
127
- // let B = new InstrumentSet();
128
-
129
- // for (let instrument of instruments2) {
130
- // B.add(instrument);
131
- // }
132
-
133
- // return { A, B };
134
- }