Skip to content

Instantly share code, notes, and snippets.

@eleses
Last active May 23, 2020 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eleses/abed028654f5736678e610a0aef6fe22 to your computer and use it in GitHub Desktop.
Save eleses/abed028654f5736678e610a0aef6fe22 to your computer and use it in GitHub Desktop.
Cleanup unittest; now with working Ppar
/* 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]);
};
};
}
@eleses
Copy link
Author

eleses commented Mar 12, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment