also in backwards
This commit is contained in:
parent
20b785ef29
commit
ac72870894
|
@ -65,11 +65,16 @@ public class MarsMap {
|
||||||
setNewLongitude(newLongitude);
|
setNewLongitude(newLongitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNewLongitude(int newLongitude) {
|
private void decrementLongitude() {
|
||||||
currentPosition = currentPosition.ofUpdatedLongitude(newLongitude);
|
int longitude = currentPosition.getLongitude();
|
||||||
|
int newLongitude = longitude - 1 < 1
|
||||||
|
? width
|
||||||
|
: --longitude;
|
||||||
|
setNewLongitude(newLongitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decrementLongitude() {
|
private void setNewLongitude(int newLongitude) {
|
||||||
|
currentPosition = currentPosition.ofUpdatedLongitude(newLongitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinates getCurrentPosition() {
|
public Coordinates getCurrentPosition() {
|
||||||
|
|
|
@ -95,6 +95,17 @@ public class MarsRoverTest {
|
||||||
assertEquals(rover.getCurrentDirection(), EAST);
|
assertEquals(rover.getCurrentDirection(), EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loopTheWorldInLongitudeMovingBackwards() {
|
||||||
|
Coordinates originalCoordinates = rover.getCurrentCoordinates();
|
||||||
|
|
||||||
|
rover.turnLeft();
|
||||||
|
repeatAction(10, i -> rover.moveBackwards());
|
||||||
|
|
||||||
|
assertEquals(rover.getCurrentCoordinates(), originalCoordinates);
|
||||||
|
assertEquals(rover.getCurrentDirection(), EAST);
|
||||||
|
}
|
||||||
|
|
||||||
private void repeatAction(int times, IntConsumer actionToRepeat) {
|
private void repeatAction(int times, IntConsumer actionToRepeat) {
|
||||||
IntStream.rangeClosed(1, times)
|
IntStream.rangeClosed(1, times)
|
||||||
.forEach(actionToRepeat);
|
.forEach(actionToRepeat);
|
||||||
|
|
Loading…
Reference in New Issue