Skip to content

Instantly share code, notes, and snippets.

@andrewcsmith
Last active January 4, 2016 05:19
Show Gist options
  • Save andrewcsmith/8573993 to your computer and use it in GitHub Desktop.
Save andrewcsmith/8573993 to your computer and use it in GitHub Desktop.
UnitTest class and usage that I'm working on
UnitTest {
var <assertionCount = 0, <successCount = 0, <failureCount = 0;
test {
arg name, func;
("Testing: " ++ name).postln;
func.value(this);
("Assertions: " ++ assertionCount ++ "\t Successes: " ++ successCount ++ "\t Failures: " ++ failureCount).postln;
}
assert {
arg truthValue;
assertionCount = assertionCount+1;
truthValue = truthValue.value;
if(truthValue,
{ successCount = successCount+1 },
{ failureCount = failureCount+1 }
);
^truthValue;
}
}
(
u = UnitTest.new;
u.test("that true is true", {
arg self;
self.assert({true});
self.assert({1 > 0});
self.assert({false});
});
)
/* Prints the following:
Testing: that true is true
Assertions: 3 Successes: 2 Failures: 1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment