1
0
Fork 0

slight improve on test suit

This commit is contained in:
Xavier Fontanet 2024-06-24 01:06:30 +02:00
parent 877d534716
commit d40ff90c6e
3 changed files with 13 additions and 18 deletions

View File

@ -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<Coordinates> getObstacles() {
return List.of();
}
protected void repeatAction(int times, Runnable actionToRepeat) {
IntStream.rangeClosed(1, times)
.forEach(i -> actionToRepeat.run());
}
}

View File

@ -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());
}
}

View File

@ -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<Coordinates> 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)
);
}
}