Skip to content

Commit

Permalink
feat(position): implement move
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Apr 16, 2022
1 parent 00032e7 commit 6259920
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/kotlin/movements/Position.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}

}
31 changes: 31 additions & 0 deletions src/test/kotlin/movements/PositionTest.kt
Original file line number Diff line number Diff line change
@@ -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))
}

}

0 comments on commit 6259920

Please sign in to comment.