From 865c3c64295da50778a4035eee589f7b918aa535 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Sun, 11 Mar 2018 17:48:07 +0100 Subject: [PATCH] changed test --- OGP1718-Worms/src/worms/model/Worm.java | 20 ++++--- OGP1718-Worms/tests/worms/model/WormTest.java | 56 +++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 3eb13e4..2a1fbd2 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -102,17 +102,21 @@ public class Worm { if (!isValidMinRadius(minRadius)) throw new IllegalArgumentException("Invalid min radius"); // TODO add decent exception msg - if (!canHaveAsMinRadius(radius)) + this.minRadius = minRadius; + + if (!canHaveAsRadius(radius)) throw new IllegalArgumentException("Invalid radius"); setRadius(radius); - this.minRadius = minRadius; + setActionPoints(getMaxActionPoints()); int validName = isValidName(name); if (validName != -1) throw new IllegalNameException(validName, name); this.name = name; + + Tuple test = null; } //=================================================================================== @@ -231,13 +235,13 @@ public class Worm { /** * check whether the given radius is a valid minimum radius for the worm * - * @param radius + * @param minRadius * the radius to check * @return True if and only if the radius is a number and the radius is bigger then 0 * |result == ((!Double.isNaN(radius)) && (radius > 0)) */ - public static boolean isValidMinRadius(double radius) { - return !Double.isNaN(radius) && radius > 0; + public static boolean isValidMinRadius(double minRadius) { + return !Double.isNaN(minRadius) && minRadius > 0; } /** @@ -252,7 +256,7 @@ public class Worm { * |! canHaveAsMinRadius(radius) */ public void setRadius(double radius) throws IllegalArgumentException { - if (!canHaveAsMinRadius(radius)) + if (!canHaveAsRadius(radius)) throw new IllegalArgumentException("Invalid radius"); this.radius = radius; @@ -290,8 +294,8 @@ public class Worm { * (or equal) and the radius is a number * |result == (radius >= this.minRadius && !Double.isNaN(radius)) */ - private boolean canHaveAsMinRadius(double radius) { - return radius >= getMinRadius() && !Double.isNaN(radius); + private boolean canHaveAsRadius(double radius) { + return !Double.isNaN(radius) && radius >= getMinRadius(); } /** diff --git a/OGP1718-Worms/tests/worms/model/WormTest.java b/OGP1718-Worms/tests/worms/model/WormTest.java index 34f7adb..716f10d 100644 --- a/OGP1718-Worms/tests/worms/model/WormTest.java +++ b/OGP1718-Worms/tests/worms/model/WormTest.java @@ -1,13 +1,13 @@ package worms.model; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; + import static org.junit.jupiter.api.Assertions.*; import worms.util.Tuple; class WormTest { - private Worm worm; + /*private Worm worm; @BeforeEach void setUp() { @@ -24,7 +24,7 @@ class WormTest { void getOrientation() { assertEquals(0, worm.getOrientation()); } - + @Test void getRadius() { assertEquals(1, worm.getRadius()); @@ -35,12 +35,7 @@ class WormTest { worm.setRadius(2); assertEquals(2, worm.getRadius()); } - - /**@Test //TODO mag niet voorkomen => exception (hoe doe je dat?) - void setRadius2() { - worm.setRadius(0.02); - }*/ - + @Test void getMinimumRadius() { assertEquals(0.25, worm.getMinRadius()); @@ -49,18 +44,10 @@ class WormTest { @Test void getMass1() { assertEquals(4448.0, worm.getMass()); - - //Leen: ik heb bij de setMass round rond de formule gezet, anders was test fout. - //Moet dit round of ceil zijn? Ik dacht round, maar ben niet zeker + + //Leen: ik heb bij de setMass round rond de formule gezet, anders was test fout. + //Moet dit round of ceil zijn? Ik dacht round, maar ben niet zeker } - - /** @Test TODO was een idee voor een testfunctie, maar setOrientation - * is private, dus misschien moet dit niet - void getMass2() { - worm.setOrientation(Math.PI/2); - assertEquals(Math.PI/2, worm.getOrientation()); - assertEquals(17241, worm.getMass()); - }*/ @Test void getActionPoints() { @@ -93,30 +80,37 @@ class WormTest { worm.setName("Jefke Janssens"); assertEquals("Jefke Janssens", worm.getName()); } - + @Test void setName2() { worm.setName("Jefke 'anssens"); assertEquals("Jefke 'anssens", worm.getName()); + }*/ + + private static Worm worm; + + @BeforeAll + static void setUp() { + worm = new Worm(Tuple.create(0.0, 0.0), 0, "Test", 1); } @Test void move() { + assertEquals("Test", worm.getName()); } @Test void turn() { } - @Test - void jump() { - } + @RepeatedTest(10) + void jump(RepetitionInfo repetitionInfo) { + if (repetitionInfo.getCurrentRepetition() > 1){ + assertThrows(IllegalStateException.class, () -> worm.jump()); + } + else { + worm.jump(); + } - @Test - void jumpTime() { - } - - @Test - void jumpStep() { } } \ No newline at end of file