From 1d15cd7254e5ff90e09de99c3283bf3475271cbb Mon Sep 17 00:00:00 2001 From: Xavier Fontanet Date: Thu, 20 Jun 2024 18:21:18 +0200 Subject: [PATCH] simplify --- .../hack3/codingtests/marsrover/Coordinates.java | 14 +++++++------- .../hack3/codingtests/marsrover/MarsRoverTest.java | 10 +++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java b/src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java index 3ddc2fc..fb8bcd7 100644 --- a/src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java +++ b/src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java @@ -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); diff --git a/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java b/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java index 3413ce3..a11b4ba 100644 --- a/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java +++ b/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java @@ -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); } }