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,66 @@
|
|
|
1
|
+
// articulation.mjs
|
|
2
|
+
//
|
|
3
|
+
// Tests for articulation.mjs.
|
|
4
|
+
|
|
5
|
+
import { expect } from './testing.mjs'
|
|
6
|
+
|
|
7
|
+
import { Element } from '../element.mjs'
|
|
8
|
+
import { Articulation } from '../articulation.mjs'
|
|
9
|
+
|
|
10
|
+
export const test = {
|
|
11
|
+
tests: [
|
|
12
|
+
{
|
|
13
|
+
title: "default constructor results in undefined symbol",
|
|
14
|
+
test: () => {
|
|
15
|
+
const articulation = new Articulation();
|
|
16
|
+
|
|
17
|
+
expect(articulation.symbol, undefined);
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "constructor correctly initialises valid symbol",
|
|
22
|
+
test: () => {
|
|
23
|
+
const articulation = new Articulation("test");
|
|
24
|
+
const symbol = Symbol.for("test");
|
|
25
|
+
|
|
26
|
+
expect(articulation.symbol, (result) => { return result === symbol; });
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
{
|
|
31
|
+
title: "isEqual succeeds when comparing with self",
|
|
32
|
+
test: () => {
|
|
33
|
+
const articulation = new Articulation("test");
|
|
34
|
+
|
|
35
|
+
expect(articulation.isEqual(articulation), true);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: "isEqual succeeds when comparing articulations with the same symbol",
|
|
40
|
+
test: () => {
|
|
41
|
+
const articulation = new Articulation("test");
|
|
42
|
+
const other = new Articulation("test");
|
|
43
|
+
|
|
44
|
+
expect(articulation.isEqual(other), true);
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: "isEqual fails when comparing articulations with different symbols",
|
|
49
|
+
test: () => {
|
|
50
|
+
const articulation = new Articulation("test");
|
|
51
|
+
const other = new Articulation("other");
|
|
52
|
+
|
|
53
|
+
expect(articulation.isEqual(other), false);
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: "isEqual fails when comparing against a non-articulation class",
|
|
58
|
+
test: () => {
|
|
59
|
+
const articulation = new Articulation();
|
|
60
|
+
const other = new Element();
|
|
61
|
+
|
|
62
|
+
expect(articulation.isEqual(other), false);
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
11
|
+
export const test = {
|
|
12
|
+
tests: [
|
|
13
|
+
{
|
|
14
|
+
title: "default constructor results in correct set",
|
|
15
|
+
test: () => {
|
|
16
|
+
let set = new ArticulationSet();
|
|
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-articulation",
|
|
25
|
+
test: () => {
|
|
26
|
+
let set = new ArticulationSet();
|
|
27
|
+
let element = Instruments.Snare;
|
|
28
|
+
|
|
29
|
+
expectException(() => { set.add(element); }, Error);
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: "add succeeds adding articulation",
|
|
34
|
+
test: () => {
|
|
35
|
+
let set = new ArticulationSet();
|
|
36
|
+
let element = Articulations.Accent;
|
|
37
|
+
|
|
38
|
+
expect(set.add(element), (result) => { return result === set; });
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
],
|
|
43
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
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
|
+
expectException(() => {
|
|
18
|
+
new Set.BinaryOperator();
|
|
19
|
+
}, Error);
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: "constructor results in Error exception when first set undefined",
|
|
24
|
+
test: () => {
|
|
25
|
+
expectException(() => {
|
|
26
|
+
new Set.BinaryOperator(undefined, new Set());
|
|
27
|
+
}, Error);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title: "constructor results in Error exception when second set undefined",
|
|
32
|
+
test: () => {
|
|
33
|
+
expectException(() => {
|
|
34
|
+
new Set.BinaryOperator(new Set(), undefined);
|
|
35
|
+
}, Error);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title:
|
|
40
|
+
"constructor throws Error when sets are different types without validation skipping",
|
|
41
|
+
test: () => {
|
|
42
|
+
const set1 = new InstrumentSet();
|
|
43
|
+
const set2 = new ArticulationSet();
|
|
44
|
+
|
|
45
|
+
expectException(() => {
|
|
46
|
+
new Set.BinaryOperator(set1, set2, {
|
|
47
|
+
skipValidation: false,
|
|
48
|
+
});
|
|
49
|
+
}, Error);
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
title:
|
|
54
|
+
"constructor succeeds when sets are different types with validation skipping",
|
|
55
|
+
test: () => {
|
|
56
|
+
const set1 = new InstrumentSet();
|
|
57
|
+
const set2 = new ArticulationSet();
|
|
58
|
+
|
|
59
|
+
const operator = new Set.BinaryOperator(set1, set2, {
|
|
60
|
+
skipValidation: true,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(operator.elements[0] === set1, true);
|
|
64
|
+
expect(operator.elements[1] === set2, true);
|
|
65
|
+
expect(operator.isAbstract, true);
|
|
66
|
+
expect(operator.allowDuplicates, false);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
title:
|
|
71
|
+
"constructor succeeds when sets are same types without validation skipping",
|
|
72
|
+
test: () => {
|
|
73
|
+
const set1 = new InstrumentSet();
|
|
74
|
+
const set2 = new InstrumentSet();
|
|
75
|
+
|
|
76
|
+
const operator = new Set.BinaryOperator(set1, set2, {
|
|
77
|
+
skipValidation: false,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(operator.elements[0] === set1, true);
|
|
81
|
+
expect(operator.elements[1] === set2, true);
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
title:
|
|
86
|
+
"constructor succeeds when sets are same types with validation skipping",
|
|
87
|
+
test: () => {
|
|
88
|
+
const set1 = new InstrumentSet();
|
|
89
|
+
const set2 = new InstrumentSet();
|
|
90
|
+
|
|
91
|
+
const operator = new Set.BinaryOperator(set1, set2, { skipValidation: true });
|
|
92
|
+
|
|
93
|
+
expect(operator.elements[0] === set1, true);
|
|
94
|
+
expect(operator.elements[1] === set2, true);
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
title:
|
|
100
|
+
"smallestSet returns smallest set when smallest is first",
|
|
101
|
+
test: () => {
|
|
102
|
+
const set1 = new InstrumentSet({ add: Instruments.Snare });
|
|
103
|
+
const set2 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Bass1 ]});
|
|
104
|
+
|
|
105
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
106
|
+
|
|
107
|
+
expect(operator.smallestSet, 0);
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
title:
|
|
112
|
+
"smallestSet returns smallest set when smallest is second",
|
|
113
|
+
test: () => {
|
|
114
|
+
const set1 = new InstrumentSet({ add: [ Instruments.Snare, Instruments.Bass1 ] });
|
|
115
|
+
const set2 = new InstrumentSet({ add: Instruments.Snare});
|
|
116
|
+
|
|
117
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
118
|
+
|
|
119
|
+
expect(operator.smallestSet, 1);
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
title:
|
|
124
|
+
"smallestSet returns smallest set when both are the same size",
|
|
125
|
+
test: () => {
|
|
126
|
+
const set1 = new InstrumentSet({ add: Instruments.Bass1 });
|
|
127
|
+
const set2 = new InstrumentSet({ add: Instruments.Snare});
|
|
128
|
+
|
|
129
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
130
|
+
|
|
131
|
+
expect(operator.smallestSet, 0);
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
{
|
|
136
|
+
title:
|
|
137
|
+
"size throws error (Operator not derived)",
|
|
138
|
+
test: () => {
|
|
139
|
+
const set1 = new InstrumentSet();
|
|
140
|
+
const set2 = new InstrumentSet();
|
|
141
|
+
|
|
142
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
143
|
+
|
|
144
|
+
expectException(() => operator.size, Error);
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
{
|
|
149
|
+
title:
|
|
150
|
+
"elementAt throws error because size throws",
|
|
151
|
+
test: () => {
|
|
152
|
+
const set1 = new InstrumentSet();
|
|
153
|
+
const set2 = new InstrumentSet();
|
|
154
|
+
|
|
155
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
156
|
+
|
|
157
|
+
expectException(() => operator.elementAt(0), Error);
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
{
|
|
162
|
+
title:
|
|
163
|
+
"has throws error (Operator not derived)",
|
|
164
|
+
test: () => {
|
|
165
|
+
const set1 = new InstrumentSet();
|
|
166
|
+
const set2 = new InstrumentSet();
|
|
167
|
+
|
|
168
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
169
|
+
|
|
170
|
+
expectException(() => operator.has(), Error);
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
{
|
|
175
|
+
title: "clone succeeds on an operator (Shallow)",
|
|
176
|
+
test: () => {
|
|
177
|
+
const set1 = new InstrumentSet();
|
|
178
|
+
const set2 = new InstrumentSet();
|
|
179
|
+
|
|
180
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
181
|
+
const clone = operator.clone();
|
|
182
|
+
|
|
183
|
+
expect(clone.isAbstract, true);
|
|
184
|
+
expect(clone.allowDuplicates, false);
|
|
185
|
+
expect(clone.isStrict, true);
|
|
186
|
+
expect(clone.skipValidation, false);
|
|
187
|
+
expect(clone.elements[0] === set1, true);
|
|
188
|
+
expect(clone.elements[1] === set2, true);
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
title: "clone succeeds on an operator (Deep)",
|
|
193
|
+
test: () => {
|
|
194
|
+
const set1 = new InstrumentSet();
|
|
195
|
+
const set2 = new InstrumentSet();
|
|
196
|
+
|
|
197
|
+
const operator = new Set.BinaryOperator(set1, set2);
|
|
198
|
+
const clone = operator.clone(true);
|
|
199
|
+
|
|
200
|
+
expect(clone.isAbstract, true);
|
|
201
|
+
expect(clone.allowDuplicates, false);
|
|
202
|
+
expect(clone.isStrict, true);
|
|
203
|
+
expect(clone.skipValidation, false);
|
|
204
|
+
expect(clone.elements[0] !== set1, true);
|
|
205
|
+
expect(clone.elements[1] !== set2, true);
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
],
|
|
210
|
+
};
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// chord.mjs
|
|
2
|
+
//
|
|
3
|
+
// Tests for chord.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 { Chord } from "../chord.mjs";
|
|
11
|
+
import { Note } from "../note.mjs";
|
|
12
|
+
import { NoteSet } from "../noteset.mjs";
|
|
13
|
+
import { Group } from "../group.mjs";
|
|
14
|
+
|
|
15
|
+
export const test = {
|
|
16
|
+
tests: [
|
|
17
|
+
{
|
|
18
|
+
title: "default constructor results in correct chord",
|
|
19
|
+
test: () => {
|
|
20
|
+
let chord = new Chord();
|
|
21
|
+
|
|
22
|
+
expect(chord.isAbstract, false);
|
|
23
|
+
expect(chord.allowDuplicates, false);
|
|
24
|
+
expect(chord.size, 0);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: "add throws error when adding non-note",
|
|
29
|
+
test: () => {
|
|
30
|
+
let chord = new Chord();
|
|
31
|
+
let element = new Group(1, 1);
|
|
32
|
+
|
|
33
|
+
expectException(() => {
|
|
34
|
+
chord.add(element);
|
|
35
|
+
}, Error);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: "add succeeds adding note",
|
|
40
|
+
test: () => {
|
|
41
|
+
let chord = new Chord();
|
|
42
|
+
let element = new Note();
|
|
43
|
+
|
|
44
|
+
expect(chord.add(element), (result) => {
|
|
45
|
+
return result === chord;
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
{
|
|
51
|
+
title:
|
|
52
|
+
"isEqual fails when compared with chord with different numbers of notes",
|
|
53
|
+
test: () => {
|
|
54
|
+
const chord = new Chord({ add: [Instruments.Snare] });
|
|
55
|
+
const other = new Chord({ add: [Instruments.Snare, Instruments.Bass1] });
|
|
56
|
+
|
|
57
|
+
expect(chord.isEqual(other), false);
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
title:
|
|
62
|
+
"isEqual fails when compared with chord with different numbers of articulations",
|
|
63
|
+
test: () => {
|
|
64
|
+
const chord = new Chord({
|
|
65
|
+
add: [new Note({ add: [Instruments.Snare, Articulations.Accent] })],
|
|
66
|
+
});
|
|
67
|
+
const other = new Chord({ add: [Instruments.Snare] });
|
|
68
|
+
|
|
69
|
+
expect(chord.isEqual(other), false);
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
title:
|
|
74
|
+
"isEqual succeeds when comparing chords with same instruments (no articulations)",
|
|
75
|
+
test: () => {
|
|
76
|
+
const chord = new Chord({ add: [Instruments.Snare, Instruments.Bass1] });
|
|
77
|
+
const other = new Chord({add: [Instruments.Snare, Instruments.Bass1],});
|
|
78
|
+
|
|
79
|
+
expect(chord.isEqual(other), true);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
title:
|
|
84
|
+
"isEqual succeeds when comparing chords with same, but disordered instruments (no articulations)",
|
|
85
|
+
test: () => {
|
|
86
|
+
const chord = new Chord({ add: [Instruments.Bass1, Instruments.Snare] });
|
|
87
|
+
const other = new Chord({add: [Instruments.Snare, Instruments.Bass1],});
|
|
88
|
+
|
|
89
|
+
expect(chord.isEqual(other), true);
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
title:
|
|
94
|
+
"isEqual succeeds when comparing chords with same instruments and articulations (ordered)",
|
|
95
|
+
test: () => {
|
|
96
|
+
const chord = new Chord({
|
|
97
|
+
add: [
|
|
98
|
+
new Note({ add: [Instruments.Snare, Articulations.Accent] }),
|
|
99
|
+
new Note({ add: [Instruments.Bass1, Articulations.Fermata] }),
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
const other = new Chord({
|
|
103
|
+
add: [
|
|
104
|
+
new Note({ add: [Instruments.Snare, Articulations.Accent] }),
|
|
105
|
+
new Note({ add: [Instruments.Bass1, Articulations.Fermata] }),
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
expect(chord.isEqual(other), true);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
title:
|
|
114
|
+
"isEqual succeeds when comparing chords with same instruments and articulations (disordered)",
|
|
115
|
+
test: () => {
|
|
116
|
+
const chord = new Chord({
|
|
117
|
+
add: [
|
|
118
|
+
new Note({ add: [Instruments.Snare, Articulations.Fermata] }),
|
|
119
|
+
new Note({ add: [Instruments.Bass1, Articulations.Accent] }),
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
const other = new Chord({
|
|
123
|
+
add: [
|
|
124
|
+
new Note({ add: [Instruments.Snare, Articulations.Accent] }),
|
|
125
|
+
new Note({ add: [Instruments.Bass1, Articulations.Fermata] }),
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(chord.isEqual(other), true);
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
title:
|
|
134
|
+
"isEqual fails when comparing chords with different instruments (no articulations)",
|
|
135
|
+
test: () => {
|
|
136
|
+
const chord = new Chord({ add: [Instruments.Bass1, Instruments.Snare] });
|
|
137
|
+
const other = new Chord({add: [Instruments.Snare, Instruments.Claves],});
|
|
138
|
+
|
|
139
|
+
expect(chord.isEqual(other), false);
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
title:
|
|
144
|
+
"isEqual fails when comparing chords with different instruments (same articulations)",
|
|
145
|
+
test: () => {
|
|
146
|
+
const chord = new Chord({
|
|
147
|
+
add: [
|
|
148
|
+
new Note({ add: [Instruments.Snare, Articulations.Fermata] }),
|
|
149
|
+
new Note({ add: [Instruments.Bass1, Articulations.Accent] }),
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
const other = new Chord({
|
|
153
|
+
add: [
|
|
154
|
+
new Note({ add: [Instruments.Snare, Articulations.Accent] }),
|
|
155
|
+
new Note({ add: [Instruments.Claves, Articulations.Fermata] }),
|
|
156
|
+
],
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(chord.isEqual(other), false);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
title:
|
|
164
|
+
"isEqual fails when comparing chords with different instruments (different articulations)",
|
|
165
|
+
test: () => {
|
|
166
|
+
const chord = new Chord({
|
|
167
|
+
add: [
|
|
168
|
+
new Note({ add: [Instruments.Snare, Articulations.Fermata] }),
|
|
169
|
+
new Note({ add: [Instruments.Bass1, Articulations.Accent] }),
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
const other = new Chord({
|
|
173
|
+
add: [
|
|
174
|
+
new Note({ add: [Instruments.Snare, Articulations.Staccato] }),
|
|
175
|
+
new Note({ add: [Instruments.Claves, Articulations.Fermata] }),
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(chord.isEqual(other), false);
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
title:
|
|
184
|
+
"isEqual fails when comparing chords with same instruments (different articulations)",
|
|
185
|
+
test: () => {
|
|
186
|
+
const chord = new Chord({
|
|
187
|
+
add: [
|
|
188
|
+
new Note({ add: [Instruments.Snare, Articulations.Fermata] }),
|
|
189
|
+
new Note({ add: [Instruments.Bass1, Articulations.Accent] }),
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
const other = new Chord({
|
|
193
|
+
add: [
|
|
194
|
+
new Note({ add: [Instruments.Snare, Articulations.Staccato] }),
|
|
195
|
+
new Note({ add: [Instruments.Bass1, Articulations.Fermata] }),
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
expect(chord.isEqual(other), false);
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
{
|
|
204
|
+
title:
|
|
205
|
+
"internalAdd correctly merges notes",
|
|
206
|
+
test: () => {
|
|
207
|
+
const chord = new Chord({
|
|
208
|
+
add: [
|
|
209
|
+
new Note({ add: [Instruments.Snare, Articulations.Fermata] }),
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
const note = new Note({
|
|
213
|
+
add: [
|
|
214
|
+
Instruments.Snare,
|
|
215
|
+
new ArticulationSet({add: [ Articulations.Staccato, Articulations.Accent ]})
|
|
216
|
+
]
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
chord.internalAdd(note);
|
|
220
|
+
|
|
221
|
+
expect(chord.size, 1);
|
|
222
|
+
expect(chord.elementAt(0).instrument === Instruments.Snare, true);
|
|
223
|
+
const articulations = chord.elementAt(0).articulations;
|
|
224
|
+
expect(articulations !== undefined, true);
|
|
225
|
+
expect(articulations.elementAt(0) === Articulations.Fermata, true);
|
|
226
|
+
expect(articulations.elementAt(1) === Articulations.Staccato, true);
|
|
227
|
+
expect(articulations.elementAt(2) === Articulations.Accent, true);
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
title:
|
|
232
|
+
"internalAdd correctly adds notes with different instruments",
|
|
233
|
+
test: () => {
|
|
234
|
+
const chord = new Chord({
|
|
235
|
+
add: [
|
|
236
|
+
new Note({ add: [Instruments.Snare, Articulations.Fermata] }),
|
|
237
|
+
],
|
|
238
|
+
});
|
|
239
|
+
const note = new Note({
|
|
240
|
+
add: [
|
|
241
|
+
Instruments.Bass1,
|
|
242
|
+
new ArticulationSet({add: [ Articulations.Staccato, Articulations.Accent ]})
|
|
243
|
+
]
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
chord.internalAdd(note);
|
|
247
|
+
|
|
248
|
+
expect(chord.size, 2);
|
|
249
|
+
expect(chord.elementAt(0).instrument === Instruments.Snare, true);
|
|
250
|
+
expect(chord.elementAt(1).instrument === Instruments.Bass1, true);
|
|
251
|
+
expect(chord.elementAt(0).articulations !== undefined, true);
|
|
252
|
+
expect(chord.elementAt(0).articulations.elementAt(0) === Articulations.Fermata, true);
|
|
253
|
+
const articulations = chord.elementAt(1).articulations;
|
|
254
|
+
expect(articulations !== undefined, true);
|
|
255
|
+
expect(articulations.elementAt(0) === Articulations.Staccato, true);
|
|
256
|
+
expect(articulations.elementAt(1) === Articulations.Accent, true);
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
{
|
|
261
|
+
title:
|
|
262
|
+
"toNoteSet correctly returns equivalent note chord",
|
|
263
|
+
test: () => {
|
|
264
|
+
const chord = new Chord({
|
|
265
|
+
add: [
|
|
266
|
+
new Note({ add: [Instruments.Snare, Articulations.Fermata] }),
|
|
267
|
+
new Note({
|
|
268
|
+
add: [
|
|
269
|
+
Instruments.Bass1,
|
|
270
|
+
new ArticulationSet({add: [ Articulations.Staccato, Articulations.Accent ]})
|
|
271
|
+
]
|
|
272
|
+
})
|
|
273
|
+
],
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const noteset = chord.toNoteSet();
|
|
277
|
+
|
|
278
|
+
expect(noteset instanceof NoteSet, true);
|
|
279
|
+
expect(noteset.size, 2);
|
|
280
|
+
expect(noteset.elementAt(0).instrument === Instruments.Snare, true);
|
|
281
|
+
expect(noteset.elementAt(1).instrument === Instruments.Bass1, true);
|
|
282
|
+
expect(noteset.elementAt(0).articulations !== undefined, true);
|
|
283
|
+
expect(noteset.elementAt(0).articulations.elementAt(0) === Articulations.Fermata, true);
|
|
284
|
+
const articulations = noteset.elementAt(1).articulations;
|
|
285
|
+
expect(articulations !== undefined, true);
|
|
286
|
+
expect(articulations.elementAt(0) === Articulations.Staccato, true);
|
|
287
|
+
expect(articulations.elementAt(1) === Articulations.Accent, true);
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
],
|
|
292
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// concolour.mjs
|
|
2
|
+
//
|
|
3
|
+
// Console and console text colour..
|
|
4
|
+
|
|
5
|
+
const timestamp = () => {
|
|
6
|
+
const now = new Date();
|
|
7
|
+
return `${now.toLocaleDateString()} ${now.toLocaleTimeString()}`;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
reset: "\x1b[0m",
|
|
12
|
+
bright: "\x1b[1m",
|
|
13
|
+
dim: "\x1b[2m",
|
|
14
|
+
underscore: "\x1b[4m",
|
|
15
|
+
blink: "\x1b[5m",
|
|
16
|
+
reverse: "\x1b[7m",
|
|
17
|
+
hidden: "\x1b[8m",
|
|
18
|
+
|
|
19
|
+
fg: {
|
|
20
|
+
black: "\x1b[30m",
|
|
21
|
+
red: "\x1b[31m",
|
|
22
|
+
green: "\x1b[32m",
|
|
23
|
+
yellow: "\x1b[33m",
|
|
24
|
+
blue: "\x1b[34m",
|
|
25
|
+
magenta: "\x1b[35m",
|
|
26
|
+
cyan: "\x1b[36m",
|
|
27
|
+
white: "\x1b[37m",
|
|
28
|
+
gray: "\x1b[90m",
|
|
29
|
+
brightred: "\x1b[91m",
|
|
30
|
+
brightgreen: "\x1b[92m",
|
|
31
|
+
brightyellow: "\x1b[93m",
|
|
32
|
+
brightblue: "\x1b[94m",
|
|
33
|
+
brightmagenta: "\x1b[95m",
|
|
34
|
+
brightcyan: "\x1b[96m",
|
|
35
|
+
brightwhite: "\x1b[97m",
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
bg: {
|
|
39
|
+
black: "\x1b[40m",
|
|
40
|
+
red: "\x1b[41m",
|
|
41
|
+
green: "\x1b[42m",
|
|
42
|
+
yellow: "\x1b[43m",
|
|
43
|
+
blue: "\x1b[44m",
|
|
44
|
+
magenta: "\x1b[45m",
|
|
45
|
+
cyan: "\x1b[46m",
|
|
46
|
+
white: "\x1b[47m",
|
|
47
|
+
gray: "\x1b[100m",
|
|
48
|
+
brightred: "\x1b[101m",
|
|
49
|
+
brightgreen: "\x1b[102m",
|
|
50
|
+
brightyellow: "\x1b[103m",
|
|
51
|
+
brightblue: "\x1b[104m",
|
|
52
|
+
brightmagenta: "\x1b[105m",
|
|
53
|
+
brightcyan: "\x1b[106m",
|
|
54
|
+
brightwhite: "\x1b[107m",
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
log: function(message, colour = this.fg.white, bgcolour = "", options = {}) {
|
|
58
|
+
if (options.suffix) {
|
|
59
|
+
process.stdout.write(`${colour}${bgcolour}${message}${this.reset}\n`);
|
|
60
|
+
} else {
|
|
61
|
+
const output = `${colour}${bgcolour}[${timestamp()}] ${message}${this.reset}`;
|
|
62
|
+
|
|
63
|
+
if (options.prefix) {
|
|
64
|
+
process.stdout.write(output);
|
|
65
|
+
} else {
|
|
66
|
+
console.log(output);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
}
|