Rover moved forward but coordinates doesn't match with the expected
This commit is contained in:
parent
6afb4b522b
commit
f27d458b49
|
@ -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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ public class MarsRover {
|
||||||
this.longitudeStartingPoint = longitudeStartingPoint;
|
this.longitudeStartingPoint = longitudeStartingPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveForward() {
|
public Coordinates moveForward() {
|
||||||
|
return Coordinates.of(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static cat.hack3.codingtests.marsrover.MarsMap.Direction.SOUTH;
|
import static cat.hack3.codingtests.marsrover.MarsMap.Direction.SOUTH;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
public class MarsRoverTest {
|
public class MarsRoverTest {
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ public class MarsRoverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void roverMakeItsFirstStep() {
|
public void roverMakeItsFirstStep() {
|
||||||
rover.moveForward();
|
Coordinates currentPosition = rover.moveForward();
|
||||||
|
assertEquals(currentPosition, Coordinates.of(3, 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue