applied JPMS. UTs working (in a self module). Big Refactor needed... (sorry for that big commit)
This commit is contained in:
parent
57bf2d3999
commit
877d534716
|
@ -11,6 +11,13 @@
|
|||
|
||||
<artifactId>mars-station</artifactId>
|
||||
<version>2.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>rover-api</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.MarsMap;
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMap;
|
||||
|
||||
public class MarsRover implements RotableRiderRover {
|
||||
|
||||
private final MarsMap marsMap;
|
||||
private final PlanetMap marsMap;
|
||||
private final RoverActionReporter roverActionReporter;
|
||||
private Direction currentDirection;
|
||||
|
||||
public MarsRover(MarsMap marsMap, Direction startingDirection) {
|
||||
public MarsRover(PlanetMap marsMap, Direction startingDirection) {
|
||||
this.marsMap = marsMap;
|
||||
currentDirection = startingDirection;
|
||||
roverActionReporter = new RoverActionReporter();
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.api.RoverDeployer;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMap;
|
||||
|
||||
public class MarsRoverDeployer implements RoverDeployer {
|
||||
@Override
|
||||
public RotableRiderRover deploy(PlanetMap map, Direction startingDirection) {
|
||||
return new MarsRover(map, startingDirection);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.RotableRiderRover.Rotation;
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover.Rotation;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cat.hack3.codingtests.marsrover.cartography;
|
||||
package cat.hack3.codingtests.marsrover.gps;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates.Latitude;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates.Longitude;
|
|
@ -1,7 +1,10 @@
|
|||
package cat.hack3.codingtests.marsrover.cartography;
|
||||
package cat.hack3.codingtests.marsrover.gps;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates.Latitude;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates.Longitude;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -14,7 +17,7 @@ import java.util.List;
|
|||
* 2 2-1 2-2 2-3
|
||||
* 3 3-1 3-2 3-3
|
||||
*/
|
||||
public class MarsMap {
|
||||
public class MarsMap implements PlanetMap {
|
||||
|
||||
private static final int FIRST_POSITION_IN_MAP = 1;
|
||||
private static final int INCREMENT_UNIT = 1;
|
||||
|
@ -31,6 +34,7 @@ public class MarsMap {
|
|||
positionResolver = new MapIncrementalPositionResolver(FIRST_POSITION_IN_MAP, INCREMENT_UNIT, height, width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coordinates getNextPositionTowards(Direction direction) {
|
||||
return switch (direction) {
|
||||
case NORTH -> getDecrementLatitude();
|
||||
|
@ -64,14 +68,17 @@ public class MarsMap {
|
|||
return currentPosition.withUpdated(Longitude.of(newLongitude));
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void updateLocation(Coordinates newPosition) {
|
||||
currentPosition = newPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willCollideWithObstacle(Coordinates newCoordinates) {
|
||||
return obstaclesLocalizations.contains(newCoordinates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coordinates getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package cat.hack3.codingtests.marsrover.gps;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMap;
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMapInitializer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MarsMapInitializer implements PlanetMapInitializer {
|
||||
@Override
|
||||
public PlanetMap setupNewMap(int height, int width, Coordinates startingCoordinates, List<Coordinates> obstaclesLocalizations) {
|
||||
return new MarsMap(height, width, startingCoordinates, obstaclesLocalizations);
|
||||
}
|
||||
@Override
|
||||
public PlanetMap setupNewMap(int height, int width, Coordinates startingCoordinates) {
|
||||
return new MarsMap(height, width, startingCoordinates);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
module mars.station {
|
||||
requires rover.api;
|
||||
requires java.logging;
|
||||
|
||||
provides cat.hack3.codingtests.marsrover.cartography.PlanetMapInitializer
|
||||
with cat.hack3.codingtests.marsrover.gps.MarsMapInitializer;
|
||||
|
||||
provides cat.hack3.codingtests.marsrover.api.RoverDeployer
|
||||
with cat.hack3.codingtests.marsrover.MarsRoverDeployer;
|
||||
}
|
3
pom.xml
3
pom.xml
|
@ -13,6 +13,9 @@
|
|||
<module>mars-station</module>
|
||||
<module>user-interface-console</module>
|
||||
<module>rover-commands</module>
|
||||
<module>rover-api</module>
|
||||
<module>station-plugin</module>
|
||||
<module>tests-suite</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mars-rover</artifactId>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<version>10.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>rover-api</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,4 +1,4 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
package cat.hack3.codingtests.marsrover.api;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
|
@ -0,0 +1,8 @@
|
|||
package cat.hack3.codingtests.marsrover.api;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMap;
|
||||
|
||||
public interface RoverDeployer {
|
||||
RotableRiderRover deploy(PlanetMap map, Direction startingDirection);
|
||||
}
|
|
@ -14,8 +14,8 @@ public record Coordinates(Latitude latitude, Longitude longitude) {
|
|||
return Coordinates.of(latitude.pointer, newLongitude.pointer);
|
||||
}
|
||||
|
||||
record Latitude(long pointer) {
|
||||
static Latitude of(long pointer) {
|
||||
public record Latitude(long pointer) {
|
||||
public static Latitude of(long pointer) {
|
||||
return new Latitude(pointer);
|
||||
}
|
||||
@Override
|
||||
|
@ -23,8 +23,8 @@ public record Coordinates(Latitude latitude, Longitude longitude) {
|
|||
return String.valueOf(pointer);
|
||||
}
|
||||
}
|
||||
record Longitude(long pointer) {
|
||||
static Longitude of(long pointer) {
|
||||
public record Longitude(long pointer) {
|
||||
public static Longitude of(long pointer) {
|
||||
return new Longitude(pointer);
|
||||
}
|
||||
@Override
|
|
@ -0,0 +1,11 @@
|
|||
package cat.hack3.codingtests.marsrover.cartography;
|
||||
|
||||
public interface PlanetMap {
|
||||
Coordinates getNextPositionTowards(Direction direction);
|
||||
|
||||
void updateLocation(Coordinates newPosition);
|
||||
|
||||
boolean willCollideWithObstacle(Coordinates newCoordinates);
|
||||
|
||||
Coordinates getCurrentPosition();
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package cat.hack3.codingtests.marsrover.cartography;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PlanetMapInitializer {
|
||||
PlanetMap setupNewMap(int height, int width, Coordinates startingCoordinates, List<Coordinates> obstaclesLocalizations);
|
||||
PlanetMap setupNewMap(int height, int width, Coordinates startingCoordinates);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
module rover.api {
|
||||
exports cat.hack3.codingtests.marsrover.api;
|
||||
exports cat.hack3.codingtests.marsrover.cartography;
|
||||
}
|
|
@ -12,17 +12,17 @@
|
|||
<artifactId>rover-commands</artifactId>
|
||||
<version>2.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>rover-api</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>mars-station</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,13 +0,0 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
class MoveForwardCommand implements RoverCommand {
|
||||
private final RotableRiderRover rover;
|
||||
|
||||
public MoveForwardCommand(RotableRiderRover rover) {
|
||||
this.rover = rover;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
rover.moveTowards(rover.getCurrentDirection());
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.RotableRiderRover.Rotation.LEFT;
|
||||
|
||||
class TurnLeftCommand implements RoverCommand {
|
||||
private final RotableRiderRover rover;
|
||||
|
||||
public TurnLeftCommand(RotableRiderRover rover) {
|
||||
this.rover = rover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
rover.rotateTowards(LEFT);
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.RotableRiderRover.Rotation.RIGHT;
|
||||
|
||||
class TurnRightCommand implements RoverCommand {
|
||||
private final RotableRiderRover rover;
|
||||
|
||||
public TurnRightCommand(RotableRiderRover rover) {
|
||||
this.rover = rover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
rover.rotateTowards(RIGHT);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
package cat.hack3.codingtests.marsrover.commands;
|
||||
|
||||
class MoveBackwardsCommand implements RoverCommand {
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.RoverCommand;
|
||||
|
||||
public class MoveBackwardsCommand implements RoverCommand {
|
||||
private final RotableRiderRover rover;
|
||||
|
||||
public MoveBackwardsCommand(RotableRiderRover rover) {
|
|
@ -0,0 +1,17 @@
|
|||
package cat.hack3.codingtests.marsrover.commands;
|
||||
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.RoverCommand;
|
||||
|
||||
public class MoveForwardCommand implements RoverCommand {
|
||||
private final RotableRiderRover rover;
|
||||
|
||||
public MoveForwardCommand(RotableRiderRover rover) {
|
||||
this.rover = rover;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
rover.moveTowards(rover.getCurrentDirection());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cat.hack3.codingtests.marsrover.commands;
|
||||
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.RoverCommand;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.api.RotableRiderRover.Rotation.LEFT;
|
||||
|
||||
public class TurnLeftCommand implements RoverCommand {
|
||||
private final RotableRiderRover rover;
|
||||
|
||||
public TurnLeftCommand(RotableRiderRover rover) {
|
||||
this.rover = rover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
rover.rotateTowards(LEFT);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cat.hack3.codingtests.marsrover.commands;
|
||||
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.RoverCommand;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.api.RotableRiderRover.Rotation.RIGHT;
|
||||
|
||||
public class TurnRightCommand implements RoverCommand {
|
||||
private final RotableRiderRover rover;
|
||||
|
||||
public TurnRightCommand(RotableRiderRover rover) {
|
||||
this.rover = rover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
rover.rotateTowards(RIGHT);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,11 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
package cat.hack3.codingtests.marsrover.commands.api;
|
||||
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.commands.MoveBackwardsCommand;
|
||||
import cat.hack3.codingtests.marsrover.commands.MoveForwardCommand;
|
||||
import cat.hack3.codingtests.marsrover.commands.TurnLeftCommand;
|
||||
import cat.hack3.codingtests.marsrover.commands.TurnRightCommand;
|
||||
|
||||
public class CommandFactory {
|
||||
private final RotableRiderRover rover;
|
|
@ -1,4 +1,4 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
package cat.hack3.codingtests.marsrover.commands.api;
|
||||
|
||||
public interface RoverCommand {
|
||||
enum Type {MOVE_FORWARD, MOVE_BACKWARDS, TURN_LEFT, TURN_RIGHT}
|
|
@ -0,0 +1,5 @@
|
|||
module rover.commands {
|
||||
requires rover.api;
|
||||
|
||||
exports cat.hack3.codingtests.marsrover.commands.api;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mars-rover</artifactId>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<version>10.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>station-plugin</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>rover-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
package cat.hack3.codingtests.marsrover.plugin.station;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMapInitializer;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class PlanetMapInitializerProvider {
|
||||
public PlanetMapInitializer getNextAvailable() {
|
||||
return ServiceLoader
|
||||
.load(PlanetMapInitializer.class)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cat.hack3.codingtests.marsrover.plugin.station;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RoverDeployer;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class RoverDeployerProvider {
|
||||
public RoverDeployer getNextAvailable() {
|
||||
return ServiceLoader
|
||||
.load(RoverDeployer.class)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
module station.plugin {
|
||||
requires rover.api;
|
||||
|
||||
uses cat.hack3.codingtests.marsrover.cartography.PlanetMapInitializer;
|
||||
uses cat.hack3.codingtests.marsrover.api.RoverDeployer;
|
||||
|
||||
exports cat.hack3.codingtests.marsrover.plugin.station;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mars-rover</artifactId>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<version>10.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>tests-suite</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>rover-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>station-plugin</artifactId>
|
||||
<version>10.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>rover-commands</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cat.hack3.codingtests</groupId>
|
||||
<artifactId>mars-station</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,63 @@
|
|||
package cat.hack3.codingtests.marsrover.test;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.api.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.PlanetMap;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.CommandFactory;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.RoverCommand;
|
||||
import cat.hack3.codingtests.marsrover.plugin.station.PlanetMapInitializerProvider;
|
||||
import cat.hack3.codingtests.marsrover.plugin.station.RoverDeployerProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.cartography.Direction.SOUTH;
|
||||
import static cat.hack3.codingtests.marsrover.commands.api.RoverCommand.Type.*;
|
||||
|
||||
public class CommonTests {
|
||||
|
||||
public static final Direction STARTING_DIRECTION = SOUTH;
|
||||
|
||||
protected RotableRiderRover rover;
|
||||
protected RoverCommand moveForwardCommand;
|
||||
protected RoverCommand moveBackwardsCommand;
|
||||
protected RoverCommand turnLeftCommand;
|
||||
protected RoverCommand turnRightCommand;
|
||||
|
||||
private PlanetMapInitializerProvider gpsProvider;
|
||||
private RoverDeployerProvider roverProvider;
|
||||
|
||||
protected void setup() {
|
||||
gpsProvider = new PlanetMapInitializerProvider();
|
||||
roverProvider = new RoverDeployerProvider();
|
||||
|
||||
int mapWidth = 10;
|
||||
int mapHeight = 10;
|
||||
int latitudeStartingPoint = 2;
|
||||
int longitudeStartingPoint = 3;
|
||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||
|
||||
var marsMap = getMap(mapHeight, mapWidth, startingCoordinates);
|
||||
rover = getRover(marsMap);
|
||||
|
||||
var commandFactory = new CommandFactory(this.rover);
|
||||
moveForwardCommand = commandFactory.createCommand(MOVE_FORWARD);
|
||||
moveBackwardsCommand = commandFactory.createCommand(MOVE_BACKWARDS);
|
||||
turnLeftCommand = commandFactory.createCommand(TURN_LEFT);
|
||||
turnRightCommand = commandFactory.createCommand(TURN_RIGHT);
|
||||
}
|
||||
|
||||
private PlanetMap getMap(int mapHeight, int mapWidth, Coordinates startingCoordinates) {
|
||||
var planetInitializer = gpsProvider.getNextAvailable();
|
||||
return planetInitializer.setupNewMap(mapHeight, mapWidth, startingCoordinates, getObstacles());
|
||||
}
|
||||
|
||||
private RotableRiderRover getRover(PlanetMap marsMap) {
|
||||
var roverDeployer = roverProvider.getNextAvailable();
|
||||
return roverDeployer.deploy(marsMap, CommonTests.STARTING_DIRECTION);
|
||||
}
|
||||
|
||||
protected List<Coordinates> getObstacles() {
|
||||
return List.of();
|
||||
}
|
||||
}
|
|
@ -1,41 +1,20 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
package cat.hack3.codingtests.marsrover.test;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.MarsMap;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.RoverCommand.Type.*;
|
||||
import static cat.hack3.codingtests.marsrover.cartography.Direction.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
public class MarsRoverTest {
|
||||
|
||||
private MarsRover rover;
|
||||
|
||||
private RoverCommand moveForwardCommand;
|
||||
private RoverCommand moveBackwardsCommand;
|
||||
private RoverCommand turnLeftCommand;
|
||||
private RoverCommand turnRightCommand;
|
||||
public class MarsRoverTest extends CommonTests {
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
int mapWidth = 10;
|
||||
int mapHeight = 10;
|
||||
int latitudeStartingPoint = 2;
|
||||
int longitudeStartingPoint = 3;
|
||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||
var marsMap = new MarsMap(mapHeight, mapWidth, startingCoordinates);
|
||||
rover = new MarsRover(marsMap, SOUTH);
|
||||
|
||||
var commandFactory = new CommandFactory(rover);
|
||||
moveForwardCommand = commandFactory.createCommand(MOVE_FORWARD);
|
||||
moveBackwardsCommand = commandFactory.createCommand(MOVE_BACKWARDS);
|
||||
turnLeftCommand = commandFactory.createCommand(TURN_LEFT);
|
||||
turnRightCommand = commandFactory.createCommand(TURN_RIGHT);
|
||||
setup();
|
||||
}
|
||||
|
||||
@Test
|
|
@ -1,47 +1,20 @@
|
|||
package cat.hack3.codingtests.marsrover;
|
||||
package cat.hack3.codingtests.marsrover.test;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.MarsMap;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.RoverCommand.Type.*;
|
||||
import static cat.hack3.codingtests.marsrover.cartography.Direction.SOUTH;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
|
||||
public class MarsRoverWithObstaclesTest {
|
||||
|
||||
private MarsRover rover;
|
||||
|
||||
private RoverCommand moveForwardCommand;
|
||||
private RoverCommand turnLeftCommand;
|
||||
private RoverCommand turnRightCommand;
|
||||
public class MarsRoverWithObstaclesTest extends CommonTests {
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
int mapWidth = 10;
|
||||
int mapHeight = 10;
|
||||
int latitudeStartingPoint = 2;
|
||||
int longitudeStartingPoint = 3;
|
||||
var startingCoordinates = Coordinates.of(latitudeStartingPoint, longitudeStartingPoint);
|
||||
List<Coordinates> obstaclesLocalizations = List.of(
|
||||
Coordinates.of(3, 3),
|
||||
Coordinates.of(5, 5),
|
||||
Coordinates.of(7, 7),
|
||||
Coordinates.of(9, 9),
|
||||
Coordinates.of(10, 10)
|
||||
);
|
||||
var marsMap = new MarsMap(mapHeight, mapWidth, startingCoordinates, obstaclesLocalizations);
|
||||
rover = new MarsRover(marsMap, SOUTH);
|
||||
|
||||
var commandFactory = new CommandFactory(rover);
|
||||
moveForwardCommand = commandFactory.createCommand(MOVE_FORWARD);
|
||||
turnLeftCommand = commandFactory.createCommand(TURN_LEFT);
|
||||
turnRightCommand = commandFactory.createCommand(TURN_RIGHT);
|
||||
super.setup();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -74,4 +47,14 @@ public class MarsRoverWithObstaclesTest {
|
|||
assertNotEquals(rover.getCurrentCoordinates(), positionAfterMove);
|
||||
}
|
||||
|
||||
@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)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
module tests.suite {
|
||||
requires rover.api;
|
||||
requires station.plugin;
|
||||
requires mars.station;
|
||||
requires rover.commands;
|
||||
|
||||
requires org.testng;
|
||||
|
||||
exports cat.hack3.codingtests.marsrover.test;
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package cat.hack3.codingtests.marsrover.ui.console;
|
||||
|
||||
import cat.hack3.codingtests.marsrover.CommandFactory;
|
||||
import cat.hack3.codingtests.marsrover.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.RoverCommand;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.CommandFactory;
|
||||
import cat.hack3.codingtests.marsrover.commands.api.RoverCommand;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import static cat.hack3.codingtests.marsrover.RoverCommand.Type.*;
|
||||
import static cat.hack3.codingtests.marsrover.commands.api.RoverCommand.Type.*;
|
||||
import static cat.hack3.codingtests.marsrover.ui.console.UICommons.isNotExitSignal;
|
||||
import static cat.hack3.codingtests.marsrover.ui.console.UICommons.output;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import cat.hack3.codingtests.marsrover.MarsRover;
|
|||
import cat.hack3.codingtests.marsrover.RotableRiderRover;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Coordinates;
|
||||
import cat.hack3.codingtests.marsrover.cartography.Direction;
|
||||
import cat.hack3.codingtests.marsrover.cartography.MarsMap;
|
||||
import cat.hack3.codingtests.marsrover.gps.MarsMap;
|
||||
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.List;
|
||||
|
|
Loading…
Reference in New Issue