Legger til test for at roboter i full rundkjøring blir flyttet som forventet og at det ikke skapes en evig loop i koden

Co-Authored-By: gabrielmagnus <gabrielmagnus@users.noreply.github.com>
This commit is contained in:
torlunjen 2020-04-21 15:46:30 +02:00
parent 6606f8aa52
commit f9fc0507fb

View File

@ -285,4 +285,33 @@ public class PhaseTest {
assertEquals(RobotID.ROBOT_3, board.getRobotOnPosition(new Position(4, 7)));
assertEquals(RobotID.ROBOT_4, board.getRobotOnPosition(new Position(4, 8)));
}
@Test
public void robotBehindOtherRobotsOnConveyorBeltsShapedAsARoundaboutMoves() {
long startTime = System.currentTimeMillis();
List<Robot> robots = new ArrayList<>();
List<Player> players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 8)));
robots.add(new Robot(RobotID.ROBOT_2, new Position(2, 8)));
robots.add(new Robot(RobotID.ROBOT_3, new Position(2, 9)));
robots.add(new Robot(RobotID.ROBOT_4, new Position(1, 9)));
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
players.add(new Player(RobotID.ROBOT_2, "Player 2"));
players.add(new Player(RobotID.ROBOT_3, "Player 3"));
players.add(new Player(RobotID.ROBOT_4, "Player 4"));
try {
board = BoardLoaderUtil.loadBoard("boards/test_board.txt", robots);
Phase testPhase = new Phase(board, players, 0, null);
testPhase.moveAllConveyorBelts();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(1, 9)));
assertEquals(RobotID.ROBOT_2, board.getRobotOnPosition(new Position(1, 8)));
assertEquals(RobotID.ROBOT_3, board.getRobotOnPosition(new Position(2, 8)));
assertEquals(RobotID.ROBOT_4, board.getRobotOnPosition(new Position(2, 9)));
int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f);
assertTrue(elapsedTime < 1);
}
}