1
0
Fork 0

rover makes a long ride

This commit is contained in:
Xavier Fontanet 2024-06-20 17:31:40 +02:00
parent 3f4aafd43e
commit 5f44eb39fc
3 changed files with 18 additions and 0 deletions

View File

@ -1,5 +1,8 @@
package cat.hack3.codingtests.marsrover;
import java.util.logging.Logger;
/**
* Notice that the representation is the following:
* Latitude is Y, starts from 0 on the top and goes down incrementally
@ -12,6 +15,7 @@ package cat.hack3.codingtests.marsrover;
public class Coordinates {
private int latitude;
private int longitude;
private Logger logger = Logger.getLogger(Coordinates.class.getName());
public static Coordinates of(int latitude, int longitude) {
return new Coordinates(latitude, longitude);
@ -24,6 +28,7 @@ public class Coordinates {
public Coordinates incrementSouth() {
latitude++;
logger.info("incremented South latitude, now is "+latitude);
return this;
}

View File

@ -19,4 +19,8 @@ public class MarsRover {
case WEST -> null;
};
}
public Coordinates getCurrentCoordinates() {
return currentCoordinates;
}
}

View File

@ -3,6 +3,8 @@ package cat.hack3.codingtests.marsrover;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.stream.IntStream;
import static cat.hack3.codingtests.marsrover.MarsMap.Direction.SOUTH;
import static org.testng.Assert.assertEquals;
@ -28,4 +30,11 @@ public class MarsRoverTest {
Coordinates currentPosition = rover.moveForward();
assertEquals(currentPosition, Coordinates.of(3, 3));
}
@Test
public void make5StepsInARow() {
IntStream.rangeClosed(0, 5)
.forEach(i -> rover.moveForward());
assertEquals(rover.getCurrentCoordinates(), Coordinates.of(8, 3));
}
}