Release v3.4

Updated test suite
This commit is contained in:
Koen Yskout
2018-05-08 09:41:13 +02:00
parent 492299b18d
commit cc27abd957
2 changed files with 231 additions and 143 deletions

View File

@@ -12,7 +12,6 @@ import org.junit.*;
import worms.facade.Facade;
import worms.facade.IFacade;
import worms.internal.gui.game.IActionHandler;
import worms.programs.IProgramFactory;
import worms.programs.ProgramFactory;
import worms.programs.ProgramParser;
import worms.util.*;
@@ -23,7 +22,7 @@ public class Part3_FullFacadeTest {
private static int score = 0;
private static final double EPS = 1e-3;
public final static double GAME_STANDARD_ACCELERATION = 5.0;
private final static IFacade facade = new Facade();
@@ -74,7 +73,8 @@ public class Part3_FullFacadeTest {
System.out.println();
System.out.println(" FINAL SCORE: " + score + "/" + max_score);
System.out.println();
System.out.println(" FINAL PERCENTAGE: " + Math.round(score*100/max_score) + "%");
if (max_score > 0)
System.out.println(" FINAL PERCENTAGE: " + Math.round(score * 100 / max_score) + "%");
System.out.println();
}
@@ -126,11 +126,10 @@ public class Part3_FullFacadeTest {
}
private static double getDistance(double[] p1, double[] p2) {
double dx = p1[0]-p2[0];
double dy = p1[1]-p2[1];
return Math.sqrt(dx*dx + dy*dy);
double dx = p1[0] - p2[0];
double dy = p1[1] - p2[1];
return Math.sqrt(dx * dx + dy * dy);
}
/**************
* WORLD TESTS
@@ -219,7 +218,6 @@ public class Part3_FullFacadeTest {
try {
assertEquals(0, facade.getAllTeams(theWorld).size());
} catch (MustNotImplementException exc) {
max_score -= 1;
}
score += 1;
}
@@ -238,16 +236,20 @@ public class Part3_FullFacadeTest {
@Test
public void terminateWorld_WorldWithTeams() {
System.out.println(max_score);
max_score += 2;
try {
facade.createTeam(theWorld, "TeamA");
System.out.println("team created");
facade.createTeam(theWorld, "TeamB");
facade.terminate(theWorld);
assertEquals(0, facade.getAllTeams(theWorld).size());
score += 2;
} catch (MustNotImplementException exc) {
System.out.println("Executing catcher");
max_score -= 2;
}
System.out.println(max_score);
}
@Test
@@ -705,6 +707,7 @@ public class Part3_FullFacadeTest {
facade.decreaseNbActionPoints(worm, 20);
BigInteger nbHitPoints = facade.getNbHitPoints(worm);
facade.startGame(theWorld);
assertTrue(facade.hasActiveGame(theWorld));
assertEquals(worm, facade.getActiveWorm(theWorld));
assertEquals(facade.getMaxNbActionPoints(worm), facade.getNbActionPoints(worm));
assertEquals(nbHitPoints.add(BigInteger.TEN), facade.getNbHitPoints(worm));
@@ -722,8 +725,9 @@ public class Part3_FullFacadeTest {
facade.decreaseNbActionPoints(wormB, 20);
BigInteger nbHitPointsB = facade.getNbHitPoints(wormB);
facade.decreaseNbActionPoints(wormC, 20);
BigInteger nbHitPointsC = facade.getNbHitPoints(wormA);
BigInteger nbHitPointsC = facade.getNbHitPoints(wormC);
facade.startGame(theWorld);
assertTrue(facade.hasActiveGame(theWorld));
Worm activeWorm = facade.getActiveWorm(theWorld);
assertTrue(facade.getAllWorms(theWorld).contains(activeWorm));
if (activeWorm == wormA) {
@@ -747,7 +751,7 @@ public class Part3_FullFacadeTest {
facade.createWorm(theWorld, new double[] { 7.95, 4.0 }, 0.1, 1.0, "Worm", null);
facade.startGame(theWorld);
facade.finishGame(theWorld);
assertNull(facade.getActiveWorm(theWorld));
assertFalse(facade.hasActiveGame(theWorld));
score += 1;
}
@@ -756,7 +760,7 @@ public class Part3_FullFacadeTest {
max_score += 1;
facade.createWorm(theWorld, new double[] { 7.95, 4.0 }, 0.1, 1.0, "Worm", null);
facade.finishGame(theWorld);
assertNull(facade.getActiveWorm(theWorld));
assertFalse(facade.hasActiveGame(theWorld));
score += 1;
}
@@ -844,15 +848,19 @@ public class Part3_FullFacadeTest {
Worm worm1 = facade.createWorm(theWorld, new double[] { 7.95, 4.0 }, 0.1, 1.0, "FirstWorm", null);
Worm worm2 = facade.createWorm(theWorld, new double[] { 2.5, 7.95 }, 0.1, 1.0, "SecondWorm", null);
Worm worm3 = facade.createWorm(theWorld, new double[] { 6.5, 7.95 }, 0.1, 1.0, "ThirdWorm", null);
Team someTeam = facade.createTeam(theWorld, "SomeTeam");
facade.addWormsToTeam(someTeam, worm1, worm3);
facade.startGame(theWorld);
facade.activateNextWorm(theWorld);
facade.removeWorm(theWorld, worm2);
facade.activateNextWorm(theWorld);
facade.activateNextWorm(theWorld);
assertEquals(facade.getName(someTeam), facade.getWinner(theWorld));
score += 4;
try {
Team someTeam = facade.createTeam(theWorld, "SomeTeam");
facade.addWormsToTeam(someTeam, worm1, worm3);
facade.startGame(theWorld);
facade.activateNextWorm(theWorld);
facade.removeWorm(theWorld, worm2);
facade.activateNextWorm(theWorld);
facade.activateNextWorm(theWorld);
assertEquals(facade.getName(someTeam), facade.getWinner(theWorld));
score += 4;
} catch (MustNotImplementException exc) {
max_score -= 4;
}
}
@Test
@@ -878,13 +886,17 @@ public class Part3_FullFacadeTest {
max_score += 1;
Worm worm1 = facade.createWorm(theWorld, new double[] { 7.95, 4.0 }, 0.1, 1.0, "FirstWorm", null);
Worm worm2 = facade.createWorm(theWorld, new double[] { 2.5, 7.95 }, 0.1, 1.0, "SecondWorm", null);
Team teamA = facade.createTeam(theWorld, "TeamA");
facade.addWormsToTeam(teamA, worm1);
Team teamB = facade.createTeam(theWorld, "TeamB");
facade.addWormsToTeam(teamB, worm2);
facade.startGame(theWorld);
assertNull(facade.getWinner(theWorld));
score += 1;
try {
Team teamA = facade.createTeam(theWorld, "TeamA");
facade.addWormsToTeam(teamA, worm1);
Team teamB = facade.createTeam(theWorld, "TeamB");
facade.addWormsToTeam(teamB, worm2);
facade.startGame(theWorld);
assertNull(facade.getWinner(theWorld));
score += 1;
} catch (MustNotImplementException exc) {
max_score -= 1;
}
}
@Test
@@ -892,11 +904,15 @@ public class Part3_FullFacadeTest {
max_score += 1;
Worm worm1 = facade.createWorm(theWorld, new double[] { 7.95, 4.0 }, 0.1, 1.0, "FirstWorm", null);
facade.createWorm(theWorld, new double[] { 2.5, 7.95 }, 0.1, 1.0, "SecondWorm", null);
Team teamA = facade.createTeam(theWorld, "TeamA");
facade.addWormsToTeam(teamA, worm1);
facade.startGame(theWorld);
assertNull(facade.getWinner(theWorld));
score += 1;
try {
Team teamA = facade.createTeam(theWorld, "TeamA");
facade.addWormsToTeam(teamA, worm1);
facade.startGame(theWorld);
assertNull(facade.getWinner(theWorld));
score += 1;
} catch (MustNotImplementException exc) {
max_score -= 1;
}
}
/**************
@@ -1134,7 +1150,7 @@ public class Part3_FullFacadeTest {
assertTrue(facade.getAllWormsOfTeam(theTeam).isEmpty());
score += 1;
} catch (MustNotImplementException exc) {
max_score = -1;
max_score -= 1;
}
}
@@ -1508,10 +1524,12 @@ public class Part3_FullFacadeTest {
long oldNbActionPoints = facade.getNbActionPoints(theWorm);
facade.move(theWorm);
double[] newLocation = facade.getLocation(theWorm);
double[] expectedLocation = new double[] {7.5,8.0};
double[] expectedLocation = new double[] { 7.5, 8.0 };
assertTrue(facade.isAdjacent(theWorld, newLocation, facade.getRadius(theWorm)));
assertEquals(expectedLocation[0]+facade.getRadius(theWorm)*0.1/2.0, newLocation[0], facade.getRadius(theWorm)*0.12/2.0);
assertEquals(expectedLocation[1]-facade.getRadius(theWorm)*0.1/2.0, newLocation[1], facade.getRadius(theWorm)*0.12/2.0);
assertEquals(expectedLocation[0] + facade.getRadius(theWorm) * 0.1 / 2.0, newLocation[0],
facade.getRadius(theWorm) * 0.12 / 2.0);
assertEquals(expectedLocation[1] - facade.getRadius(theWorm) * 0.1 / 2.0, newLocation[1],
facade.getRadius(theWorm) * 0.12 / 2.0);
// We allow a deviation of +/-1 in calculating the action points.
assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 4)
&& (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 2));
@@ -1521,15 +1539,15 @@ public class Part3_FullFacadeTest {
@Test
public void move_OnlyPassableTerrainInDirection() {
max_score += 15;
Worm theWorm = facade.createWorm(theWorld, new double[] { 7.0, 3.0 }, PI, 2.0, "Worm", null);
Worm theWorm = facade.createWorm(theWorld, new double[] { 8.375, 3.0 }, PI, 0.6, "Worm", null);
long oldNbActionPoints = facade.getNbActionPoints(theWorm);
facade.move(theWorm);
double[] newLocation = facade.getLocation(theWorm);
assertEquals(7.0 - 2.0, newLocation[0], EPS);
assertEquals(8.375 - 0.6, newLocation[0], EPS);
assertEquals(3.0, newLocation[1], EPS);
// We allow a deviation of +/-1 in calculating the action points.
assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 3)
&& (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 1));
assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 1)
&& (facade.getNbActionPoints(theWorm) <= oldNbActionPoints));
score += 15;
}
@@ -1542,10 +1560,12 @@ public class Part3_FullFacadeTest {
double[] newLocation = facade.getLocation(theWorm);
// The worm will move in an almost vertical direction, such that he is still
// adjacent to the vertical wall.
double[] expectedLocation = new double[] {8.0,6.0};
double[] expectedLocation = new double[] { 8.0, 6.0 };
assertTrue(facade.isAdjacent(theWorld, newLocation, facade.getRadius(theWorm)));
assertEquals(expectedLocation[0]-facade.getRadius(theWorm)*0.1/2.0, newLocation[0], facade.getRadius(theWorm)*0.12/2.0);
assertEquals(expectedLocation[1]-facade.getRadius(theWorm)*0.1/2.0, newLocation[1], facade.getRadius(theWorm)*0.12/2.0);
assertEquals(expectedLocation[0] - facade.getRadius(theWorm) * 0.1 / 2.0, newLocation[0],
facade.getRadius(theWorm) * 0.12 / 2.0);
assertEquals(expectedLocation[1] - facade.getRadius(theWorm) * 0.1 / 2.0, newLocation[1],
facade.getRadius(theWorm) * 0.12 / 2.0);
assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 5)
&& (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 3));
score += 15;
@@ -1601,7 +1621,7 @@ public class Part3_FullFacadeTest {
assertTrue(facade.isAdjacent(otherWorld, newLocation, 2.0));
double distanceToEdge = Math.min(
Math.sqrt(Math.pow(newLocation[0] - 5.0, 2.0) + Math.pow(newLocation[1] - 2.0, 2.0)),
Math.sqrt(Math.pow(newLocation[0] - 5.0, 2.0) + Math.pow(newLocation[1] - 8.0, 2.0)) );
Math.sqrt(Math.pow(newLocation[0] - 5.0, 2.0) + Math.pow(newLocation[1] - 8.0, 2.0)));
assertEquals(2.1, distanceToEdge, 0.2);
assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 5)
&& (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 3));
@@ -1719,15 +1739,19 @@ public class Part3_FullFacadeTest {
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, false, true, true, true, true, false }, };
World otherWorld = facade.createWorld(10.0, 10.0, map10x10);
Worm theWorm = facade.createWorm(otherWorld, new double[] { 4.5, 6.0 }, PI, 2.0, "Worm", null);
Worm theWorm = facade.createWorm(otherWorld, new double[] { 4.5, 7.375 }, 3 * PI / 2.0, 0.6, "Worm", null);
facade.move(theWorm);
System.out.println(facade.getLocation(theWorm)[1]);
try {
BigInteger oldNbHitPoints = facade.getNbHitPoints(theWorm);
System.out.println("Number of hit points: " + oldNbHitPoints);
facade.fall(theWorm);
double[] newLocation = facade.getLocation(theWorm);
assertTrue(facade.isAdjacent(otherWorld, newLocation, facade.getRadius(theWorm)));
assertEquals(4.5, newLocation[0], EPS);
assertEquals(3.0+facade.getRadius(theWorm)*0.1/2.0, newLocation[1], facade.getRadius(theWorm)*0.12/2.0);
assertEquals(oldNbHitPoints.subtract(BigInteger.valueOf(9)),facade.getNbHitPoints(theWorm) );
assertEquals(1.6 + facade.getRadius(theWorm) * 0.1 / 2.0, newLocation[1],
facade.getRadius(theWorm) * 0.12 / 2.0);
assertEquals(oldNbHitPoints.subtract(BigInteger.valueOf(15)), facade.getNbHitPoints(theWorm));
score += 15;
} catch (MustNotImplementException exc) {
max_score -= 15;
@@ -1737,8 +1761,8 @@ public class Part3_FullFacadeTest {
@Test
public void fall_InWorldOverlappingWorms() {
max_score += 12;
map10x10 = new boolean[][] { { true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, false, false, true, true, true, false },
map10x10 = new boolean[][] { { false, false, false, false, false, false, false, false, false, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false },
@@ -1748,15 +1772,16 @@ public class Part3_FullFacadeTest {
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, false, false, false, true, true, true, false }, };
World otherWorld = facade.createWorld(10.0, 10.0, map10x10);
Worm theWorm = facade.createWorm(otherWorld, new double[] { 4.5, 6.0 }, PI, 2.0, "Worm", null);
Worm worm1 = facade.createWorm(otherWorld, new double[] { 5.5, 2.0 }, PI, 1.0, "WormA", null);
Worm worm2 = facade.createWorm(otherWorld, new double[] { 3.5, 2.0 }, PI, 1.0, "WormB", null);
Worm theWorm = facade.createWorm(otherWorld, new double[] { 4.5, 8.375 }, 3 * PI / 2, 0.6, "Worm", null);
Worm worm1 = facade.createWorm(otherWorld, new double[] { 4.8, 1.31 }, PI, 0.3, "WormA", null);
Worm worm2 = facade.createWorm(otherWorld, new double[] { 4.2, 1.31 }, PI, 0.3, "WormB", null);
facade.move(theWorm);
try {
long oldNbHitPoints_TheWorm = facade.getNbHitPoints(theWorm).longValue();
long oldNbHitPoints_worm1 = facade.getNbHitPoints(worm1).longValue();
long oldNbHitPoints_worm2 = facade.getNbHitPoints(worm2).longValue();
facade.fall(theWorm);
assertEquals(oldNbHitPoints_TheWorm - 9 + oldNbHitPoints_worm1 / 2 + oldNbHitPoints_worm2 / 2,
assertEquals(oldNbHitPoints_TheWorm - 18 + oldNbHitPoints_worm1 / 2 + oldNbHitPoints_worm2 / 2,
facade.getNbHitPoints(theWorm).longValue());
assertEquals(facade.getNbHitPoints(worm1).longValue(), oldNbHitPoints_worm1 / 2);
assertEquals(facade.getNbHitPoints(worm2).longValue(), oldNbHitPoints_worm2 / 2);
@@ -1770,7 +1795,8 @@ public class Part3_FullFacadeTest {
public void fall_OutOfWorld() {
max_score += 6;
// Worm hanging on the ceiling.
Worm theWorm = facade.createWorm(theWorld, new double[] { 3.0, 8.0 }, 3 * PI / 4.0, 1.0, "Worm", null);
Worm theWorm = facade.createWorm(theWorld, new double[] { 3.0, 8.375 }, 3 * PI / 2.0, 0.6, "Worm", null);
facade.move(theWorm);
try {
facade.fall(theWorm);
assertFalse(facade.hasAsWorm(theWorld, theWorm));
@@ -1780,7 +1806,8 @@ public class Part3_FullFacadeTest {
max_score -= 3;
}
// Worm hanging on side wall.
Worm otherWorm = facade.createWorm(theWorld, new double[] { 8.0, 3.0 }, 3 * PI / 4.0, 1.0, "WormB", null);
Worm otherWorm = facade.createWorm(theWorld, new double[] { 8.375, 3.0 }, PI, 0.6, "WormB", null);
facade.move(otherWorm);
try {
facade.fall(otherWorm);
assertFalse(facade.hasAsWorm(theWorld, otherWorm));
@@ -1897,13 +1924,15 @@ public class Part3_FullFacadeTest {
@Test
public void jumpTime_ReachingImpassableTerrain() {
max_score += 14;
double[] worm_location = new double[] { 7.5, 6.5 };
double[] worm_location = new double[] { 7.5, 6.3 };
double worm_orientation = 3 * PI / 4.0;
double worm_radius = 1.5;
Worm theWorm = facade.createWorm(theWorld, worm_location, worm_orientation, worm_radius, "Worm", null);
double jumpTime = facade.getJumpTime(theWorm, 0.01);
assertEquals(0.39, jumpTime, 0.05);
System.out.println(jumpTime);
assertEquals(0.5, jumpTime, 0.2);
double[] locationAfterJump = facade.getJumpStep(theWorm, jumpTime);
System.out.println(getDistance(worm_location, locationAfterJump));
assertTrue(facade.isAdjacent(theWorld, locationAfterJump, worm_radius));
score += 14;
}
@@ -1916,8 +1945,9 @@ public class Part3_FullFacadeTest {
double worm_radius = 0.5;
Worm theWorm = facade.createWorm(theWorld, worm_location, worm_orientation, worm_radius, "Worm", null);
try {
facade.getJumpTime(theWorm, 0.05);
fail();
double jumpTime = facade.getJumpTime(theWorm, 0.05);
assertTrue(jumpTime >= 0.0);
score += 8;
} catch (ModelException exc) {
score += 8;
}
@@ -2101,7 +2131,7 @@ public class Part3_FullFacadeTest {
assertTrue(facade.isTerminated(newFood));
assertEquals(1.5 * 1.1, facade.getRadius(theWorm), EPS);
assertTrue(facade.isAdjacent(theWorld, facade.getLocation(theWorm), facade.getRadius(theWorm)));
assertTrue(getDistance(worm_location,facade.getLocation(theWorm)) < facade.getRadius(theWorm)*0.2);
assertTrue(getDistance(worm_location, facade.getLocation(theWorm)) < facade.getRadius(theWorm) * 0.2);
assertEquals(oldNbActionPoints - 8, facade.getNbActionPoints(theWorm));
score += 8;
}
@@ -2121,7 +2151,7 @@ public class Part3_FullFacadeTest {
assertTrue(facade.isTerminated(newFood));
assertEquals(1.5 * 0.9, facade.getRadius(theWorm), EPS);
assertTrue(facade.isAdjacent(theWorld, facade.getLocation(theWorm), facade.getRadius(theWorm)));
assertTrue(getDistance(worm_location,facade.getLocation(theWorm)) < facade.getRadius(theWorm)*0.2);
assertTrue(getDistance(worm_location, facade.getLocation(theWorm)) < facade.getRadius(theWorm) * 0.2);
long expectedNbActionPoints = Math.min(oldNbActionPoints - 8,
referenceMaxActionPoints(facade.getRadius(theWorm)));
assertEquals(expectedNbActionPoints, facade.getNbActionPoints(theWorm));
@@ -2143,7 +2173,7 @@ public class Part3_FullFacadeTest {
assertTrue(facade.isTerminated(newFood));
assertEquals(0.25, facade.getRadius(theWorm), EPS);
assertTrue(facade.isAdjacent(theWorld, facade.getLocation(theWorm), facade.getRadius(theWorm)));
assertTrue(getDistance(worm_location,facade.getLocation(theWorm)) < facade.getRadius(theWorm)*0.2);
assertTrue(getDistance(worm_location, facade.getLocation(theWorm)) < facade.getRadius(theWorm) * 0.2);
long expectedNbActionPoints = Math.min(oldNbActionPoints - 8,
referenceMaxActionPoints(facade.getRadius(theWorm)));
assertEquals(expectedNbActionPoints, facade.getNbActionPoints(theWorm));
@@ -2165,7 +2195,7 @@ public class Part3_FullFacadeTest {
assertTrue(facade.isTerminated(newFood1) ^ facade.isTerminated(newFood2) ^ facade.isTerminated(newFood3));
assertEquals(1.5 * 1.1, facade.getRadius(theWorm), EPS);
assertTrue(facade.isAdjacent(theWorld, facade.getLocation(theWorm), facade.getRadius(theWorm)));
assertTrue(getDistance(worm_location,facade.getLocation(theWorm)) < facade.getRadius(theWorm)*0.2);
assertTrue(getDistance(worm_location, facade.getLocation(theWorm)) < facade.getRadius(theWorm) * 0.2);
assertEquals(oldNbActionPoints - 8, facade.getNbActionPoints(theWorm));
score += 2;
}
@@ -2184,7 +2214,7 @@ public class Part3_FullFacadeTest {
assertTrue(facade.isTerminated(newFood1) ^ facade.isTerminated(newFood2));
assertEquals(1.5 * 1.1, facade.getRadius(theWorm), EPS);
assertTrue(facade.isAdjacent(theWorld, facade.getLocation(theWorm), facade.getRadius(theWorm)));
assertTrue(getDistance(worm_location,facade.getLocation(theWorm)) < facade.getRadius(theWorm)*0.2);
assertTrue(getDistance(worm_location, facade.getLocation(theWorm)) < facade.getRadius(theWorm) * 0.2);
assertEquals(oldNbActionPoints - 8, facade.getNbActionPoints(theWorm));
score += 18;
}
@@ -2212,11 +2242,22 @@ public class Part3_FullFacadeTest {
@Test
public void eat_EnlargedWormNotFullyInWorld() {
max_score += 8;
double[] worm_location = new double[] { 7.5, 1.505 };
map10x10 = new boolean[][] { { true, true, true, true, true, true, true, true, true, true },
{ true, true, true, true, true, true, true, true, true, true },
{ true, true, true, true, true, true, true, true, true, true },
{ true, true, true, true, true, true, true, true, true, true },
{ true, true, true, true, true, true, true, true, true, true },
{ true, true, true, true, true, true, true, false, false, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false } };
World theWorld = facade.createWorld(10.0, 10.0, map10x10);
double[] worm_location = new double[] { 6.995, 1.95 };
double worm_orientation = 3 * PI / 2.0;
double worm_radius = 1.5;
double worm_radius = 1.9;
Worm theWorm = facade.createWorm(theWorld, worm_location, worm_orientation, worm_radius, "Worm", null);
double[] location = new double[] { 8.795, 1.5 };
double[] location = new double[] { 8.795, 1.9 };
Food newFood = facade.createFood(theWorld, location);
long oldNbActionPoints = facade.getNbActionPoints(theWorm);
facade.eat(theWorm);
@@ -2234,12 +2275,12 @@ public class Part3_FullFacadeTest {
{ true, true, true, true, false, false, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, true, true, true, true, true, false },
{ true, true, true, true, false, false, false,false, false,false },
{ true, true, true, true, false, false, false, false, false, false },
{ true, true, true, true, false, true, true, true, true, false },
{ true, true, true, true, false, true, true, true, true, false },
{ true, true, true, true, false, true, true, true, true, false },
{ true, true, true, true, false, true, true, true, true, false },
{ false,false,false,false,false,false,false,false,false,false }, };
{ false, false, false, false, false, false, false, false, false, false }, };
World otherWorld = facade.createWorld(10.0, 10.0, map10x10);
double[] worm_location = new double[] { 7.0, 3.0 };
double worm_orientation = PI / 4.0;
@@ -2448,8 +2489,10 @@ public class Part3_FullFacadeTest {
Worm theWorm = facade.createWorm(theWorld, worm_location, worm_orientation, worm_radius, "Worm", null);
try {
Projectile projectile = facade.fire(theWorm);
facade.getJumpTime(projectile, 0.00001);
fail();
double jumpTime = facade.getJumpTime(projectile, 0.00001);
System.out.println(jumpTime);
assertTrue(jumpTime >= 0.0);
score += 6;
} catch (ModelException exc) {
score += 6;
}
@@ -2986,32 +3029,41 @@ public class Part3_FullFacadeTest {
@Test
public void castSpell_WormsSameTeam() {
max_score += 4;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormA", theTeam);
BigInteger nbHitPoints1 = facade.getNbHitPoints(worm1);
Worm worm2 = facade.createWorm(theWorld, new double[] { 6.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormB", theTeam);
BigInteger nbHitPoints2 = facade.getNbHitPoints(worm2);
facade.castSpell(theWorld);
BigInteger expectedNbHitPoints = nbHitPoints1.add(nbHitPoints2).divide(BigInteger.valueOf(2));
assertEquals(expectedNbHitPoints, facade.getNbHitPoints(worm1));
assertEquals(expectedNbHitPoints, facade.getNbHitPoints(worm2));
score += 4;
try {
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormA", null);
BigInteger nbHitPoints1 = facade.getNbHitPoints(worm1);
Worm worm2 = facade.createWorm(theWorld, new double[] { 6.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormB", null);
BigInteger nbHitPoints2 = facade.getNbHitPoints(worm2);
facade.addWormsToTeam(theTeam, worm1, worm2);
facade.castSpell(theWorld);
BigInteger expectedNbHitPoints = nbHitPoints1.add(nbHitPoints2).divide(BigInteger.valueOf(2));
assertEquals(expectedNbHitPoints, facade.getNbHitPoints(worm1));
assertEquals(expectedNbHitPoints, facade.getNbHitPoints(worm2));
score += 4;
} catch (MustNotImplementException exc) {
max_score -= 4;
}
}
@Test
public void castSpell_WormsDifferentTeams() {
max_score += 4;
Worm largestWorm = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormA",
theTeam);
long nbActionPointsLargest = facade.getNbActionPoints(largestWorm);
Worm smallestWorm = facade.createWorm(theWorld, new double[] { 6.0, 8.0 }, FIXTURE_DIRECTION, 1.0, "WormB",
null);
facade.decreaseNbActionPoints(smallestWorm, 10);
long nbActionPointsSmallest = facade.getNbActionPoints(smallestWorm);
facade.castSpell(theWorld);
long actionPointsToTransfer = Math.min(nbActionPointsLargest, 5);
assertEquals(nbActionPointsLargest - actionPointsToTransfer, facade.getNbActionPoints(largestWorm));
assertEquals(nbActionPointsSmallest + actionPointsToTransfer, facade.getNbActionPoints(smallestWorm));
score += 4;
try {
Worm largestWorm = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormA",
theTeam);
long nbActionPointsLargest = facade.getNbActionPoints(largestWorm);
Worm smallestWorm = facade.createWorm(theWorld, new double[] { 6.0, 8.0 }, FIXTURE_DIRECTION, 1.0, "WormB",
null);
facade.decreaseNbActionPoints(smallestWorm, 10);
long nbActionPointsSmallest = facade.getNbActionPoints(smallestWorm);
facade.castSpell(theWorld);
long actionPointsToTransfer = Math.min(nbActionPointsLargest, 5);
assertEquals(nbActionPointsLargest - actionPointsToTransfer, facade.getNbActionPoints(largestWorm));
assertEquals(nbActionPointsSmallest + actionPointsToTransfer, facade.getNbActionPoints(smallestWorm));
score += 4;
} catch (MustNotImplementException exc) {
max_score -= 4;
}
}
@Test
@@ -3082,10 +3134,14 @@ public class Part3_FullFacadeTest {
int oldNbHitPoints2 = facade.getNbHitPoints(projectile2);
facade.terminate(theWorm);
facade.castSpell(theWorld);
assertTrue((facade.getNbHitPoints(projectile1) == oldNbHitPoints1 + 2) || (oldNbHitPoints1 == 7)
|| (oldNbHitPoints1 == 10));
assertTrue((facade.getNbHitPoints(projectile2) == oldNbHitPoints2 + 2) || (oldNbHitPoints2 == 7)
|| (oldNbHitPoints2 == 10));
int newNbHitPoints1 = facade.getNbHitPoints(projectile1);
int newNbHitPoints2 = facade.getNbHitPoints(projectile2);
assertTrue((newNbHitPoints1 == oldNbHitPoints1 + 2)
|| (newNbHitPoints1 == 7 && newNbHitPoints1 - oldNbHitPoints1 < 2)
|| (newNbHitPoints1 == 10 && newNbHitPoints1 - oldNbHitPoints1 < 2));
assertTrue((newNbHitPoints2 == oldNbHitPoints2 + 2)
|| (newNbHitPoints2 == 7 && newNbHitPoints2 - oldNbHitPoints2 < 2)
|| (newNbHitPoints2 == 10 && newNbHitPoints2 - oldNbHitPoints2 < 2));
score += 4;
}
@@ -3393,7 +3449,7 @@ public class Part3_FullFacadeTest {
public void testEatStatement_WormEating() throws ModelException {
max_score += 4;
Worm worm1 = facade.createWorm(theWorld, new double[] { 7.5, 5.5 }, 7 * PI / 12.0, 1.5, "WormA", theTeam);
Food food = facade.createFood(theWorld, new double[] {8.795,5.5});
Food food = facade.createFood(theWorld, new double[] { 8.795, 5.5 });
String code = "eat; ";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
@@ -3416,7 +3472,7 @@ public class Part3_FullFacadeTest {
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = {};
assertArrayEquals(expecteds, results.toArray());
assertEquals(1.5,facade.getRadius(worm1),EPS);
assertEquals(1.5, facade.getRadius(worm1), EPS);
score += 4;
}
@@ -3443,7 +3499,7 @@ public class Part3_FullFacadeTest {
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = {};
assertArrayEquals(expecteds, results.toArray());
assertEquals(2,facade.getAllItems(theWorld).size());
assertEquals(2, facade.getAllItems(theWorld).size());
score += 4;
}
@@ -3635,6 +3691,8 @@ public class Part3_FullFacadeTest {
String code = "print 1.0; v := 1.0; while true { v := v + 1.0; print v; if 4.5 < v break; } print 10.0;";
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 1.0, 2.0, 3.0, 4.0, 5.0, 10.0 };
@@ -3652,6 +3710,8 @@ public class Part3_FullFacadeTest {
String code = "print 1.0; v := 1.0; while true { v := v + 1.0; { print v; if 4.5 < v break; print 0.0;} } print 10.0;";
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 1.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0, 5.0, 10.0 };
@@ -3667,13 +3727,17 @@ public class Part3_FullFacadeTest {
max_score += 8;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "v := true; while v {print v; v := false; } break;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
facade.executeProgram(worm1);
fail();
} catch (ModelException exc) {
score += 8;
} catch (MustNotImplementException exc) {
max_score -= 8;
}
}
@@ -3682,11 +3746,13 @@ public class Part3_FullFacadeTest {
max_score += 12;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: { print 10.0; break; print 15.0; } print 0.0; invoke p; print 20.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 0.0, 10.0, 20.0};
Object[] expecteds = { 0.0, 10.0, 20.0 };
assertArrayEquals(expecteds, results.toArray());
score += 12;
} catch (MustNotImplementException exc) {
@@ -3699,11 +3765,13 @@ public class Part3_FullFacadeTest {
max_score += 20;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: { print 1.0; while true { print 2.0; break; } print 3.0; break; print 4.0;} def g: { print 10.0; invoke p; print 20.0; break; print 30.0; } print 0.0; invoke g; print 100.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 0.0, 10.0, 1.0, 2.0, 3.0, 20.0, 100.0};
Object[] expecteds = { 0.0, 10.0, 1.0, 2.0, 3.0, 20.0, 100.0 };
assertArrayEquals(expecteds, results.toArray());
score += 20;
} catch (MustNotImplementException exc) {
@@ -3716,9 +3784,11 @@ public class Part3_FullFacadeTest {
max_score += 4;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "invoke p;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
facade.executeProgram(worm1);
fail();
} catch (ModelException exc) {
@@ -3733,11 +3803,13 @@ public class Part3_FullFacadeTest {
max_score += 6;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: print 4.0; print 1.0; invoke p; print 7.0; invoke p; print 10.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 1.0, 4.0, 7.0, 4.0, 10.0};
Object[] expecteds = { 1.0, 4.0, 7.0, 4.0, 10.0 };
assertArrayEquals(expecteds, results.toArray());
score += 6;
} catch (MustNotImplementException exc) {
@@ -3750,9 +3822,11 @@ public class Part3_FullFacadeTest {
max_score += 4;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: print 4.0; def p: print 8.0; print 1.0; invoke p; print 7.0; ";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 1.0, 8.0, 7.0 };
assertArrayEquals(expecteds, results.toArray());
@@ -3767,11 +3841,13 @@ public class Part3_FullFacadeTest {
max_score += 8;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: a := 10; invoke p; print a;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 10.0};
Object[] expecteds = { 10.0 };
assertArrayEquals(expecteds, results.toArray());
score += 8;
} catch (MustNotImplementException exc) {
@@ -3784,11 +3860,13 @@ public class Part3_FullFacadeTest {
max_score += 10;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: a := a + 10.0; a := 3; invoke p; print a;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 13.0};
Object[] expecteds = { 13.0 };
assertArrayEquals(expecteds, results.toArray());
score += 10;
} catch (MustNotImplementException exc) {
@@ -3801,11 +3879,13 @@ public class Part3_FullFacadeTest {
max_score += 10;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: print 1.0; def g: { print 2.0; invoke p; print 3.0; } invoke g; ";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 2.0, 1.0, 3.0};
Object[] expecteds = { 2.0, 1.0, 3.0 };
assertArrayEquals(expecteds, results.toArray());
score += 10;
} catch (MustNotImplementException exc) {
@@ -3818,11 +3898,13 @@ public class Part3_FullFacadeTest {
max_score += 35;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: { print a; if a < 5.5 { a := a + 1.0; invoke p; } } a := 0.0; invoke p; print a + 1.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
Object[] expecteds = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
assertArrayEquals(expecteds, results.toArray());
score += 35;
} catch (MustNotImplementException exc) {
@@ -3835,15 +3917,17 @@ public class Part3_FullFacadeTest {
max_score += 25;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "def p: { print a; a := a + 5.0; jump; print a; } a := 10.0; invoke p; print a + 1.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
facade.decreaseNbActionPoints(worm1, facade.getNbActionPoints(worm1));
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
facade.decreaseNbActionPoints(worm1, facade.getNbActionPoints(worm1));
List<Object> results = facade.executeProgram(worm1);
assertNull(results);
facade.decreaseNbActionPoints(worm1, -facade.getMaxNbActionPoints(worm1));
results = facade.executeProgram(worm1);
Object[] expecteds = { 10.0, 15.0, 16.0};
Object[] expecteds = { 10.0, 15.0, 16.0 };
assertArrayEquals(expecteds, results.toArray());
score += 25;
} catch (MustNotImplementException exc) {
@@ -3851,11 +3935,6 @@ public class Part3_FullFacadeTest {
}
}
// break statement
// nested break statements
// Assignment: assignment to variable with same name as procedure.
/*******************
* EXPRESSION TESTS
*******************/
@@ -4123,9 +4202,11 @@ public class Part3_FullFacadeTest {
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
facade.createWorm(theWorld, new double[] { 6.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormB", theTeam);
String code = "print sameteam searchobj 0.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { true };
assertArrayEquals(expecteds, results.toArray());
@@ -4141,9 +4222,11 @@ public class Part3_FullFacadeTest {
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
facade.createWorm(theWorld, new double[] { 6.0, 7.5 }, FIXTURE_DIRECTION, 1.5, "WormB", null);
String code = "print sameteam searchobj 0.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { false };
assertArrayEquals(expecteds, results.toArray());
@@ -4158,9 +4241,11 @@ public class Part3_FullFacadeTest {
max_score += 3;
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", theTeam);
String code = "print sameteam null;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
if (program == null)
throw new MustNotImplementException();
facade.loadProgramOnWorm(worm1, program, actionHandler);
List<Object> results = facade.executeProgram(worm1);
Object[] expecteds = { false };
assertArrayEquals(expecteds, results.toArray());
@@ -4176,9 +4261,9 @@ public class Part3_FullFacadeTest {
Worm worm1 = facade.createWorm(theWorld, new double[] { 2.0, 7.5 }, 0.0, 1.5, "WormA", null);
facade.createFood(theWorld, new double[] { 8.795, 7.5 });
String code = "print sameteam searchobj 0.0;";
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
try {
Program program = ProgramParser.parseProgramFromString(code, programFactory);
facade.loadProgramOnWorm(worm1, program, actionHandler);
facade.executeProgram(worm1);
fail();
} catch (ModelException exc) {