-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00032e7
commit 6259920
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
|
||
} |