diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index b6aca51..755af8b 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -6,6 +6,7 @@ import ch.zhaw.pm2.racetrack.strategy.*; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static ch.zhaw.pm2.racetrack.PositionVector.Direction; @@ -34,9 +35,7 @@ public class Game implements GameSpecification { */ public boolean initPhase() { if (config.getTrackDirectory().listFiles().length > 0) { - List tracks = new ArrayList<>(); - - File selectedTrack = config.getTrackDirectory().listFiles()[userInterface.selectOption("Select Track file", tracks)]; + File selectedTrack = config.getTrackDirectory().listFiles()[userInterface.selectOption("Select Track file", Arrays.asList(config.getTrackDirectory().list()))]; try { selectTrack(selectedTrack); } catch (FileNotFoundException e) { diff --git a/src/test/java/ch/zhaw/pm2/racetrack/CarTest.java b/src/test/java/ch/zhaw/pm2/racetrack/CarTest.java index aeaf688..4d274c7 100644 --- a/src/test/java/ch/zhaw/pm2/racetrack/CarTest.java +++ b/src/test/java/ch/zhaw/pm2/racetrack/CarTest.java @@ -33,6 +33,9 @@ class CarTest { car = new Car(DEFAULT_ID, new PositionVector(DEFAULT_X, DEFAULT_Y)); } + /** + * Checks getID + */ @Test void getID() { assertEquals(DEFAULT_ID, car.getID()); diff --git a/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java b/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java index bede5b2..9be5d2b 100644 --- a/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java +++ b/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java @@ -45,6 +45,9 @@ class GameTest { } + /** + * Tests if Carindex is correct + */ @Test void getCurrentCarIndex() { Assertions.assertEquals(CAR_INDEX_ONE, game.getCurrentCarIndex()); @@ -52,34 +55,52 @@ class GameTest { Assertions.assertEquals(CAR_INDEX_TWO, game.getCurrentCarIndex()); } + /** + * Checks if CarId matches char given in trackfile + */ @Test void getCarId() { Assertions.assertEquals('a', game.getCarId(0)); Assertions.assertEquals('b', game.getCarId(1)); } + /** + * Checks initial carposition + */ @Test void getCarPosition() { Assertions.assertEquals(new PositionVector(24, 22), game.getCarPosition(0)); Assertions.assertEquals(new PositionVector(24, 24), game.getCarPosition(1)); } + /** + * Checks if initial carvelocity is 0,0 + */ @Test void getCarVelocity() { Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(0)); Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(1)); } + /** + * Checks initial winner + */ @Test void getWinner() { Assertions.assertEquals(NO_WINNER, game.getWinner()); } + /** + * Checks correct inital state + */ @Test void onlyOneCarLeft() { Assertions.assertFalse(game.onlyOneCarLeft()); } + /** + * Checks if cars are able to move + */ @Test void carsMoving() { Assertions.assertTrue(game.carsMoving()); @@ -109,6 +130,9 @@ class GameTest { } + /** + * Checks if car does change velocity specified by direction input + */ @Test void carTurnCorrect() { game.doCarTurn(RIGHT); @@ -131,6 +155,9 @@ class GameTest { class Play { private Game game; + /** + * This method will start a game instance on the challenge track. Car a uses MoveListStrategy. Car b uses DoNotMoveStrategy + */ @Test void winner() { game = new Game(new interFace("Test",new Integer[]{0,2,0},new PositionVector.Direction[]{RIGHT, @@ -176,6 +203,9 @@ class GameTest { Assertions.assertEquals("a",game.gamePhase()); } + /** + * Will start a game instance where car a does crash. + */ @Test void crashA() { game = new Game(new interFace("Test",new Integer[]{0,1,0},new PositionVector.Direction[]{UP}), new Config()); @@ -183,6 +213,9 @@ class GameTest { Assertions.assertEquals("b",game.gamePhase()); } + /** + * Checks that a car cant win before finishing a complete round around the track. + */ @Test void passFinishLineInWrongDirection() { game = new Game(new interFace("Test",new Integer[]{1,0,1},new PositionVector.Direction[]{LEFT,NONE,NONE,RIGHT,RIGHT}), new Config()); @@ -190,6 +223,9 @@ class GameTest { Assertions.assertEquals("a",game.gamePhase()); } + /** + * Does wait 10 seconds before closing the textio. + */ @AfterEach void cleanUp() { try {