diff --git a/src/main/kotlin/blocks/implementation/LBlock.kt b/src/main/kotlin/blocks/implementation/LBlock.kt index 39fc4fd..c793de2 100644 --- a/src/main/kotlin/blocks/implementation/LBlock.kt +++ b/src/main/kotlin/blocks/implementation/LBlock.kt @@ -5,7 +5,7 @@ import blocks.Rotation import movements.Direction import movements.Position -class LBlock(private val initialPosition: Position): Block { +class LBlock(private var initialPosition: Position): Block { val positions = listOf(Position(0, 0), Position(1, 0), Position(2, 0), Position(2,1)) @@ -18,7 +18,7 @@ class LBlock(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/LBlock/LBlockMoveTest.kt b/src/test/kotlin/blocks/LBlock/LBlockMoveTest.kt new file mode 100644 index 0000000..e969e99 --- /dev/null +++ b/src/test/kotlin/blocks/LBlock/LBlockMoveTest.kt @@ -0,0 +1,77 @@ +package blocks.LBlock + +import blocks.Block +import blocks.MoveTest +import blocks.implementation.LBlock +import movements.Direction +import movements.Position +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class LBlockMoveTest : MoveTest { + + private lateinit var lBlock: Block + + @BeforeEach + fun setUp() { + lBlock = LBlock(Position(2, 2)) + } + + @Test + override fun `Move to Right changes column plus one`() { + lBlock.move(Direction.RIGHT) + assertEquals( + listOf(Position(2, 3), Position(3, 3), Position(4, 3), Position(4, 4)), + lBlock.getNeededPositions() + ) + } + + @Test + override fun `Double move to Right changes column plus two`() { + lBlock.move(Direction.RIGHT) + lBlock.move(Direction.RIGHT) + assertEquals( + listOf(Position(2, 4), Position(3, 4), Position(4, 4), Position(4, 5)), + lBlock.getNeededPositions() + ) + } + + @Test + override fun `Move to Left changes column minus one`() { + lBlock.move(Direction.LEFT) + assertEquals( + listOf(Position(2, 1), Position(3, 1), Position(4, 1), Position(4, 2)), + lBlock.getNeededPositions() + ) + } + + @Test + override fun `Double move to Left changes column minus two`() { + lBlock.move(Direction.LEFT) + lBlock.move(Direction.LEFT) + assertEquals( + listOf(Position(2, 0), Position(3, 0), Position(4, 0), Position(4, 1)), + lBlock.getNeededPositions() + ) + } + + @Test + override fun `Move down changes row plus one`() { + lBlock.move(Direction.DOWN) + assertEquals( + listOf(Position(3, 2), Position(4, 2), Position(5, 2), Position(5, 3)), + lBlock.getNeededPositions() + ) + } + + @Test + override fun `Double move Down changes row plus two`() { + lBlock.move(Direction.DOWN) + lBlock.move(Direction.DOWN) + assertEquals( + listOf(Position(4, 2), Position(5, 2), Position(6, 2), Position(6, 3)), + lBlock.getNeededPositions() + ) + } +} \ No newline at end of file