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 35 additions and 19 deletions
Showing only changes of commit 31a24120eb - Show all commits

View File

@ -42,7 +42,7 @@ class CarTest {
* @param x the expected value for x coordinate
* @param y the expected value for y coordinate
*/
void CheckNextPosition(int x, int y) {
void checkNextPosition(int x, int y) {
assertEquals(new PositionVector(x, y), car.nextPosition());
}
@ -52,7 +52,7 @@ class CarTest {
*/
@Test
void setPosition() {
CheckNextPosition(DEFAULT_X, DEFAULT_Y);
checkNextPosition(DEFAULT_X, DEFAULT_Y);
// List of valid Positions
List<PositionVector> validPositions = new ArrayList<>();
@ -82,13 +82,17 @@ class CarTest {
assertTrue(exception);
// position should keep unchanged
CheckNextPosition(DEFAULT_X, DEFAULT_Y);
checkNextPosition(DEFAULT_X, DEFAULT_Y);
}
}
void checkVelocity(int x, int y) {
assertEquals(new PositionVector(x, y), car.getVelocity());
}
/**
* Checks if the methods accelerate and move are working correctly with acceleration in all directions.
* Checks if the methods accelerate, move and getVelocity are working correctly with acceleration in all directions.
* Checks also if velocity is calculated correctly if method accelerate is called a second time.
*/
@Test
@ -98,7 +102,7 @@ class CarTest {
//position shouldn't be changed because velocity should be 0.
car.move();
CheckNextPosition(DEFAULT_X, DEFAULT_Y);
checkNextPosition(DEFAULT_X, DEFAULT_Y);
for (PositionVector.Direction direction1 : directions) {
@ -106,29 +110,41 @@ class CarTest {
setUp();
//variables to save the actual expected result of method nextPosition
int ExpectedNextPosX = DEFAULT_X;
int ExpectedNextPosY = DEFAULT_Y;
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);
ExpectedNextPosX += direction1.vector.getX();
ExpectedNextPosY += direction1.vector.getY();
CheckNextPosition(ExpectedNextPosX, ExpectedNextPosY);
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();
CheckNextPosition(ExpectedNextPosX, ExpectedNextPosY);
expectedNextPosX += direction1.vector.getX();
expectedNextPosY += direction1.vector.getY();
checkVelocity(expectedVelocityX, expectedVelocityY);
checkNextPosition(expectedNextPosX, expectedNextPosY);
for (PositionVector.Direction direction2 : directions) {
car.accelerate(direction2);
ExpectedNextPosX += direction2.vector.getX();
ExpectedNextPosY += direction2.vector.getY();
CheckNextPosition(ExpectedNextPosX, ExpectedNextPosY);
expectedVelocityX += direction2.vector.getX();
expectedVelocityY += direction2.vector.getY();
expectedNextPosX += direction2.vector.getX();
expectedNextPosY += direction2.vector.getY();
checkVelocity(expectedVelocityX, expectedVelocityY);
checkNextPosition(expectedNextPosX, expectedNextPosY);
car.move();
ExpectedNextPosX += (direction1.vector.getX() + direction2.vector.getX());
ExpectedNextPosY += (direction1.vector.getY() + direction2.vector.getY());
CheckNextPosition(ExpectedNextPosX, ExpectedNextPosY);
checkVelocity(expectedVelocityX, expectedVelocityY);
expectedNextPosX += (direction1.vector.getX() + direction2.vector.getX());
expectedNextPosY += (direction1.vector.getY() + direction2.vector.getY());
checkNextPosition(expectedNextPosX, expectedNextPosY);
}
}
}