fixes
This commit is contained in:
@@ -384,7 +384,6 @@ public class Facade implements IFacade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <<<<<<< HEAD
|
|
||||||
* Create and return a new worm that is positioned at the given location, looks
|
* 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.
|
* in the given direction, has the given radius and the given name.
|
||||||
*
|
*
|
||||||
|
@@ -595,7 +595,7 @@ public class Worm {
|
|||||||
|
|
||||||
public void collision(Worm smallestWorm, Worm largestWorm) {
|
public void collision(Worm smallestWorm, Worm largestWorm) {
|
||||||
long total = 1 + (new Random().nextLong() * (10 - 1));
|
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;
|
long loseLargest = total - loseSmallest;
|
||||||
smallestWorm.decreaseHitPoints(loseSmallest);
|
smallestWorm.decreaseHitPoints(loseSmallest);
|
||||||
largestWorm.decreaseHitPoints(loseLargest);
|
largestWorm.decreaseHitPoints(loseLargest);
|
||||||
|
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.RepeatedTest;
|
import org.junit.jupiter.api.RepeatedTest;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import worms.util.Tuple;
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -15,12 +15,12 @@ class WormTest {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setUp() {
|
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)
|
@RepeatedTest(5000)
|
||||||
void move() {
|
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;
|
int steps = r.nextInt(5101) - 100;
|
||||||
double maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
|
double maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
|
||||||
double minAngle = 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 newLocX = worm.getLocation().item1 + steps * worm.getRadius() * Math.cos(worm.getOrientation());
|
||||||
double newLocY = worm.getLocation().item2 + steps * worm.getRadius() * Math.sin(worm.getOrientation());
|
double newLocY = worm.getLocation().item2 + steps * worm.getRadius() * Math.sin(worm.getOrientation());
|
||||||
worm.move(steps);
|
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) {
|
if (!Worm.isValidOrientation(oldAngle + angle) || worm.getActionPoints() - (long) Math.ceil(Math.toDegrees(angle) / 6) < 0) {
|
||||||
assertThrows(AssertionError.class, () -> worm.turn(angle));
|
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 {
|
else {
|
||||||
worm.turn(angle);
|
worm.turn(angle);
|
||||||
@@ -64,7 +64,7 @@ class WormTest {
|
|||||||
@RepeatedTest(5000)
|
@RepeatedTest(5000)
|
||||||
void jump() {
|
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 maxAngle = Math.abs(2 * Math.PI - worm.getOrientation());
|
||||||
double minAngle = worm.getOrientation();
|
double minAngle = worm.getOrientation();
|
||||||
double combAngle = maxAngle + minAngle;
|
double combAngle = maxAngle + minAngle;
|
||||||
@@ -82,12 +82,12 @@ class WormTest {
|
|||||||
double v = force / worm.getMass() * Worm.FORCE_TIME;
|
double v = force / worm.getMass() * Worm.FORCE_TIME;
|
||||||
double newLocX = worm.getLocation().item1 + Math.pow(v, 2) * Math.sin(2 * orient) / Worm.G;
|
double newLocX = worm.getLocation().item1 + Math.pow(v, 2) * Math.sin(2 * orient) / Worm.G;
|
||||||
worm.jump();
|
worm.jump();
|
||||||
assertEquals(Tuple.create(newLocX, worm.getLocation().item2), worm.getLocation());
|
assertEquals(Coordinate.create(newLocX, worm.getLocation().getCoordinateY()), worm.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
void doubleJump() {
|
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();
|
worm.jump();
|
||||||
assertThrows(IllegalStateException.class, () -> worm.jump());
|
assertThrows(IllegalStateException.class, () -> worm.jump());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user