Skip to content

Commit

Permalink
feat(lblock): implement simple movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Apr 16, 2022
1 parent 3897c44 commit b5c7ea9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/blocks/implementation/LBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -18,7 +18,7 @@ class LBlock(private val initialPosition: Position): Block {
}

override fun move(direction: Direction) {
TODO("Not yet implemented")
initialPosition = initialPosition.move(direction)
}

}
77 changes: 77 additions & 0 deletions src/test/kotlin/blocks/LBlock/LBlockMoveTest.kt
Original file line number Diff line number Diff line change
@@ -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()
)
}
}

0 comments on commit b5c7ea9

Please sign in to comment.