Skip to content

Commit

Permalink
Add some tests (#8)
Browse files Browse the repository at this point in the history
- Add `testMicrotones` in `convert_nn_to_freq.test.js`
- Add receive_mpe.test.js
  • Loading branch information
szk2s authored May 30, 2019
1 parent 4fb4e02 commit f798876
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 33 deletions.
4 changes: 2 additions & 2 deletions abstractions/receive_mpe.maxpat
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 50.0, 100.0, 83.0, 22.0 ],
"text" : "prepend track"
"patching_rect" : [ 50.0, 100.0, 107.0, 22.0 ],
"text" : "prepend mpe_port"
}

}
Expand Down
14 changes: 6 additions & 8 deletions abstractions/send_mpe.maxpat
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 99.0, 100.0, 83.0, 22.0 ],
"text" : "prepend track"
"patching_rect" : [ 99.0, 100.0, 107.0, 22.0 ],
"text" : "prepend mpe_port"
}

}
Expand Down Expand Up @@ -88,7 +88,7 @@
"box" : {
"comment" : "data_to_send: any",
"id" : "obj-12",
"index" : 0,
"index" : 1,
"maxclass" : "inlet",
"numinlets" : 0,
"numoutlets" : 1,
Expand All @@ -99,9 +99,9 @@
}
, {
"box" : {
"comment" : "track_id: int | symbol",
"comment" : "target_id: int | symbol",
"id" : "obj-13",
"index" : 0,
"index" : 2,
"maxclass" : "inlet",
"numinlets" : 0,
"numoutlets" : 1,
Expand Down Expand Up @@ -146,9 +146,7 @@
}

}
],
"dependency_cache" : [ ],
"autosave" : 0
]
}

}
16 changes: 16 additions & 0 deletions projects/test/code/convert_nn_to_freq.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,21 @@ module.exports = {
parser.freq(44),
0.1
);
},
testMicroTone: function*(maxAPI) {
maxAPI.outlet({
convert_nn_to_freq: { inlet0: 60, inlet1: 8192 + 8192 / 4, inlet2: 1 }
});
expect(yield, 'Eighth higher than C=60').to.be.closeTo(
parser.freq(60.25),
0.1
);
maxAPI.outlet({
convert_nn_to_freq: { inlet0: 65, inlet1: 8192 - 8192 / 2, inlet2: 1 }
});
expect(yield, 'Quarter lower than F=65').to.be.closeTo(
parser.freq(64.5),
0.1
);
}
};
56 changes: 56 additions & 0 deletions projects/test/code/receive_mpe.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { assert } = require('chai');

module.exports = {
// Name of the patcher which you want to test
target: 'receive_mpe',

// `initPatcher` will be executed just before each test function.
initPatcher: function*(maxAPI) {
maxAPI.outlet({
send_mpe: { inlet1: 8888 },
receive_mpe: { inlet0: 8888 }
});
setTimeout(() => {
maxAPI.outlet({ send_mpe: { inlet0: 1 } });
}, 50);
assert.notEqual(yield, null, 'isOk');
},

// The key of each test generator function should start with 'test'
testReceiveNumber: function*(maxAPI) {
maxAPI.outlet({
send_mpe: { inlet0: 178 }
});
assert.deepEqual(yield, { outlet0: 178 }, 'natural number');
maxAPI.outlet({
send_mpe: { inlet1: 145 },
receive_mpe: { inlet0: 145 }
});
setTimeout(() => {
maxAPI.outlet({ send_mpe: { inlet0: -78.5 } });
}, 50);
assert.deepEqual(yield, { outlet0: -78.5 }, 'negative float');
},
testReceiveContinuously: function*(maxAPI) {
for (let i = 0; i < 3000; i++) {
maxAPI.outlet({
send_mpe: { inlet0: i }
});
assert.deepEqual(yield, { outlet0: i });
}
},
testReceiveList: function*(maxAPI) {
maxAPI.outlet({
send_mpe: { inlet1: 277 },
receive_mpe: { inlet0: 277 }
});
setTimeout(() => {
maxAPI.outlet({ send_mpe: { inlet0: [-0.3, 'hi', 5] } });
}, 50);
assert.deepEqual(
yield,
{ outlet0: [-0.3, 'hi', 5] },
'list of mixed types'
);
}
};
166 changes: 149 additions & 17 deletions projects/test/test.maxpat
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
,
"classnamespace" : "box",
"rect" : [ 34.0, 78.0, 942.0, 788.0 ],
"rect" : [ 1474.0, -102.0, 1420.0, 968.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
Expand Down Expand Up @@ -38,6 +38,79 @@
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"id" : "obj-1",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "dictionary" ],
"patching_rect" : [ 575.0, 387.0, 99.0, 22.0 ],
"text" : "dict.pack outlet0:"
}

}
, {
"box" : {
"id" : "obj-6",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 575.0, 431.0, 125.0, 22.0 ],
"text" : "prepend receive_mpe"
}

}
, {
"box" : {
"id" : "obj-5",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 575.0, 280.0, 105.0, 22.0 ],
"text" : "dict.unpack inlet0:"
}

}
, {
"box" : {
"id" : "obj-4",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 2,
"outlettype" : [ "", "" ],
"patching_rect" : [ 319.5, 280.0, 140.0, 22.0 ],
"text" : "dict.unpack inlet0: inlet1:"
}

}
, {
"box" : {
"color" : [ 0.96078431372549, 0.588235294117647, 0.152941176470588, 1.0 ],
"id" : "obj-3",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 575.0, 334.0, 77.0, 22.0 ],
"text" : "receive_mpe"
}

}
, {
"box" : {
"color" : [ 0.96078431372549, 0.588235294117647, 0.152941176470588, 1.0 ],
"id" : "obj-2",
"maxclass" : "newobj",
"numinlets" : 2,
"numoutlets" : 0,
"patching_rect" : [ 319.5, 334.0, 140.0, 22.0 ],
"text" : "send_mpe"
}

}
, {
"box" : {
"id" : "obj-8",
"maxclass" : "message",
Expand Down Expand Up @@ -72,18 +145,6 @@
"text" : "tdd"
}

}
, {
"box" : {
"id" : "obj-1",
"maxclass" : "newobj",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "dictionary" ],
"patching_rect" : [ 252.0, 494.0, 217.0, 22.0 ],
"text" : "dict.pack outlet0: outlet1: @triggers 0 1"
}

}
, {
"box" : {
Expand Down Expand Up @@ -127,15 +188,22 @@
"id" : "obj-12",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 64.0, 194.0, 179.0, 22.0 ],
"text" : "dict.unpack convert_nn_to_freq:"
"numoutlets" : 3,
"outlettype" : [ "", "", "" ],
"patching_rect" : [ 64.0, 194.0, 530.0, 22.0 ],
"text" : "dict.unpack convert_nn_to_freq: send_mpe: receive_mpe:"
}

}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-6", 0 ],
"source" : [ "obj-1", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-9", 2 ],
"source" : [ "obj-11", 2 ]
Expand All @@ -162,6 +230,20 @@
"source" : [ "obj-12", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-4", 0 ],
"source" : [ "obj-12", 1 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-5", 0 ],
"source" : [ "obj-12", 2 ]
}

}
, {
"patchline" : {
Expand All @@ -170,13 +252,49 @@
"source" : [ "obj-14", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"source" : [ "obj-3", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-12", 0 ],
"source" : [ "obj-30", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-2", 1 ],
"source" : [ "obj-4", 1 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"source" : [ "obj-4", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"source" : [ "obj-5", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-30", 0 ],
"midpoints" : [ 584.5, 512.0, 49.0, 512.0, 49.0, 77.0, 73.5, 77.0 ],
"source" : [ "obj-6", 0 ]
}

}
, {
"patchline" : {
Expand Down Expand Up @@ -228,6 +346,20 @@
"type" : "TEXT",
"implicit" : 1
}
, {
"name" : "send_mpe.maxpat",
"bootpath" : "~/repos/m4l-mpe-tools/abstractions",
"patcherrelativepath" : "../../abstractions",
"type" : "JSON",
"implicit" : 1
}
, {
"name" : "receive_mpe.maxpat",
"bootpath" : "~/repos/m4l-mpe-tools/abstractions",
"patcherrelativepath" : "../../abstractions",
"type" : "JSON",
"implicit" : 1
}
],
"autosave" : 0
}
Expand Down
12 changes: 6 additions & 6 deletions projects/test/test.maxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name" : "test",
"version" : 1,
"creationdate" : 3642055787,
"modificationdate" : 3642075359,
"modificationdate" : 3642082862,
"viewrect" : [ 0.0, 44.0, 361.0, 533.0 ],
"autoorganize" : 0,
"hideprojectwindow" : 0,
Expand Down Expand Up @@ -35,17 +35,17 @@
,
"searchpath" : {
"0" : {
"bootpath" : "~/repos/m4l-mpe-tools/node_modules/tdd-max",
"projectrelativepath" : "../../node_modules/tdd-max",
"label" : "node_modules/tdd-max",
"bootpath" : "~/repos/m4l-mpe-tools/abstractions",
"projectrelativepath" : "../../abstractions",
"label" : "",
"recursive" : 1,
"enabled" : 1,
"includeincollective" : 0
}
,
"1" : {
"bootpath" : "~/repos/m4l-mpe-tools/abstractions",
"projectrelativepath" : "../../abstractions",
"bootpath" : "~/repos/m4l-mpe-tools/node_modules/tdd-max",
"projectrelativepath" : "../../node_modules/tdd-max",
"label" : "",
"recursive" : 1,
"enabled" : 1,
Expand Down

0 comments on commit f798876

Please sign in to comment.