Fixed Error in CarTest.java #20

Merged
schrom01 merged 9 commits from car into main 2022-03-10 14:51:27 +01:00
1 changed files with 29 additions and 26 deletions
Showing only changes of commit a67a96d19d - Show all commits

View File

@ -105,34 +105,37 @@ class CarTest {
car.move(); car.move();
checkNextPosition(DEFAULT_X, DEFAULT_Y); checkNextPosition(DEFAULT_X, DEFAULT_Y);
for (PositionVector.Direction direction1 : directions) { for (PositionVector.Direction direction1 : directions) {
//create a new instance of Car with default coordinates and velocity 0.
setUp();
//variables to save the actual expected result of method nextPosition
int expectedNextPosX = DEFAULT_X;
int expectedNextPosY = DEFAULT_Y;
//variables to save the acutal expected result of method getVelocity
int expectedVelocityX = 0;
int expectedVelocityY = 0;
car.accelerate(direction1);
expectedVelocityX += direction1.vector.getX();
expectedVelocityY += direction1.vector.getY();
expectedNextPosX += direction1.vector.getX();
expectedNextPosY += direction1.vector.getY();
checkVelocity(expectedVelocityX, expectedVelocityY);
checkNextPosition(expectedNextPosX, expectedNextPosY);
car.move();
expectedNextPosX += direction1.vector.getX();
expectedNextPosY += direction1.vector.getY();
checkVelocity(expectedVelocityX, expectedVelocityY);
checkNextPosition(expectedNextPosX, expectedNextPosY);
for (PositionVector.Direction direction2 : directions) { for (PositionVector.Direction direction2 : directions) {
//create a new instance of Car with default coordinates and velocity 0.
setUp();
//variables to save the actual expected result of method nextPosition
int expectedNextPosX = DEFAULT_X;
int expectedNextPosY = DEFAULT_Y;
//variables to save the acutal expected result of method getVelocity
int expectedVelocityX = 0;
int expectedVelocityY = 0;
car.accelerate(direction1);
expectedVelocityX += direction1.vector.getX();
expectedVelocityY += direction1.vector.getY();
expectedNextPosX += direction1.vector.getX();
expectedNextPosY += direction1.vector.getY();
checkVelocity(expectedVelocityX, expectedVelocityY);
checkNextPosition(expectedNextPosX, expectedNextPosY);
car.move();
expectedNextPosX += direction1.vector.getX();
expectedNextPosY += direction1.vector.getY();
checkVelocity(expectedVelocityX, expectedVelocityY);
checkNextPosition(expectedNextPosX, expectedNextPosY);
car.accelerate(direction2); car.accelerate(direction2);
expectedVelocityX += direction2.vector.getX(); expectedVelocityX += direction2.vector.getX();
expectedVelocityY += direction2.vector.getY(); expectedVelocityY += direction2.vector.getY();