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