1
0
Fork 0

Rover moved forward but coordinates doesn't match with the expected

This commit is contained in:
Xavier Fontanet 2024-06-20 16:43:38 +02:00
parent 6afb4b522b
commit f27d458b49
3 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,34 @@
package cat.hack3.codingtests.marsrover;
public class Coordinates {
private final int latitude;
private final int longitude;
public static Coordinates of(int latitude, int longitude) {
return new Coordinates(latitude, longitude);
}
public Coordinates(int latitude, int longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Coordinates that = (Coordinates) o;
if (latitude != that.latitude) return false;
return longitude == that.longitude;
}
@Override
public String toString() {
return "Coordinates{" +
"latitude=" + latitude +
", longitude=" + longitude +
'}';
}
}

View File

@ -11,7 +11,7 @@ public class MarsRover {
this.longitudeStartingPoint = longitudeStartingPoint;
}
public void moveForward() {
public Coordinates moveForward() {
return Coordinates.of(0, 0);
}
}

View File

@ -4,6 +4,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static cat.hack3.codingtests.marsrover.MarsMap.Direction.SOUTH;
import static org.testng.Assert.assertEquals;
public class MarsRoverTest {
@ -23,6 +24,7 @@ public class MarsRoverTest {
@Test
public void roverMakeItsFirstStep() {
rover.moveForward();
Coordinates currentPosition = rover.moveForward();
assertEquals(currentPosition, Coordinates.of(3, 3));
}
}