Skip to content

Instantly share code, notes, and snippets.

@scottoffen
Last active January 1, 2016 06:29
Show Gist options
  • Save scottoffen/8105783 to your computer and use it in GitHub Desktop.
Save scottoffen/8105783 to your computer and use it in GitHub Desktop.
Groovy test case for the song Particle Man by TMBG!
import groovy.util.GroovyTestCase;
class TestMan extends GroovyTestCase
{
def particleMan = new Man(Man.Type.Particle);
def triangleMan = new Man(Man.Type.Triangle);
def universeMan = new Man(Man.Type.Universe);
def personMan = new Man(Man.Type.Person);
void testParticleMan ()
{
assert particleMan == new Man(Man.Type.Particle);
// should extend Particle
assert particleMan in Particle;
/* This is not important
*assert particleMan.hasProperty('...');
*assert particleMan.respondsTo('...', '...');
*/
assert particleMan; // Maybe should have checked this first?
// Dump current state
println ("isDot : " + particleMan.isDot());
println ("isSpeck : " + particleMan.isSpeck());
def underWater = "Nobody knows";
if (particleMan.respondsTo('getWet'))
{
underWater = "He gets wet";
}
else if ((Water.respondsTo('getParticle', [ particleMan ])) || (Water.respondsTo('getParticleMan', [ particleMan ])))
{
underWater = "Water gets him";
}
println ("When underwater: " + underWater);
println ("It's about time we knew!");
assert particleMan; // Does this need to be checked again?
}
void testTriangleMan ()
{
assert triangleMan == new Man(Man.Type.Triangle);
assert triangleMan.hates(particleMan);
assert Man.whoWinsFight(triangleMan, particleMan) == triangleMan;
assert triangleMan(); // This is in the wrong place
}
void testUniverseMan ()
{
assert universeMan == new Man(Man.Type.Universe);
assert universeMan.radius >= 46000000000; // in light years (ly)
assert universeMan.dispositionTowardsSmallerMan() == 'usually kind';
assert universeMan(); // Once again, check this first, maybe?
def watch = universeMan.getWatch();
assert watch; // false if no watch found
if (watch)
{
assert watch.hasHandType(Watch.HandType.Minute);
assert watch.hasHandType(Watch.HandType.Millennum);
assert watch.hasHandType(Watch.HandType.Eon);
}
def land_state = watch.whenHandsMeet();
assert land_state == 'happy';
assert universeMan.isPowerful();
assert universeMan(); // Nothing changed, what's the point of this?!?
}
void testPersonMan ()
{
assert personMan == new Man(Man.Type.Person);
personMan.hitOnHeadWith(new Pan(Pan.Type.Frying));
personMan.liveLifeIn(new Can(Can.Type.Garbage));
assert personMan; // What changed?
// Dump current state
println ("isDepressed : " + personMan.isDepressed());
println ("isAMess : " + personMan.isAMess());
println ("feelsTotallyWorthless : " + personMan.feelsTotallyWorthless());
// A method (presumably a property getter?) called feelsTotallyWorthless?
// Who came up with this Man.Type.Person?
assert personMan == new Man(Man.Type.Degraded); // Seriously? Just deprecate this already!
assert personMan; // Stop doing this!
}
void testTriangleVsPerson ()
{
// This is a complete duplicate! Why do we have this twice?
assert triangleMan == new Man(Man.Type.Triangle);
assert triangleMan.hates(personMan);
assert Man.whoWinsFight(triangleMan, personMan) == triangleMan;
assert triangleMan(); // I give up, do whatever you want
}
}
@bletalien
Copy link

Just stumbled upon this. Needed the laugh. Thanks!

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