Skip to content

Commit

Permalink
feat(jblock): implement simple movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Apr 16, 2022
1 parent c2635cc commit a7916a9
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/JBlock.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 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))

Expand All @@ -18,7 +18,7 @@ class JBlock(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/JBlock/JBlockMoveTest.kt
Original file line number Diff line number Diff line change
@@ -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()
)
}

}

0 comments on commit a7916a9

Please sign in to comment.