diff --git a/src/main/kotlin/movements/Position.kt b/src/main/kotlin/movements/Position.kt index b410024..1654ddd 100644 --- a/src/main/kotlin/movements/Position.kt +++ b/src/main/kotlin/movements/Position.kt @@ -1,3 +1,13 @@ package movements -data class Position(val row: Int, val column: Int) +data class Position(val row: Int, val column: Int) { + + fun move(direction: Direction): Position { + return when(direction) { + Direction.DOWN -> Position(row, column + 1) + Direction.LEFT -> Position(row - 1, column) + Direction.RIGHT -> Position(row + 1, column) + } + } + +} diff --git a/src/test/kotlin/movements/PositionTest.kt b/src/test/kotlin/movements/PositionTest.kt new file mode 100644 index 0000000..a93ce0e --- /dev/null +++ b/src/test/kotlin/movements/PositionTest.kt @@ -0,0 +1,31 @@ +package movements + +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class PositionTest { + + lateinit var position: Position + + @BeforeEach + fun setUp() { + position = Position(1,1) + } + + @Test + fun `Apply DOWN direction`(){ + assertEquals(Position(1,2), position.move(Direction.DOWN)) + } + + @Test + fun `Apply LEFT direction`(){ + assertEquals(Position(0,1), position.move(Direction.LEFT)) + } + + @Test + fun `Apply RIGHT direction`(){ + assertEquals(Position(2,1), position.move(Direction.RIGHT)) + } + +} \ No newline at end of file