codecleanup

This commit is contained in:
Andrin Fassbind 2022-03-25 23:06:23 +01:00
parent c41b56b47e
commit be240d6721
2 changed files with 39 additions and 0 deletions

View File

@ -33,6 +33,9 @@ class CarTest {
car = new Car(DEFAULT_ID, new PositionVector(DEFAULT_X, DEFAULT_Y)); car = new Car(DEFAULT_ID, new PositionVector(DEFAULT_X, DEFAULT_Y));
} }
/**
* Checks getID
*/
@Test @Test
void getID() { void getID() {
assertEquals(DEFAULT_ID, car.getID()); assertEquals(DEFAULT_ID, car.getID());

View File

@ -45,6 +45,9 @@ class GameTest {
} }
/**
* Tests if Carindex is correct
*/
@Test @Test
void getCurrentCarIndex() { void getCurrentCarIndex() {
Assertions.assertEquals(CAR_INDEX_ONE, game.getCurrentCarIndex()); Assertions.assertEquals(CAR_INDEX_ONE, game.getCurrentCarIndex());
@ -52,34 +55,52 @@ class GameTest {
Assertions.assertEquals(CAR_INDEX_TWO, game.getCurrentCarIndex()); Assertions.assertEquals(CAR_INDEX_TWO, game.getCurrentCarIndex());
} }
/**
* Checks if CarId matches char given in trackfile
*/
@Test @Test
void getCarId() { void getCarId() {
Assertions.assertEquals('a', game.getCarId(0)); Assertions.assertEquals('a', game.getCarId(0));
Assertions.assertEquals('b', game.getCarId(1)); Assertions.assertEquals('b', game.getCarId(1));
} }
/**
* Checks initial carposition
*/
@Test @Test
void getCarPosition() { void getCarPosition() {
Assertions.assertEquals(new PositionVector(24, 22), game.getCarPosition(0)); Assertions.assertEquals(new PositionVector(24, 22), game.getCarPosition(0));
Assertions.assertEquals(new PositionVector(24, 24), game.getCarPosition(1)); Assertions.assertEquals(new PositionVector(24, 24), game.getCarPosition(1));
} }
/**
* Checks if initial carvelocity is 0,0
*/
@Test @Test
void getCarVelocity() { void getCarVelocity() {
Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(0)); Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(0));
Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(1)); Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(1));
} }
/**
* Checks initial winner
*/
@Test @Test
void getWinner() { void getWinner() {
Assertions.assertEquals(NO_WINNER, game.getWinner()); Assertions.assertEquals(NO_WINNER, game.getWinner());
} }
/**
* Checks correct inital state
*/
@Test @Test
void onlyOneCarLeft() { void onlyOneCarLeft() {
Assertions.assertFalse(game.onlyOneCarLeft()); Assertions.assertFalse(game.onlyOneCarLeft());
} }
/**
* Checks if cars are able to move
*/
@Test @Test
void carsMoving() { void carsMoving() {
Assertions.assertTrue(game.carsMoving()); Assertions.assertTrue(game.carsMoving());
@ -109,6 +130,9 @@ class GameTest {
} }
/**
* Checks if car does change velocity specified by direction input
*/
@Test @Test
void carTurnCorrect() { void carTurnCorrect() {
game.doCarTurn(RIGHT); game.doCarTurn(RIGHT);
@ -131,6 +155,9 @@ class GameTest {
class Play { class Play {
private Game game; private Game game;
/**
* This method will start a game instance on the challenge track. Car a uses MoveListStrategy. Car b uses DoNotMoveStrategy
*/
@Test @Test
void winner() { void winner() {
game = new Game(new interFace("Test",new Integer[]{0,2,0},new PositionVector.Direction[]{RIGHT, 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()); Assertions.assertEquals("a",game.gamePhase());
} }
/**
* Will start a game instance where car a does crash.
*/
@Test @Test
void crashA() { void crashA() {
game = new Game(new interFace("Test",new Integer[]{0,1,0},new PositionVector.Direction[]{UP}), new Config()); 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()); Assertions.assertEquals("b",game.gamePhase());
} }
/**
* Checks that a car cant win before finishing a complete round around the track.
*/
@Test @Test
void passFinishLineInWrongDirection() { void passFinishLineInWrongDirection() {
game = new Game(new interFace("Test",new Integer[]{1,0,1},new PositionVector.Direction[]{LEFT,NONE,NONE,RIGHT,RIGHT}), new Config()); 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()); Assertions.assertEquals("a",game.gamePhase());
} }
/**
* Does wait 10 seconds before closing the textio.
*/
@AfterEach @AfterEach
void cleanUp() { void cleanUp() {
try { try {