obstacles feature works fine
This commit is contained in:
parent
afe21ad223
commit
ca409a9eee
|
@ -26,13 +26,11 @@ public class ClientCommandInterface {
|
||||||
private void start() {
|
private void start() {
|
||||||
output(PresentationMessage.INTRO);
|
output(PresentationMessage.INTRO);
|
||||||
|
|
||||||
//MarsRover rover = roverInitializer.autoInitialize();
|
MarsRover rover = roverInitializer.autoInitialize();
|
||||||
MarsRover rover = roverInitializer.initializeFromUserInputs();
|
//MarsRover rover = roverInitializer.initializeFromUserInputs();
|
||||||
|
|
||||||
var commandsPerformer = new RoverCommandsPerformer(reader, rover);
|
var commandsPerformer = new RoverCommandsPerformer(reader, rover);
|
||||||
commandsPerformer.acceptCommandsUntilExitSignal();
|
commandsPerformer.acceptCommandsUntilExitSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import cat.hack3.codingtests.marsrover.MarsMap;
|
||||||
import cat.hack3.codingtests.marsrover.MarsRover;
|
import cat.hack3.codingtests.marsrover.MarsRover;
|
||||||
|
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import static cat.hack3.codingtests.marsrover.ui.UICommons.output;
|
import static cat.hack3.codingtests.marsrover.ui.UICommons.output;
|
||||||
|
@ -53,12 +54,19 @@ public class RoverInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
MarsRover autoInitialize() { //to test more quickly
|
MarsRover autoInitialize() { //to test more quickly
|
||||||
return deployRover(10, 10, 2, 3, Direction.SOUTH);
|
List<Coordinates> obstacles = List.of(
|
||||||
|
Coordinates.of(3, 3),
|
||||||
|
Coordinates.of(5, 5),
|
||||||
|
Coordinates.of(7, 7),
|
||||||
|
Coordinates.of(9, 9),
|
||||||
|
Coordinates.of(10, 10)
|
||||||
|
);
|
||||||
|
return deployRover(10, 10, 2, 3, Direction.SOUTH, obstacles);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MarsRover deployRover(int mapHeight, int mapWidth, int latitudeStartingPoint, int longitudeStartingPoint, Direction startingDirection) {
|
private MarsRover deployRover(int mapHeight, int mapWidth, int latitudeStartingPoint, int longitudeStartingPoint, Direction startingDirection, List<Coordinates>... obstaclesLocalizations) {
|
||||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||||
var marsMap = new MarsMap(mapHeight, mapWidth, startingCoordinates);
|
var marsMap = new MarsMap(mapHeight, mapWidth, startingCoordinates, obstaclesLocalizations);
|
||||||
return new MarsRover(marsMap, startingDirection);
|
return new MarsRover(marsMap, startingDirection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
|
|
||||||
import static cat.hack3.codingtests.marsrover.Direction.SOUTH;
|
import static cat.hack3.codingtests.marsrover.Direction.SOUTH;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotEquals;
|
||||||
|
|
||||||
public class MarsRoverWithObstaclesTest {
|
public class MarsRoverWithObstaclesTest {
|
||||||
|
|
||||||
|
@ -33,10 +34,30 @@ public class MarsRoverWithObstaclesTest {
|
||||||
@Test
|
@Test
|
||||||
public void findAnObstacleAtFirstMove() {
|
public void findAnObstacleAtFirstMove() {
|
||||||
Coordinates originalCoordinates = rover.getCurrentCoordinates();
|
Coordinates originalCoordinates = rover.getCurrentCoordinates();
|
||||||
|
Direction originalDirection = rover.getCurrentDirection();
|
||||||
|
|
||||||
rover.moveForward();
|
rover.moveForward();
|
||||||
|
|
||||||
assertEquals(rover.getCurrentCoordinates(), originalCoordinates);
|
assertEquals(rover.getCurrentCoordinates(), originalCoordinates);
|
||||||
|
assertEquals(rover.getCurrentDirection(), originalDirection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void afterFindingObstacleWalkAroundUntilFindingNext() {
|
||||||
|
Coordinates oneStepForward = rover.moveForward();
|
||||||
|
assertNotEquals(oneStepForward, Coordinates.of(3, 3));
|
||||||
|
|
||||||
|
rover.turnLeft();
|
||||||
|
rover.moveForward();
|
||||||
|
rover.moveForward();
|
||||||
|
rover.turnRight();
|
||||||
|
rover.moveForward();
|
||||||
|
rover.moveForward();
|
||||||
|
var currentPosition = Coordinates.of(4, 5);
|
||||||
|
assertEquals(rover.getCurrentCoordinates(), currentPosition);
|
||||||
|
rover.moveForward();
|
||||||
|
var positionAfterMove = Coordinates.of(5, 4);
|
||||||
|
assertNotEquals(rover.getCurrentCoordinates(), positionAfterMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue