From f27d458b49eea6081877a4ce8d67cafa1104bb21 Mon Sep 17 00:00:00 2001 From: Xavier Fontanet Date: Thu, 20 Jun 2024 16:43:38 +0200 Subject: [PATCH] Rover moved forward but coordinates doesn't match with the expected --- .../codingtests/marsrover/Coordinates.java | 34 +++++++++++++++++++ .../codingtests/marsrover/MarsRover.java | 4 +-- .../codingtests/marsrover/MarsRoverTest.java | 4 ++- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java diff --git a/src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java b/src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java new file mode 100644 index 0000000..39b5348 --- /dev/null +++ b/src/main/java/cat/hack3/codingtests/marsrover/Coordinates.java @@ -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 + + '}'; + } +} diff --git a/src/main/java/cat/hack3/codingtests/marsrover/MarsRover.java b/src/main/java/cat/hack3/codingtests/marsrover/MarsRover.java index b025825..896924f 100644 --- a/src/main/java/cat/hack3/codingtests/marsrover/MarsRover.java +++ b/src/main/java/cat/hack3/codingtests/marsrover/MarsRover.java @@ -11,7 +11,7 @@ public class MarsRover { this.longitudeStartingPoint = longitudeStartingPoint; } - public void moveForward() { - + public Coordinates moveForward() { + return Coordinates.of(0, 0); } } diff --git a/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java b/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java index 8dbac60..58aed53 100644 --- a/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java +++ b/src/test/java/cat/hack3/codingtests/marsrover/MarsRoverTest.java @@ -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)); } }