slight improve on test suit
This commit is contained in:
parent
877d534716
commit
d40ff90c6e
|
@ -10,6 +10,7 @@ import cat.hack3.codingtests.marsrover.plugin.station.PlanetMapInitializerProvid
|
||||||
import cat.hack3.codingtests.marsrover.plugin.station.RoverDeployerProvider;
|
import cat.hack3.codingtests.marsrover.plugin.station.RoverDeployerProvider;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static cat.hack3.codingtests.marsrover.cartography.Direction.SOUTH;
|
import static cat.hack3.codingtests.marsrover.cartography.Direction.SOUTH;
|
||||||
import static cat.hack3.codingtests.marsrover.commands.api.RoverCommand.Type.*;
|
import static cat.hack3.codingtests.marsrover.commands.api.RoverCommand.Type.*;
|
||||||
|
@ -60,4 +61,9 @@ public class CommonTests {
|
||||||
protected List<Coordinates> getObstacles() {
|
protected List<Coordinates> getObstacles() {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void repeatAction(int times, Runnable actionToRepeat) {
|
||||||
|
IntStream.rangeClosed(1, times)
|
||||||
|
.forEach(i -> actionToRepeat.run());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import static cat.hack3.codingtests.marsrover.cartography.Direction.*;
|
import static cat.hack3.codingtests.marsrover.cartography.Direction.*;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -133,8 +131,4 @@ public class MarsRoverTest extends CommonTests {
|
||||||
assertEquals(rover.getCurrentDirection(), EAST);
|
assertEquals(rover.getCurrentDirection(), EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repeatAction(int times, Runnable actionToRepeat) {
|
|
||||||
IntStream.rangeClosed(1, times)
|
|
||||||
.forEach(i -> actionToRepeat.run());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,28 +33,23 @@ public class MarsRoverWithObstaclesTest extends CommonTests {
|
||||||
moveForwardCommand.execute();
|
moveForwardCommand.execute();
|
||||||
Coordinates oneStepForward = rover.getCurrentCoordinates();
|
Coordinates oneStepForward = rover.getCurrentCoordinates();
|
||||||
assertNotEquals(oneStepForward, Coordinates.of(3, 3));
|
assertNotEquals(oneStepForward, Coordinates.of(3, 3));
|
||||||
|
assertEquals(oneStepForward, Coordinates.of(2, 3));
|
||||||
|
|
||||||
turnLeftCommand.execute();
|
turnLeftCommand.execute();
|
||||||
moveForwardCommand.execute();
|
repeatAction(2, () -> moveForwardCommand.execute());
|
||||||
moveForwardCommand.execute();
|
|
||||||
turnRightCommand.execute();
|
turnRightCommand.execute();
|
||||||
|
repeatAction(2, () -> moveForwardCommand.execute());
|
||||||
|
assertEquals(rover.getCurrentCoordinates(), Coordinates.of(4, 5));
|
||||||
moveForwardCommand.execute();
|
moveForwardCommand.execute();
|
||||||
moveForwardCommand.execute();
|
assertNotEquals(rover.getCurrentCoordinates(), Coordinates.of(5, 5));
|
||||||
var currentPosition = Coordinates.of(4, 5);
|
assertEquals(rover.getCurrentCoordinates(), Coordinates.of(4, 5));
|
||||||
assertEquals(rover.getCurrentCoordinates(), currentPosition);
|
|
||||||
moveForwardCommand.execute();
|
|
||||||
var positionAfterMove = Coordinates.of(5, 4);
|
|
||||||
assertNotEquals(rover.getCurrentCoordinates(), positionAfterMove);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Coordinates> getObstacles() {
|
protected List<Coordinates> getObstacles() {
|
||||||
return List.of(
|
return List.of(
|
||||||
Coordinates.of(3, 3),
|
Coordinates.of(3, 3),
|
||||||
Coordinates.of(5, 5),
|
Coordinates.of(5, 5)
|
||||||
Coordinates.of(7, 7),
|
|
||||||
Coordinates.of(9, 9),
|
|
||||||
Coordinates.of(10, 10)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue