Last active
May 23, 2020 12:59
-
-
Save eleses/abed028654f5736678e610a0aef6fe22 to your computer and use it in GitHub Desktop.
Cleanup unittest; now with working Ppar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* an UnitTestScript for cleanup chaining */ | |
{ |test| | |
var exhaust = { arg pat, ie = (); | |
var cu = EventStreamCleanup.new, oe = nil, str = pat.asStream; | |
var hist = List().add(cu.functions.size); | |
while({ | |
oe = str.next(ie); | |
cu.update(ie); | |
hist.add(cu.functions.size); | |
//[\ULEC, oe, ie, cu.functions.size].postln; | |
hist.size < 100 && oe.notNil}); | |
[hist, ie]; | |
}; | |
var t10y = {arg patfn, ie = (); | |
var icnt = 0, ccnt = 0; | |
var inj = Pfset({icnt = icnt + 1}, p{|ev| ev.yield}, { ccnt = ccnt + 1}); | |
exhaust.(patfn.(inj), ie); | |
[icnt, ccnt]; | |
}; | |
var testPfs = [ | |
{ |x| Pn(x, 1) }, | |
{ |x| Pn(x, 3) }, | |
{ |x| Pn(x, 0) }, | |
{ |x| Pchain(x) }, | |
{ |x| Pchain(x, x) }, | |
{ |x| Pcollect({ |ev| ev }, x) }, | |
{ |x| Pcollect({ |ev| ev.copy }, x) }, | |
{ |x| Pseq([x]) }, | |
{ |x| Pseq([x, x]) }, | |
{ |x| Pseq([x, (y: 10)]) }, | |
{ |x| Psetpre(\gg, 8, x) }, | |
{ |x| Psetpre(\hh, Pseq([nil]), x) }, | |
{ |x| Psetpre(\xx, x, Pseq([nil])) }, | |
{ |x| Psetpre(\zz, x, Pseq([ () ])) }, | |
]; | |
var testPfsDur = [ // these need a duration pre-set externally | |
{ |x| Ppar([x, Pseq([ () ])]) }, | |
{ |x| Ppar([x, x]) }, | |
]; | |
"\nBegin basic cleanup tests".postln; | |
testPfs.do { |pf| | |
var cntPairs = t10y.(pf); | |
test.assert(cntPairs[0] == cntPairs[1], "Cleanup propagation" + | |
pf.cs + "inits:" + cntPairs[0] ++ ", cleanups:" + cntPairs[1]); | |
}; | |
testPfs.do { |pf| | |
testPfs.do { |pf2| | |
var cntPairs = t10y.(pf <> pf2); | |
test.assert(cntPairs[0] == cntPairs[1], "Cleanup propagation" + | |
// (pf <> pf2).cs doesn't print anything useful | |
pf.cs + "<>" + pf2.cs + "inits:" + cntPairs[0] ++ ", cleanups:" + cntPairs[1]); | |
}; | |
}; | |
"\nBegin duration-based cleanup tests".postln; | |
testPfsDur.do { |pf| | |
var cntPairs = t10y.(pf, (dur: 0.2)); | |
test.assert(cntPairs[0] == cntPairs[1], "Cleanup propagation" + | |
pf.cs + "inits:" + cntPairs[0] ++ ", cleanups:" + cntPairs[1]); | |
}; | |
testPfsDur.do { |pf| | |
testPfs.do { |pf2| | |
var cntPairs = t10y.(pf <> pf2, (dur: 0.2)); | |
test.assert(cntPairs[0] == cntPairs[1], "Cleanup propagation" + | |
pf.cs + "<>" + pf2.cs + "inits:" + cntPairs[0] ++ ", cleanups:" + cntPairs[1]); | |
}; | |
}; | |
testPfs.do { |pf| | |
testPfsDur.do { |pf2| | |
var cntPairs = t10y.(pf <> pf2, (dur: 0.2)); | |
test.assert(cntPairs[0] == cntPairs[1], "Cleanup propagation" + | |
pf.cs + "<>" + pf2.cs + "inits:" + cntPairs[0] ++ ", cleanups:" + cntPairs[1]); | |
}; | |
}; | |
testPfsDur.do { |pf| | |
testPfsDur.do { |pf2| | |
var cntPairs = t10y.(pf <> pf2, (dur: 0.2)); | |
test.assert(cntPairs[0] == cntPairs[1], "Cleanup propagation" + | |
pf.cs + "<>" + pf2.cs + "inits:" + cntPairs[0] ++ ", cleanups:" + cntPairs[1]); | |
}; | |
}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the Thunk-based cleanup:
UNIT TEST.............
There were failures:
an UnitTestScript: MyTest - Cleanup propagation { |x| Psetpre(\xx, x, Pseq([nil])) } <> { |x| Pchain(x) } inits: 1, cleanups: 0
an UnitTestScript: MyTest - Cleanup propagation { |x| Psetpre(\xx, x, Pseq([nil])) } <> { |x| Pchain(x, x) } inits: 2, cleanups: 0
an UnitTestScript: MyTest - Cleanup propagation { |x| Psetpre(\xx, x, Pseq([nil])) } <> { |x| Psetpre(\gg, 8, x) } inits: 1, cleanups: 0