diff --git a/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/CommonTests.java b/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/CommonTests.java index fe3e247..1889ad1 100644 --- a/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/CommonTests.java +++ b/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/CommonTests.java @@ -10,6 +10,7 @@ import cat.hack3.codingtests.marsrover.plugin.station.PlanetMapInitializerProvid import cat.hack3.codingtests.marsrover.plugin.station.RoverDeployerProvider; import java.util.List; +import java.util.stream.IntStream; import static cat.hack3.codingtests.marsrover.cartography.Direction.SOUTH; import static cat.hack3.codingtests.marsrover.commands.api.RoverCommand.Type.*; @@ -60,4 +61,9 @@ public class CommonTests { protected List getObstacles() { return List.of(); } + + protected void repeatAction(int times, Runnable actionToRepeat) { + IntStream.rangeClosed(1, times) + .forEach(i -> actionToRepeat.run()); + } } diff --git a/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverTest.java b/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverTest.java index c45d831..1181258 100644 --- a/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverTest.java +++ b/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverTest.java @@ -5,8 +5,6 @@ import cat.hack3.codingtests.marsrover.cartography.Direction; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.util.stream.IntStream; - import static cat.hack3.codingtests.marsrover.cartography.Direction.*; import static org.testng.Assert.assertEquals; @@ -133,8 +131,4 @@ public class MarsRoverTest extends CommonTests { assertEquals(rover.getCurrentDirection(), EAST); } - private void repeatAction(int times, Runnable actionToRepeat) { - IntStream.rangeClosed(1, times) - .forEach(i -> actionToRepeat.run()); - } } diff --git a/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverWithObstaclesTest.java b/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverWithObstaclesTest.java index 7ed9620..0c44bea 100644 --- a/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverWithObstaclesTest.java +++ b/tests-suite/src/test/java/cat/hack3/codingtests/marsrover/test/MarsRoverWithObstaclesTest.java @@ -33,28 +33,23 @@ public class MarsRoverWithObstaclesTest extends CommonTests { moveForwardCommand.execute(); Coordinates oneStepForward = rover.getCurrentCoordinates(); assertNotEquals(oneStepForward, Coordinates.of(3, 3)); + assertEquals(oneStepForward, Coordinates.of(2, 3)); turnLeftCommand.execute(); - moveForwardCommand.execute(); - moveForwardCommand.execute(); + repeatAction(2, () -> moveForwardCommand.execute()); turnRightCommand.execute(); + repeatAction(2, () -> moveForwardCommand.execute()); + assertEquals(rover.getCurrentCoordinates(), Coordinates.of(4, 5)); moveForwardCommand.execute(); - moveForwardCommand.execute(); - var currentPosition = Coordinates.of(4, 5); - assertEquals(rover.getCurrentCoordinates(), currentPosition); - moveForwardCommand.execute(); - var positionAfterMove = Coordinates.of(5, 4); - assertNotEquals(rover.getCurrentCoordinates(), positionAfterMove); + assertNotEquals(rover.getCurrentCoordinates(), Coordinates.of(5, 5)); + assertEquals(rover.getCurrentCoordinates(), Coordinates.of(4, 5)); } @Override protected List getObstacles() { return List.of( Coordinates.of(3, 3), - Coordinates.of(5, 5), - Coordinates.of(7, 7), - Coordinates.of(9, 9), - Coordinates.of(10, 10) + Coordinates.of(5, 5) ); } }