Skip to content

Commit

Permalink
feat(position): implement addAxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Apr 16, 2022
1 parent 64ddeee commit cf143ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/movements/Position.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package movements
data class Position(val row: Int, val column: Int) {

fun move(direction: Direction): Position {
return when(direction) {
return when (direction) {
Direction.DOWN -> Position(row + 1, column)
Direction.LEFT -> Position(row, column - 1)
Direction.RIGHT -> Position(row , column + 1)
Direction.RIGHT -> Position(row, column + 1)
}
}

fun addAxes(other: Position): Position = Position(row + other.row, column + other.column)

}
24 changes: 24 additions & 0 deletions src/test/kotlin/movements/PositionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,28 @@ class PositionTest {
assertEquals(Position(1,2), position.move(Direction.RIGHT))
}

@Test
fun `Add axes with (0, 0) position`(){
val other = Position(0, 0)
assertEquals(Position(1, 1), position.addAxes(other))
}

@Test
fun `Add axes with negative row position`(){
val other = Position(-1, 0)
assertEquals(Position(0, 1), position.addAxes(other))
}

@Test
fun `Add axes with negative column position`(){
val other = Position(0, -1)
assertEquals(Position(1, 0), position.addAxes(other))
}

@Test
fun `Simple positive add`(){
val other = Position(1, 1)
assertEquals(Position(2, 2), position.addAxes(other))
}

}

0 comments on commit cf143ed

Please sign in to comment.