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