// Test the hasWon() method void testHasWon(Tester t) { resetPlayer(); t.checkExpect(player.hasWon(), false); resetPlayer(); player.score = 100000; t.checkExpect(player.hasWon(), true); }
// test the updateStats method void testUpdateStats(Tester t) { player.updateStats(avocado); t.checkExpect(player, new Player(751f, 7.7f, 600, new Posn(0, CollectTheFruit.height - 30))); resetPlayer(); player.updateStats(twinkie); t.checkExpect(player, new Player(630f, 3.9f, 0, new Posn(0, CollectTheFruit.height - 30))); }
// test the changeSpeed method void testChangeSpeed(Tester t) { resetPlayer(); player.changeSpeed(0.1f); t.checkExpect(player.speed, 6.4f); resetPlayer(); player.changeSpeed(-0.1f); t.checkExpect(player.speed, 5.4f); }
// Test the IsDead() method void testIsDead(Tester t) { resetPlayer(); t.checkExpect(player.isDead(), false); resetPlayer(); player.speed = 0; t.checkExpect(player.isDead(), true); resetPlayer(); player.hunger = 0; t.checkExpect(player.isDead(), true); }
// test the worldEnd method void testWorldEnd(Tester t) { t.checkExpect(ctf.worldEnds().worldEnds, false); resetCTF(); ctf.player.score = 300000; t.checkExpect(ctf.worldEnds().worldEnds, true); resetCTF(); ctf.player.hunger = 0; t.checkExpect(ctf.worldEnds().worldEnds, true); resetCTF(); ctf.player.speed = 0; t.checkExpect(ctf.worldEnds().worldEnds, true); }
// test the changeHunger(int) and changeHunger(float) methods void testChangeHunger(Tester t) { resetPlayer(); player.changeHunger(0.1f); t.checkExpect(player.hunger, 730f); resetPlayer(); player.changeHunger(-0.1f); t.checkExpect(player.hunger, 630f); resetPlayer(); player.changeHunger(1); t.checkExpect(player.hunger, 701f); resetPlayer(); player.changeHunger(-1); t.checkExpect(player.hunger, 699f); player.changeHunger(-1000); t.checkExpect(player.hunger, 0f); player.changeHunger(-1000f); t.checkExpect(player.hunger, 0f); }
// test the changeScore method void testChangeScore(Tester t) { player.changeScore(100); t.checkExpect(player.score, 100); player.changeScore(-100); t.checkExpect(player.score, 0); }
// test the move method void testMove(Tester t) { player.move(500, 30); t.checkExpect(player.loc, new Posn(500, 350)); }