Merge remote-tracking branch 'origin/main'

This commit is contained in:
Leonardo Brandenberger 2022-03-25 23:16:21 +01:00
commit 3b76abf760
3 changed files with 41 additions and 3 deletions

View File

@ -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<String> 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) {

View File

@ -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());

View File

@ -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 {