From 5d80824d6a586f84c46b4e7660fbc572b1fc5afd Mon Sep 17 00:00:00 2001 From: Pablo Fraile Alonso Date: Wed, 2 Mar 2022 16:54:34 +0100 Subject: [PATCH] feat(tblock): implement initial position --- .../kotlin/blocks/implementation/TBlock.kt | 24 +++++++++++++ src/test/kotlin/blocks/TBlock/TBlockTest.kt | 36 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/kotlin/blocks/implementation/TBlock.kt create mode 100644 src/test/kotlin/blocks/TBlock/TBlockTest.kt diff --git a/src/main/kotlin/blocks/implementation/TBlock.kt b/src/main/kotlin/blocks/implementation/TBlock.kt new file mode 100644 index 0000000..81a0e64 --- /dev/null +++ b/src/main/kotlin/blocks/implementation/TBlock.kt @@ -0,0 +1,24 @@ +package blocks.implementation + +import blocks.Block +import blocks.Rotation +import movements.Direction +import movements.Position + +class TBlock(private val initialPosition: Position): Block { + + val positions = listOf(Position(0, 1), Position(1, 0), Position(1,1), Position(1, 2)) + + override fun getNeededPositions(): Collection { + return positions.map({pos -> pos.addAxes(initialPosition)}) + } + + override fun rotate(degree: Rotation) { + TODO("Not yet implemented") + } + + override fun move(direction: Direction) { + TODO("Not yet implemented") + } + +} diff --git a/src/test/kotlin/blocks/TBlock/TBlockTest.kt b/src/test/kotlin/blocks/TBlock/TBlockTest.kt new file mode 100644 index 0000000..975f752 --- /dev/null +++ b/src/test/kotlin/blocks/TBlock/TBlockTest.kt @@ -0,0 +1,36 @@ +package blocks.TBlock + +import blocks.implementation.TBlock +import movements.Position +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class TBlockTest { + + @Test + fun `position 0,0 needed positions are (0,0), (1,0), (1,1), (1,2)`() { + val tBlock = TBlock(Position(0, 0)) + assertEquals( + listOf(Position(0, 1), Position(1, 0), Position(1, 1), Position(1, 2)), + tBlock.getNeededPositions() + ) + } + + @Test + fun `position 0,1 needed positions are (0,2), (1, 1), (1,2), (1,3)`() { + val tBlock = TBlock(Position(0, 1)) + assertEquals( + listOf(Position(0, 2), Position(1, 1), Position(1, 2), Position(1, 3)), + tBlock.getNeededPositions() + ) + } + + @Test + fun `position 1,0 needed positions are (1, 1), (2,0), (2,1), (2,2)`() { + val tBlock = TBlock(Position(1, 0)) + assertEquals( + listOf(Position(1, 1), Position(2, 0), Position(2, 1), Position(2, 2)), + tBlock.getNeededPositions() + ) + } +} \ No newline at end of file