simplify
This commit is contained in:
parent
24bc0f8057
commit
1d15cd7254
|
@ -5,17 +5,17 @@ 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
|
||||
* Longitude is X, starts from 0 on the left and goes to right incrementally
|
||||
* 0 1 2 3
|
||||
* 1 11 12 13
|
||||
* 2 12 22 23
|
||||
* 3 13 23 33
|
||||
* Latitude is Y, starts from 1 on the top and goes down incrementally
|
||||
* Longitude is X, starts from 1 on the left and goes to right incrementally
|
||||
* 1 2 3
|
||||
* 1 1-1 1-2 1-3
|
||||
* 2 2-1 2-2 2-3
|
||||
* 3 3-1 3-2 3-3
|
||||
*/
|
||||
public class Coordinates {
|
||||
private int latitude;
|
||||
private int longitude;
|
||||
private Logger logger = Logger.getLogger(Coordinates.class.getName());
|
||||
private final Logger logger = Logger.getLogger(Coordinates.class.getName());
|
||||
|
||||
public static Coordinates of(int latitude, int longitude) {
|
||||
return new Coordinates(latitude, longitude);
|
||||
|
|
|
@ -12,14 +12,13 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
public class MarsRoverTest {
|
||||
|
||||
private MarsMap marsMap;
|
||||
private MarsRover rover;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
int mapWidth = 10;
|
||||
int mapHeight = 10;
|
||||
marsMap = new MarsMap(mapWidth, mapHeight);
|
||||
var marsMap = new MarsMap(mapWidth, mapHeight);
|
||||
|
||||
int latitudeStartingPoint = 2;
|
||||
int longitudeStartingPoint = 3;
|
||||
|
@ -28,14 +27,11 @@ public class MarsRoverTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void roverMakeItsFirstStep() {
|
||||
public void stepForward() {
|
||||
Coordinates currentPosition = rover.moveForward();
|
||||
assertEquals(currentPosition, Coordinates.of(3, 3));
|
||||
assertEquals(rover.getCurrentDirection(), SOUTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void make5StepsInARow() {
|
||||
repeatAction(5, i -> rover.moveForward());
|
||||
assertEquals(rover.getCurrentCoordinates(), Coordinates.of(8, 3));
|
||||
assertEquals(rover.getCurrentDirection(), SOUTH);
|
||||
|
@ -52,7 +48,7 @@ public class MarsRoverTest {
|
|||
}
|
||||
|
||||
private void repeatAction(int times, IntConsumer actionToRepeat) {
|
||||
IntStream.rangeClosed(0, times)
|
||||
IntStream.rangeClosed(1, times)
|
||||
.forEach(actionToRepeat);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue