diff --git a/TECHDEBT.md b/TECHDEBT.md index 2693455..4cecd3f 100644 --- a/TECHDEBT.md +++ b/TECHDEBT.md @@ -1,5 +1,7 @@ # TODO -- [ ] Make ktlint pass checks # RPP -- [ ] ... \ No newline at end of file +- [ ] ... + +# DONE +- [x] Make ktlint pass checks diff --git a/src/main/kotlin/Rover.kt b/src/main/kotlin/Rover.kt deleted file mode 100644 index 15fc851..0000000 --- a/src/main/kotlin/Rover.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.example - -class Rover { - constructor(p: String) { - val s = p.split(' ') - if (s.size >= 3) { - rs.xx = s[0].toInt() - rs.yy = s[1].toInt() - rs.dd = s[2][0] - } - } - - 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++}} - } - } - } - - fun g(z: Char) { - go(z.toString()) - } - - val xyd: String - get() = "${rs.xx} ${rs.yy} ${rs.dd}" - - fun pos(): String { - return xyd - } - - constructor() : this("") - - private var rs = RoverState() -} - -class RoverState { - var xx: Int = 0 - var yy: Int = 0 - var dd: Char = 'N' -} diff --git a/src/main/kotlin/org/example/Rover.kt b/src/main/kotlin/org/example/Rover.kt new file mode 100644 index 0000000..281be94 --- /dev/null +++ b/src/main/kotlin/org/example/Rover.kt @@ -0,0 +1,64 @@ +package org.example + +class Rover { + constructor(p: String) { + val s = p.split(' ') + if (s.size >= 3) { + rs.xx = s[0].toInt() + rs.yy = s[1].toInt() + rs.dd = s[2][0] + } + } + + 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++ + } + } + } + } + } + + fun g(z: Char) { + go(z.toString()) + } + + val xyd: String + get() = "${rs.xx} ${rs.yy} ${rs.dd}" + + fun pos(): String { + return xyd + } + + constructor() : this("") + + private var rs = RoverState() +} + +class RoverState { + var xx: Int = 0 + var yy: Int = 0 + var dd: Char = 'N' +} diff --git a/src/test/kotlin/MarsRoverTests.kt b/src/test/kotlin/org/example/MarsRoverTests.kt similarity index 79% rename from src/test/kotlin/MarsRoverTests.kt rename to src/test/kotlin/org/example/MarsRoverTests.kt index 811074f..e19d043 100644 --- a/src/test/kotlin/MarsRoverTests.kt +++ b/src/test/kotlin/org/example/MarsRoverTests.kt @@ -1,4 +1,5 @@ -import org.example.Rover +package org.example + import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.CsvSource @@ -20,11 +21,15 @@ 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) { + 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 +}