turn right succesfull
This commit is contained in:
parent
4bf2c88852
commit
be56b4478a
|
@ -12,7 +12,7 @@ public enum Direction {
|
|||
};
|
||||
}
|
||||
|
||||
public Direction changeDirectionToLeft() {
|
||||
public Direction getNextDirectionRotatingToLeft() {
|
||||
return switch (this) {
|
||||
case NORTH -> WEST;
|
||||
case SOUTH -> EAST;
|
||||
|
@ -20,4 +20,13 @@ public enum Direction {
|
|||
case WEST -> SOUTH;
|
||||
};
|
||||
}
|
||||
|
||||
public Direction getNextDirectionRotatingToRight() {
|
||||
return switch (this) {
|
||||
case NORTH -> EAST;
|
||||
case SOUTH -> WEST;
|
||||
case EAST -> SOUTH;
|
||||
case WEST -> NORTH;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,11 @@ public class MarsRover {
|
|||
}
|
||||
|
||||
public Direction turnLeft() {
|
||||
return currentDirection = currentDirection.changeDirectionToLeft();
|
||||
return currentDirection = currentDirection.getNextDirectionRotatingToLeft();
|
||||
}
|
||||
|
||||
public Direction turnRight() {
|
||||
return currentDirection = currentDirection.getNextDirectionRotatingToRight();
|
||||
}
|
||||
|
||||
public Coordinates getCurrentCoordinates() {
|
||||
|
|
|
@ -68,12 +68,20 @@ public class MarsRoverTest {
|
|||
|
||||
@Test
|
||||
public void turnLef() {
|
||||
Direction currentDirection = rover.turnLeft();
|
||||
assertEquals(currentDirection, EAST);
|
||||
assertEquals(rover.turnLeft(), EAST);
|
||||
assertEquals(rover.turnLeft(), NORTH);
|
||||
assertEquals(rover.turnLeft(), WEST);
|
||||
repeatAction(2, i -> rover.turnLeft());
|
||||
assertEquals(currentDirection, EAST);
|
||||
assertEquals(rover.turnLeft(), SOUTH);
|
||||
assertEquals(rover.turnLeft(), EAST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void turnRight() {
|
||||
assertEquals(rover.turnRight(), WEST);
|
||||
assertEquals(rover.turnRight(), NORTH);
|
||||
assertEquals(rover.turnRight(), EAST);
|
||||
assertEquals(rover.turnRight(), SOUTH);
|
||||
assertEquals(rover.turnRight(), WEST);
|
||||
}
|
||||
|
||||
private void repeatAction(int times, IntConsumer actionToRepeat) {
|
||||
|
|
Loading…
Reference in New Issue