From a7916a933684e85eff2ad4e9f679bd19fbb00085 Mon Sep 17 00:00:00 2001 From: Pablo Fraile Alonso Date: Mon, 7 Mar 2022 18:07:21 +0100 Subject: [PATCH] feat(jblock): implement simple movement --- .../kotlin/blocks/implementation/JBlock.kt | 4 +- .../kotlin/blocks/JBlock/JBlockMoveTest.kt | 77 +++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/test/kotlin/blocks/JBlock/JBlockMoveTest.kt diff --git a/src/main/kotlin/blocks/implementation/JBlock.kt b/src/main/kotlin/blocks/implementation/JBlock.kt index d26aeaf..3954337 100644 --- a/src/main/kotlin/blocks/implementation/JBlock.kt +++ b/src/main/kotlin/blocks/implementation/JBlock.kt @@ -5,7 +5,7 @@ import blocks.Rotation import movements.Direction import movements.Position -class JBlock(private val initialPosition: Position) : Block { +class JBlock(private var initialPosition: Position) : Block { private val initialState = listOf(Position(0, 0), Position(1, 0), Position(1, 1), Position(1, 2)) @@ -18,7 +18,7 @@ class JBlock(private val initialPosition: Position) : Block { } override fun move(direction: Direction) { - TODO("Not yet implemented") + initialPosition = initialPosition.move(direction) } } diff --git a/src/test/kotlin/blocks/JBlock/JBlockMoveTest.kt b/src/test/kotlin/blocks/JBlock/JBlockMoveTest.kt new file mode 100644 index 0000000..fcb8f34 --- /dev/null +++ b/src/test/kotlin/blocks/JBlock/JBlockMoveTest.kt @@ -0,0 +1,77 @@ +package blocks.JBlock + +import blocks.MoveTest +import blocks.implementation.JBlock +import movements.Direction +import movements.Position +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class JBlockMoveTest : MoveTest { + + private lateinit var jBlock: JBlock + + @BeforeEach + fun setUp() { + jBlock = JBlock(Position(2, 2)) + } + + @Test + override fun `Move to Right changes column plus one`() { + jBlock.move(Direction.RIGHT) + assertEquals( + listOf(Position(2, 3), Position(3, 3), Position(3, 4), Position(3, 5)), + jBlock.getNeededPositions() + ) + } + + @Test + override fun `Double move to Right changes column plus two`() { + jBlock.move(Direction.RIGHT) + jBlock.move(Direction.RIGHT) + assertEquals( + listOf(Position(2, 4), Position(3, 4), Position(3, 5), Position(3, 6)), + jBlock.getNeededPositions() + ) + } + + @Test + override fun `Move to Left changes column minus one`() { + jBlock.move(Direction.LEFT) + assertEquals( + listOf(Position(2, 1), Position(3, 1), Position(3, 2), Position(3, 3)), + jBlock.getNeededPositions() + ) + } + + @Test + override fun `Double move to Left changes column minus two`() { + jBlock.move(Direction.LEFT) + jBlock.move(Direction.LEFT) + assertEquals( + listOf(Position(2, 0), Position(3, 0), Position(3, 1), Position(3, 2)), + jBlock.getNeededPositions() + ) + } + + @Test + override fun `Move down changes row plus one`() { + jBlock.move(Direction.DOWN) + assertEquals( + listOf(Position(3, 2), Position(4, 2), Position(4, 3), Position(4, 4)), + jBlock.getNeededPositions() + ) + } + + @Test + override fun `Double move Down changes row plus two`() { + jBlock.move(Direction.DOWN) + jBlock.move(Direction.DOWN) + assertEquals( + listOf(Position(4, 2), Position(5, 2), Position(5, 3), Position(5, 4)), + jBlock.getNeededPositions() + ) + } + +} \ No newline at end of file