This commit is contained in:
2018-03-30 16:40:00 +02:00
parent b613303b29
commit 049d3ba14b
3 changed files with 9 additions and 10 deletions

View File

@@ -384,7 +384,6 @@ public class Facade implements IFacade {
}
/**
* <<<<<<< HEAD
* Create and return a new worm that is positioned at the given location, looks
* in the given direction, has the given radius and the given name.
*

View File

@@ -595,7 +595,7 @@ public class Worm {
public void collision(Worm smallestWorm, Worm largestWorm) {
long total = 1 + (new Random().nextLong() * (10 - 1));
long loseSmallest = total/(largestWorm.getOrientation()/(smallestWorm.getOrientation()+largestWorm.getOrientation()));
long loseSmallest = (long) (total / (largestWorm.getOrientation() / (smallestWorm.getOrientation() + largestWorm.getOrientation())));
long loseLargest = total - loseSmallest;
smallestWorm.decreaseHitPoints(loseSmallest);
largestWorm.decreaseHitPoints(loseLargest);

View File

@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;
import static org.junit.jupiter.api.Assertions.*;
import worms.util.Tuple;
import worms.util.Coordinate;
import java.util.Random;
@@ -15,12 +15,12 @@ class WormTest {
@BeforeAll
static void setUp() {
worm = new Worm(Tuple.create(0.0, 0.0), 0, "Test", 1);
worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
}
@RepeatedTest(5000)
void move() {
worm = new Worm(Tuple.create(0.0, 0.0), 0, "Test", 1);
worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
int steps = r.nextInt(5101) - 100;
double maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
double minAngle = worm.getOrientation();
@@ -36,7 +36,7 @@ class WormTest {
double newLocX = worm.getLocation().item1 + steps * worm.getRadius() * Math.cos(worm.getOrientation());
double newLocY = worm.getLocation().item2 + steps * worm.getRadius() * Math.sin(worm.getOrientation());
worm.move(steps);
assertEquals(Tuple.create(newLocX, newLocY), worm.getLocation());
assertEquals(Coordinate.create(newLocX, newLocY), worm.getLocation());
}
}
@@ -47,7 +47,7 @@ class WormTest {
if (!Worm.isValidOrientation(oldAngle + angle) || worm.getActionPoints() - (long) Math.ceil(Math.toDegrees(angle) / 6) < 0) {
assertThrows(AssertionError.class, () -> worm.turn(angle));
worm = new Worm(Tuple.create(0.0, 0.0), 0, "Test", 1);
worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
}
else {
worm.turn(angle);
@@ -64,7 +64,7 @@ class WormTest {
@RepeatedTest(5000)
void jump() {
worm = new Worm(Tuple.create(0.0, 0.0), 0, "Test", 1);
worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
double maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
double minAngle = worm.getOrientation();
double combAngle = maxAngle + minAngle;
@@ -82,12 +82,12 @@ class WormTest {
double v = force / worm.getMass() * Worm.FORCE_TIME;
double newLocX = worm.getLocation().item1 + Math.pow(v, 2) * Math.sin(2 * orient) / Worm.G;
worm.jump();
assertEquals(Tuple.create(newLocX, worm.getLocation().item2), worm.getLocation());
assertEquals(Coordinate.create(newLocX, worm.getLocation().getCoordinateY()), worm.getLocation());
}
}
@Test
void doubleJump() {
worm = new Worm(Tuple.create(0.0, 0.0), 0, "Test", 1);
worm = new Worm(Coordinate.create(0.0, 0.0), 0, "Test", 1);
worm.jump();
assertThrows(IllegalStateException.class, () -> worm.jump());
}