Fixed Error in CarTest.java #20
|
@ -1,60 +1,136 @@
|
|||
|
||||
package ch.zhaw.pm2.racetrack;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import ch.zhaw.pm2.racetrack.strategy.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class CarTest {
|
||||
Car car;
|
||||
int DEFAULT_X = 10;
|
||||
int DEFAULT_Y = 10;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
car = new Car('a', new PositionVector(10, 10));
|
||||
car = new Car('a', new PositionVector(DEFAULT_X, DEFAULT_Y));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setPosition() {
|
||||
car.setPosition(new PositionVector(20, 20));
|
||||
checkPosition(20, 20);
|
||||
CheckNextPosition(DEFAULT_X, DEFAULT_Y);
|
||||
|
||||
List<PositionVector> validPositions = new ArrayList<>();
|
||||
validPositions.add(new PositionVector(20, 20));
|
||||
validPositions.add(new PositionVector(0, 0));
|
||||
validPositions.add(new PositionVector(20, 0));
|
||||
validPositions.add(new PositionVector(0, 20));
|
||||
|
||||
for(PositionVector positionVector : validPositions) {
|
||||
car.setPosition(positionVector);
|
||||
assertEquals(positionVector, car.nextPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nextPosition() {
|
||||
checkPosition(10, 10);
|
||||
List<PositionVector> invalidPositions = new ArrayList<>();
|
||||
invalidPositions.add(new PositionVector(0, -20));
|
||||
invalidPositions.add(new PositionVector(-20, 0));
|
||||
invalidPositions.add(new PositionVector(-20, -20));
|
||||
|
||||
for(PositionVector positionVector : invalidPositions) {
|
||||
boolean exception = false;
|
||||
try {
|
||||
car.setPosition(positionVector);
|
||||
} catch (IllegalArgumentException e) {
|
||||
exception = true;
|
||||
}
|
||||
assertTrue(exception);
|
||||
|
||||
CheckNextPosition(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void accelerate() {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void move() {
|
||||
void movement() {
|
||||
car.move();
|
||||
CheckNextPosition(DEFAULT_X, DEFAULT_Y);
|
||||
|
||||
List<PositionVector.Direction> directions = Arrays.asList(PositionVector.Direction.values());
|
||||
|
||||
for (PositionVector.Direction direction1 : directions){
|
||||
|
||||
setUp();
|
||||
int nextPosX = DEFAULT_X;
|
||||
int nextPosY = DEFAULT_Y;
|
||||
|
||||
car.accelerate(direction1);
|
||||
nextPosX += direction1.vector.getX();
|
||||
nextPosY += direction1.vector.getY();
|
||||
CheckNextPosition(nextPosX, nextPosY);
|
||||
|
||||
car.move();
|
||||
nextPosX += direction1.vector.getX();
|
||||
nextPosY += direction1.vector.getY();
|
||||
CheckNextPosition(nextPosX, nextPosY);
|
||||
|
||||
for (PositionVector.Direction direction2 : directions) {
|
||||
car.accelerate(direction2);
|
||||
nextPosX += direction2.vector.getX();
|
||||
nextPosY += direction2.vector.getY();
|
||||
CheckNextPosition(nextPosX, nextPosY);
|
||||
|
||||
car.move();
|
||||
nextPosX += direction1.vector.getX();
|
||||
nextPosY += direction1.vector.getY();
|
||||
nextPosX += direction2.vector.getX();
|
||||
nextPosY += direction2.vector.getY();
|
||||
CheckNextPosition(nextPosX, nextPosY);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void crash() {
|
||||
assertFalse(car.isCrashed());
|
||||
car.crash();
|
||||
assertTrue(car.isCrashed());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void isCrashed() {
|
||||
void MoveStrategy() {
|
||||
MoveStrategy moveStrategy;
|
||||
|
||||
moveStrategy = new DoNotMoveStrategy();
|
||||
car.setMoveStrategy(moveStrategy);
|
||||
assertEquals(moveStrategy, car.getMoveStrategy());
|
||||
|
||||
moveStrategy = new MoveListStrategy();
|
||||
car.setMoveStrategy(moveStrategy);
|
||||
assertEquals(moveStrategy, car.getMoveStrategy());
|
||||
|
||||
moveStrategy = new PathFollowerMoveStrategy();
|
||||
car.setMoveStrategy(moveStrategy);
|
||||
assertEquals(moveStrategy, car.getMoveStrategy());
|
||||
|
||||
moveStrategy = new UserMoveStrategy();
|
||||
car.setMoveStrategy(moveStrategy);
|
||||
assertEquals(moveStrategy, car.getMoveStrategy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setMoveStrategy() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getMoveStrategy() {
|
||||
}
|
||||
|
||||
void checkPosition(int x, int y) {
|
||||
assertTrue(car.nextPosition().equals(new PositionVector(x, y)));
|
||||
void CheckNextPosition(int x, int y) {
|
||||
assertEquals(new PositionVector(x, y), car.nextPosition());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue