team02-AngryNerds-projekt1-.../src/test/java/ch/zhaw/pm2/racetrack/GameTest.java

105 lines
3.3 KiB
Java

package ch.zhaw.pm2.racetrack;
import ch.zhaw.pm2.racetrack.strategy.UserMoveStrategy;
import org.junit.jupiter.api.*;
import java.io.File;
import static ch.zhaw.pm2.racetrack.Game.NO_WINNER;
class GameTest {
private UserInterface userInterface;
private Game game;
private Track track;
@Nested
@DisplayName("Test correct Setup")
class Setup {
@BeforeEach
void setup() {
userInterface = new UserInterface("Test");
game = new Game(userInterface);
track = game.selectTrack(new File(".\\tracks\\challenge.txt"));
game.selectMoveStrategy(track.getCar(0),new UserMoveStrategy(new UserInterface("Testing"),0, track.getCarId(0)));
game.selectMoveStrategy(track.getCar(1),new UserMoveStrategy(new UserInterface("Testing"),1, track.getCarId(1)));
}
@Test
void getCurrentCarIndex() {
Assertions.assertEquals(0,game.getCurrentCarIndex());
game.switchToNextActiveCar();
Assertions.assertEquals(1,game.getCurrentCarIndex());
}
@Test
void getCarId() {
Assertions.assertEquals('a',game.getCarId(0));
Assertions.assertEquals('b',game.getCarId(1));
}
@Test
void getCarPosition() {
Assertions.assertEquals(new PositionVector(24,22),game.getCarPosition(0));
Assertions.assertEquals(new PositionVector(24,24),game.getCarPosition(1));
}
@Test
void getCarVelocity() {
Assertions.assertEquals(new PositionVector(0,0),game.getCarVelocity(0));
Assertions.assertEquals(new PositionVector(0,0),game.getCarVelocity(1));
}
@Test
void getWinner() {
Assertions.assertEquals(NO_WINNER,game.getWinner());
}
@Test
void onlyOneCarLeft() {
Assertions.assertFalse(game.onlyOneCarLeft());
}
@Test
void carsMoving() {
Assertions.assertTrue(game.carsMoving());
}
}
@Nested
@DisplayName("Basic manipulation")
class manipulation {
@BeforeEach
void setup() {
userInterface = new UserInterface("Test");
game = new Game(userInterface);
track = game.selectTrack(new File(".\\tracks\\challenge.txt"));
game.selectMoveStrategy(track.getCar(0),new UserMoveStrategy(new UserInterface("Testing"),0, track.getCarId(0)));
game.selectMoveStrategy(track.getCar(1),new UserMoveStrategy(new UserInterface("Testing"),1, track.getCarId(1)));
}
@Test
void carTurnCorrect() {
try {
game.doCarTurn(PositionVector.Direction.RIGHT);
Assertions.assertEquals(new PositionVector(1,0),game.getCarVelocity(0));
} catch (PositionVectorNotValid positionVectorNotValid) {
positionVectorNotValid.printStackTrace();
}
}
@Test
void carCrash() {
try {
game.doCarTurn(PositionVector.Direction.UP);
Assertions.assertTrue(game.onlyOneCarLeft());
} catch (PositionVectorNotValid positionVectorNotValid) {
positionVectorNotValid.printStackTrace();
}
}
}
}