From c34141571e1295885c2e52832290d63f12c9312f Mon Sep 17 00:00:00 2001 From: Austin Funes Date: Thu, 30 Apr 2015 16:32:27 -0400 Subject: [PATCH] StatGui and MinionMock tests --- src/MinionMock.java | 2 ++ src/tests/MinonTests.java | 62 +++++++++++++++++++++++++++++++++++-- src/tests/StatGuiTests.java | 37 ++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/tests/StatGuiTests.java diff --git a/src/MinionMock.java b/src/MinionMock.java index c02fa5a..1eadbcf 100644 --- a/src/MinionMock.java +++ b/src/MinionMock.java @@ -116,6 +116,8 @@ public class MinionMock { public void minionTakeHit(int damage) { health-=damage; + if(health <= 0) + alive= false; } public void minionTakeDamage() { diff --git a/src/tests/MinonTests.java b/src/tests/MinonTests.java index de21524..d6b48ef 100644 --- a/src/tests/MinonTests.java +++ b/src/tests/MinonTests.java @@ -1,5 +1,63 @@ -package tests; -public class MinonTests { +import junit.framework.TestCase; +public class MinonTests extends TestCase{ + + private static int[][] nodes; + private static final int NUM = 6; + private MinionMock testMinion; + + protected void setUp()throws Exception{ + nodes = new int[NUM][2];//setting up nodes for the map + nodes[0][0] = 1; + nodes[0][1] = 3; + nodes[1][0] = 16; + nodes[1][1] = 3; + nodes[2][0] = 16; + nodes[2][1] = 9; + nodes[3][0] = 4; + nodes[3][1] = 9; + nodes[4][0] = 4; + nodes[4][1] = 15; + nodes[5][0] = 18; + nodes[5][1] = 15; + + MockGui mg = new MockGui(640,640,32, NUM, nodes); + StatGui sg= new StatGui(0,0); + MapTowerDefense map = new MapTowerDefense(100, NUM, nodes, mg, sg); + + testMinion= new MinionMock(MinionTypes.BASIC, map); + } + + public void testInitialLocation() throws Exception{ + System.out.println("X= "+testMinion.getX() + " Y= "+testMinion.getY()); + + assertEquals(testMinion.getX(),32); + assertEquals(testMinion.getY(),96); + } + + public void testHealth() throws Exception{ + assertEquals(testMinion.getHealth(),255); + } + + public void testDamage() throws Exception{ + testMinion.minionTakeHit(20); + assertEquals(testMinion.getHealth(),235); + } + + public void testMinionType() throws Exception{ + System.out.println(testMinion.getName()); + assertEquals(testMinion.getName(), "BASIC"); + } + + public void testAlive() throws Exception{ + assertTrue(testMinion.isAlive()); + } + + public void testNotAlive() throws Exception{ + testMinion.minionTakeHit(testMinion.getHealth()); + assertFalse(testMinion.isAlive()); + } + + } diff --git a/src/tests/StatGuiTests.java b/src/tests/StatGuiTests.java new file mode 100644 index 0000000..bee19e8 --- /dev/null +++ b/src/tests/StatGuiTests.java @@ -0,0 +1,37 @@ +package tests; +import StatGui; +import junit.framework.TestCase; + + +public class StatGuiTests extends TestCase { + + private StatGui sg; + + protected void setUp() throws Exception{ + sg= new StatGui(0,0); + } + + public void testMoney() throws Exception{ + assertEquals(sg.getMoney(), 1000); + } + + public void testCanAfford() throws Exception{ + assertTrue(sg.canAfford(sg.getMoney())); + assertFalse(sg.canAfford(sg.getMoney()+10)); + } + + public void testSpendMoney() throws Exception{ + assertTrue(sg.spendMoney(sg.getMoney())); + } + + public void testPayDay() throws Exception{ + sg.spendMoney(sg.getMoney()); + sg.payDay(100); + + assertEquals(sg.getMoney(), 100); + } + + + + +}