diff --git a/src/main/kotlin/Rover.kt b/src/main/kotlin/Rover.kt index 15fc851..dfcae97 100644 --- a/src/main/kotlin/Rover.kt +++ b/src/main/kotlin/Rover.kt @@ -13,9 +13,9 @@ class Rover { fun go(cms: String) { for (c in cms) { when (c) { - 'L' -> { when (rs.dd) { 'E' -> rs.dd = 'N' 'N' -> rs.dd = 'W' 'W' -> rs.dd = 'S' 'S' -> rs.dd = 'E'}} - 'R' -> { when (rs.dd) { 'E' -> rs.dd = 'S' 'S' -> rs.dd = 'W' 'W' -> rs.dd = 'N' 'N' -> rs.dd = 'E'}} - 'M' -> { when (rs.dd) { 'E' -> rs.xx++ 'S' -> rs.yy-- 'W' -> rs.xx-- 'N' -> rs.yy++}} + 'L' -> { when (rs.dd) { 'E' -> rs.dd = 'N' 'N' -> rs.dd = 'W' 'W' -> rs.dd = 'S' 'S' -> rs.dd = 'E' } } + 'R' -> { when (rs.dd) { 'E' -> rs.dd = 'S' 'S' -> rs.dd = 'W' 'W' -> rs.dd = 'N' 'N' -> rs.dd = 'E' } } + 'M' -> { when (rs.dd) { 'E' -> rs.xx++ 'S' -> rs.yy-- 'W' -> rs.xx-- 'N' -> rs.yy++ } } } } } diff --git a/src/test/kotlin/MarsRoverTests.kt b/src/test/kotlin/MarsRoverTests.kt index 811074f..572aab9 100644 --- a/src/test/kotlin/MarsRoverTests.kt +++ b/src/test/kotlin/MarsRoverTests.kt @@ -20,11 +20,11 @@ class MarsRoverTests { "1 2 S, M, 1 1 S", "1 2 W, M, 0 2 W", "1 2 N, LMLMLMLMM, 1 3 N", - "3 3 E, MMRMMRMRRM, 5 1 E" + "3 3 E, MMRMMRMRRM, 5 1 E", ) fun `execute commands`(startingPosition: String, instructions: String, expectedOutput: String) { val rover = Rover(startingPosition) rover.go(instructions) assertEquals(expectedOutput, rover.pos()) } -} \ No newline at end of file +}