changed test

This commit is contained in:
2018-03-11 17:48:07 +01:00
parent f0fb4a6cef
commit 865c3c6429
2 changed files with 37 additions and 39 deletions

View File

@@ -102,17 +102,21 @@ public class Worm {
if (!isValidMinRadius(minRadius)) if (!isValidMinRadius(minRadius))
throw new IllegalArgumentException("Invalid min radius"); // TODO add decent exception msg 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"); throw new IllegalArgumentException("Invalid radius");
setRadius(radius); setRadius(radius);
this.minRadius = minRadius;
setActionPoints(getMaxActionPoints()); setActionPoints(getMaxActionPoints());
int validName = isValidName(name); int validName = isValidName(name);
if (validName != -1) if (validName != -1)
throw new IllegalNameException(validName, name); throw new IllegalNameException(validName, name);
this.name = name; this.name = name;
Tuple<Integer, Integer> test = null;
} }
//=================================================================================== //===================================================================================
@@ -231,13 +235,13 @@ public class Worm {
/** /**
* check whether the given radius is a valid minimum radius for the worm * check whether the given radius is a valid minimum radius for the worm
* *
* @param radius * @param minRadius
* the radius to check * the radius to check
* @return True if and only if the radius is a number and the radius is bigger then 0 * @return True if and only if the radius is a number and the radius is bigger then 0
* |result == ((!Double.isNaN(radius)) && (radius > 0)) * |result == ((!Double.isNaN(radius)) && (radius > 0))
*/ */
public static boolean isValidMinRadius(double radius) { public static boolean isValidMinRadius(double minRadius) {
return !Double.isNaN(radius) && radius > 0; return !Double.isNaN(minRadius) && minRadius > 0;
} }
/** /**
@@ -252,7 +256,7 @@ public class Worm {
* |! canHaveAsMinRadius(radius) * |! canHaveAsMinRadius(radius)
*/ */
public void setRadius(double radius) throws IllegalArgumentException { public void setRadius(double radius) throws IllegalArgumentException {
if (!canHaveAsMinRadius(radius)) if (!canHaveAsRadius(radius))
throw new IllegalArgumentException("Invalid radius"); throw new IllegalArgumentException("Invalid radius");
this.radius = radius; this.radius = radius;
@@ -290,8 +294,8 @@ public class Worm {
* (or equal) and the radius is a number * (or equal) and the radius is a number
* |result == (radius >= this.minRadius && !Double.isNaN(radius)) * |result == (radius >= this.minRadius && !Double.isNaN(radius))
*/ */
private boolean canHaveAsMinRadius(double radius) { private boolean canHaveAsRadius(double radius) {
return radius >= getMinRadius() && !Double.isNaN(radius); return !Double.isNaN(radius) && radius >= getMinRadius();
} }
/** /**

View File

@@ -1,13 +1,13 @@
package worms.model; package worms.model;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import worms.util.Tuple; import worms.util.Tuple;
class WormTest { class WormTest {
private Worm worm; /*private Worm worm;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
@@ -24,7 +24,7 @@ class WormTest {
void getOrientation() { void getOrientation() {
assertEquals(0, worm.getOrientation()); assertEquals(0, worm.getOrientation());
} }
@Test @Test
void getRadius() { void getRadius() {
assertEquals(1, worm.getRadius()); assertEquals(1, worm.getRadius());
@@ -35,12 +35,7 @@ class WormTest {
worm.setRadius(2); worm.setRadius(2);
assertEquals(2, worm.getRadius()); assertEquals(2, worm.getRadius());
} }
/**@Test //TODO mag niet voorkomen => exception (hoe doe je dat?)
void setRadius2() {
worm.setRadius(0.02);
}*/
@Test @Test
void getMinimumRadius() { void getMinimumRadius() {
assertEquals(0.25, worm.getMinRadius()); assertEquals(0.25, worm.getMinRadius());
@@ -49,18 +44,10 @@ class WormTest {
@Test @Test
void getMass1() { void getMass1() {
assertEquals(4448.0, worm.getMass()); assertEquals(4448.0, worm.getMass());
//Leen: ik heb bij de setMass round rond de formule gezet, anders was test fout. //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 //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 @Test
void getActionPoints() { void getActionPoints() {
@@ -93,30 +80,37 @@ class WormTest {
worm.setName("Jefke Janssens"); worm.setName("Jefke Janssens");
assertEquals("Jefke Janssens", worm.getName()); assertEquals("Jefke Janssens", worm.getName());
} }
@Test @Test
void setName2() { void setName2() {
worm.setName("Jefke 'anssens"); worm.setName("Jefke 'anssens");
assertEquals("Jefke 'anssens", worm.getName()); 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 @Test
void move() { void move() {
assertEquals("Test", worm.getName());
} }
@Test @Test
void turn() { void turn() {
} }
@Test @RepeatedTest(10)
void jump() { void jump(RepetitionInfo repetitionInfo) {
} if (repetitionInfo.getCurrentRepetition() > 1){
assertThrows(IllegalStateException.class, () -> worm.jump());
}
else {
worm.jump();
}
@Test
void jumpTime() {
}
@Test
void jumpStep() {
} }
} }