diff --git a/OGP1718-Worms/src-provided/worms/facade/IFacade.java b/OGP1718-Worms/src-provided/worms/facade/IFacade.java index 0f34712..ac5c313 100755 --- a/OGP1718-Worms/src-provided/worms/facade/IFacade.java +++ b/OGP1718-Worms/src-provided/worms/facade/IFacade.java @@ -348,7 +348,7 @@ public interface IFacade { * - Students working alone on the project must not override this method. */ default public boolean canFall(Worm worm) throws MustNotImplementException { - throw new MustNotImplementException(); + return false; } /** @@ -387,7 +387,7 @@ public interface IFacade { /** * Make the given worm eat a portion of food. */ - void eat(Worm worm) throws ModelException; + void eat(Worm worm); /** * Have the give worm fire a projectile. @@ -552,7 +552,7 @@ public interface IFacade { * - Students working alone on the project must not override this method. */ default Team getTeam(Worm worm) throws ModelException { - throw new MustNotImplementException(); + return null; } /** diff --git a/OGP1718-Worms/src-provided/worms/programs/IProgramFactory.java b/OGP1718-Worms/src-provided/worms/programs/IProgramFactory.java index c2b4acf..417dba4 100755 --- a/OGP1718-Worms/src-provided/worms/programs/IProgramFactory.java +++ b/OGP1718-Worms/src-provided/worms/programs/IProgramFactory.java @@ -32,8 +32,8 @@ import worms.util.MustNotImplementException; *

* You should declare your class as follows:

  * public class ProgramFactory implements IProgramFactory<MyExpression, MyStatement, MyProc, Program>
- * 
where MyExpression, MyStatement, MyProc, and Program are your classes - * for representing expressions, statements, procedure definitions, and programs, + * where MyExpression, MyStatement and MyProc are your classes + * for representing expressions, statements and procedure definitions, * respectively. * *

@@ -90,7 +90,10 @@ public interface IProgramFactory { * @param body * The body of the procedure. */ - public P createProcedureDefinition(String procedureName, S body, SourceLocation sourceLocation); + public default P createProcedureDefinition(String procedureName, S body, SourceLocation sourceLocation) + throws ModelException, MustNotImplementException { + throw new MustNotImplementException(); + } /* STATEMENTS */ diff --git a/OGP1718-Worms/src-provided/worms/programs/ProgramParser.java b/OGP1718-Worms/src-provided/worms/programs/ProgramParser.java index 877b01c..283dcc2 100755 --- a/OGP1718-Worms/src-provided/worms/programs/ProgramParser.java +++ b/OGP1718-Worms/src-provided/worms/programs/ProgramParser.java @@ -17,6 +17,7 @@ import worms.programs.IProgramFactory; import worms.programs.internal.parser.ParserVisitor; import worms.programs.internal.parser.generated.WormsProgramLexer; import worms.programs.internal.parser.generated.WormsProgramParser; +import worms.util.MustNotImplementException; import worms.internal.gui.GUIUtils; import worms.model.Program; @@ -157,6 +158,8 @@ public class ProgramParser { } errors.add("Factory did not return a Program object"); } + } catch (MustNotImplementException e) { + errors.add(e.toString()); } catch (Exception e) { e.printStackTrace(); errors.add(e.toString()); diff --git a/OGP1718-Worms/src/worms/model/Program.java b/OGP1718-Worms/src/worms/model/Program.java index 295fc1b..4c1c327 100644 --- a/OGP1718-Worms/src/worms/model/Program.java +++ b/OGP1718-Worms/src/worms/model/Program.java @@ -7,7 +7,6 @@ import java.util.List; public class Program { - private final List procedureList; private final Statement main; @@ -15,7 +14,6 @@ public class Program { public Program(List proc, Statement main) { this.procedureList = proc; this.main = main; - } public Worm getWorm() { diff --git a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java index 9babc9b..39a4440 100755 --- a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java +++ b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java @@ -12,7 +12,7 @@ import org.junit.*; import worms.facade.Facade; import worms.facade.IFacade; import worms.internal.gui.game.IActionHandler; -import worms.programs.ProgramFactory; +import worms.programs.IProgramFactory; import worms.programs.ProgramParser; import worms.util.*; @@ -22,12 +22,12 @@ 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(); private final static IActionHandler actionHandler = new SimpleActionHandler(facade); - private final static ProgramFactory programFactory = new ProgramFactory(); + private final static IProgramFactory programFactory = facade.createProgramFactory(); private static final double[] FIXTURE_LOCATION = new double[] { 3.0, -7.0 }; private static final double FIXTURE_RADIUS = 0.30; @@ -73,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(); } @@ -125,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 @@ -218,7 +218,6 @@ public class Part3_FullFacadeTest { try { assertEquals(0, facade.getAllTeams(theWorld).size()); } catch (MustNotImplementException exc) { - max_score -= 1; } score += 1; } @@ -704,6 +703,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)); @@ -721,8 +721,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) { @@ -746,7 +747,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; } @@ -755,7 +756,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; } @@ -843,15 +844,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 @@ -877,13 +882,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 @@ -891,11 +900,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; + } } /************** @@ -1133,7 +1146,7 @@ public class Part3_FullFacadeTest { assertTrue(facade.getAllWormsOfTeam(theTeam).isEmpty()); score += 1; } catch (MustNotImplementException exc) { - max_score = -1; + max_score -= 1; } } @@ -1244,9 +1257,9 @@ public class Part3_FullFacadeTest { @Test public void decreaseActionPoints_DeltaTooLarge() { max_score += 1; - long oldNbActionPoints = facade.getNbActionPoints(fixtureWorm); facade.decreaseNbActionPoints(fixtureWorm, Integer.MAX_VALUE); - assertEquals(oldNbActionPoints, facade.getNbActionPoints(fixtureWorm)); + assertTrue(0 <= facade.getNbActionPoints(fixtureWorm)); + assertTrue(facade.getNbActionPoints(fixtureWorm) <= facade.getMaxNbActionPoints(fixtureWorm)); score += 1; } @@ -1257,7 +1270,8 @@ public class Part3_FullFacadeTest { long maxNbActionPoints = facade.getMaxNbActionPoints(fixtureWorm); long delta = oldNbActionPoints - maxNbActionPoints - 10; facade.decreaseNbActionPoints(fixtureWorm, delta); - assertEquals(oldNbActionPoints, facade.getNbActionPoints(fixtureWorm)); + assertTrue(0 <= facade.getNbActionPoints(fixtureWorm)); + assertTrue(facade.getNbActionPoints(fixtureWorm) <= facade.getMaxNbActionPoints(fixtureWorm)); score += 1; } @@ -1507,10 +1521,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)); @@ -1520,15 +1536,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; } @@ -1541,12 +1557,14 @@ 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) ); assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 5) - && (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 3)); + && (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 1)); score += 15; } @@ -1564,7 +1582,7 @@ public class Part3_FullFacadeTest { { true, true, true, true, false, true, true, true, true, false }, { true, true, true, true, true, true, true, true, true, false }, }; World otherWorld = facade.createWorld(10.0, 10.0, map10x10); - Worm theWorm = facade.createWorm(otherWorld, new double[] { 7.0, 5.0 }, PI, 2.0, "Worm", null); + Worm theWorm = facade.createWorm(otherWorld, new double[] { 6.85, 5.0 }, PI, 2.0, "Worm", null); long oldNbActionPoints = facade.getNbActionPoints(theWorm); facade.move(theWorm); double[] newLocation = facade.getLocation(theWorm); @@ -1572,8 +1590,8 @@ public class Part3_FullFacadeTest { assertTrue(facade.isAdjacent(otherWorld, newLocation, 2.0)); double distanceToEdge = Math.sqrt(Math.pow(newLocation[0] - 5.0, 2.0) + Math.pow(newLocation[1] - 2.0, 2.0)); assertEquals(2.1, distanceToEdge, 0.2); - assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 5) - && (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 3)); + assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 7) + && (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 5)); score += 15; } @@ -1591,7 +1609,7 @@ public class Part3_FullFacadeTest { { true, true, true, true, false, true, true, true, true, false }, { true, true, true, true, true, true, true, true, true, false }, }; World otherWorld = facade.createWorld(10.0, 10.0, map10x10); - Worm theWorm = facade.createWorm(otherWorld, new double[] { 7.0, 5.0 }, PI, 2.0, "Worm", null); + Worm theWorm = facade.createWorm(otherWorld, new double[] { 6.85, 5.0 }, PI, 2.0, "Worm", null); long oldNbActionPoints = facade.getNbActionPoints(theWorm); facade.move(theWorm); double[] newLocation = facade.getLocation(theWorm); @@ -1600,10 +1618,10 @@ 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)); + assertTrue((facade.getNbActionPoints(theWorm) >= oldNbActionPoints - 7) + && (facade.getNbActionPoints(theWorm) <= oldNbActionPoints - 5)); score += 15; } @@ -1718,15 +1736,17 @@ 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); try { BigInteger oldNbHitPoints = facade.getNbHitPoints(theWorm); 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; @@ -1736,8 +1756,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 }, @@ -1747,15 +1767,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); @@ -1769,7 +1790,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)); @@ -1779,7 +1801,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)); @@ -1896,12 +1919,12 @@ 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); + assertEquals(0.5, jumpTime, 0.2); double[] locationAfterJump = facade.getJumpStep(theWorm, jumpTime); assertTrue(facade.isAdjacent(theWorld, locationAfterJump, worm_radius)); score += 14; @@ -1915,8 +1938,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; } @@ -1951,7 +1975,7 @@ public class Part3_FullFacadeTest { @Test public void jump_ReachingImpassableTerrain() { max_score += 9; - 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); @@ -1989,7 +2013,7 @@ public class Part3_FullFacadeTest { long newNbHitPoints_worm1 = facade.getNbHitPoints(worm1).longValue(); assertTrue((newNbHitPoints_TheWorm < oldNbHitPoints_TheWorm) ^ (newNbHitPoints_worm1 < oldNbHitPoints_worm1)); assertTrue((newNbHitPoints_TheWorm == 0) || (newNbHitPoints_TheWorm >= oldNbHitPoints_TheWorm - 5)); - assertTrue((newNbHitPoints_worm1 == 0) || (newNbHitPoints_worm1 >= oldNbHitPoints_TheWorm - 40)); + assertTrue((newNbHitPoints_worm1 == 0) || (newNbHitPoints_worm1 >= oldNbHitPoints_worm1 - 40)); score += 11; } @@ -2100,7 +2124,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; } @@ -2120,7 +2144,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)); @@ -2142,7 +2166,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)); @@ -2164,7 +2188,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; } @@ -2183,7 +2207,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; } @@ -2211,11 +2235,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); @@ -2233,12 +2268,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; @@ -2432,9 +2467,9 @@ public class Part3_FullFacadeTest { facade.createWorm(theWorld, new double[] { 7.5, 7.5 }, 0.0, 1.5, "Other", null); Projectile projectile = facade.fire(theWorm); double jumpTime = facade.getJumpTime(projectile, 0.00001); - assertTrue((Math.abs(jumpTime - 0.08) < 0.01) || (Math.abs(jumpTime - 0.53) < 0.01)); + assertTrue((Math.abs(jumpTime - 0.08) < 0.05) || (Math.abs(jumpTime - 0.53) < 0.4)); double[] locationAfterJump = facade.getJumpStep(projectile, jumpTime); - assertTrue(locationAfterJump[1] >= 6.0 - facade.getRadius(projectile)); + assertTrue(locationAfterJump[1] >= 5.9 - facade.getRadius(projectile)); score += 8; } @@ -2447,8 +2482,9 @@ 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); + assertTrue(jumpTime >= 0.0); + score += 6; } catch (ModelException exc) { score += 6; } @@ -2484,7 +2520,7 @@ public class Part3_FullFacadeTest { Projectile projectile = facade.fire(theWorm); facade.jump(projectile, 0.00001); assertTrue(oldNbHitPoints1.compareTo(facade.getNbHitPoints(hittedWorm1)) > 0); - assertTrue(oldNbHitPoints2.compareTo(facade.getNbHitPoints(hittedWorm2)) > 0); + assertTrue(oldNbHitPoints2.compareTo(facade.getNbHitPoints(hittedWorm2)) >= 0); assertTrue(facade.isTerminated(projectile)); score += 6; } @@ -2499,7 +2535,8 @@ public class Part3_FullFacadeTest { try { Projectile projectile = facade.fire(theWorm); facade.jump(projectile, 0.0001); - fail(); + assertFalse(facade.getAllItems(theWorld).contains(projectile)); + score += 4; } catch (ModelException exc) { score += 4; } @@ -2985,32 +3022,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 @@ -3081,10 +3127,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; } @@ -3233,9 +3283,9 @@ 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 4.0; p := 7.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) { @@ -3392,7 +3442,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); @@ -3415,7 +3465,7 @@ public class Part3_FullFacadeTest { List 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; } @@ -3423,6 +3473,7 @@ public class Part3_FullFacadeTest { public void testEatStatement_NotEnoughActionPoints() throws ModelException { max_score += 4; Worm worm1 = facade.createWorm(theWorld, new double[] { 7.5, 5.5 }, 7 * PI / 12.0, 1.5, "WormA", theTeam); + facade.createFood(theWorld, new double[] { 8.795, 5.5 }); String code = "eat; "; Program program = ProgramParser.parseProgramFromString(code, programFactory); facade.loadProgramOnWorm(worm1, program, actionHandler); @@ -3442,7 +3493,7 @@ public class Part3_FullFacadeTest { List results = facade.executeProgram(worm1); Object[] expecteds = {}; assertArrayEquals(expecteds, results.toArray()); - assertEquals(2,facade.getAllItems(theWorld).size()); + assertEquals(2, facade.getAllItems(theWorld).size()); score += 4; } @@ -3634,6 +3685,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 results = facade.executeProgram(worm1); Object[] expecteds = { 1.0, 2.0, 3.0, 4.0, 5.0, 10.0 }; @@ -3651,6 +3704,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 results = facade.executeProgram(worm1); Object[] expecteds = { 1.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0, 5.0, 10.0 }; @@ -3666,13 +3721,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; } } @@ -3681,11 +3740,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 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) { @@ -3698,11 +3759,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 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) { @@ -3715,9 +3778,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) { @@ -3732,11 +3797,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 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) { @@ -3749,9 +3816,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 results = facade.executeProgram(worm1); Object[] expecteds = { 1.0, 8.0, 7.0 }; assertArrayEquals(expecteds, results.toArray()); @@ -3766,11 +3835,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 results = facade.executeProgram(worm1); - Object[] expecteds = { 10.0}; + Object[] expecteds = { 10.0 }; assertArrayEquals(expecteds, results.toArray()); score += 8; } catch (MustNotImplementException exc) { @@ -3783,11 +3854,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 results = facade.executeProgram(worm1); - Object[] expecteds = { 13.0}; + Object[] expecteds = { 13.0 }; assertArrayEquals(expecteds, results.toArray()); score += 10; } catch (MustNotImplementException exc) { @@ -3800,11 +3873,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 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) { @@ -3817,11 +3892,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 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) { @@ -3834,15 +3911,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 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) { @@ -3850,11 +3929,6 @@ public class Part3_FullFacadeTest { } } - // break statement - // nested break statements - - // Assignment: assignment to variable with same name as procedure. - /******************* * EXPRESSION TESTS *******************/ @@ -4122,9 +4196,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 results = facade.executeProgram(worm1); Object[] expecteds = { true }; assertArrayEquals(expecteds, results.toArray()); @@ -4140,9 +4216,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 results = facade.executeProgram(worm1); Object[] expecteds = { false }; assertArrayEquals(expecteds, results.toArray()); @@ -4157,9 +4235,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 results = facade.executeProgram(worm1); Object[] expecteds = { false }; assertArrayEquals(expecteds, results.toArray()); @@ -4175,9 +4255,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) {