-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1244be
commit 46b4c93
Showing
3 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package game.exceptions | ||
|
||
class BlockCanMoveDownException(message: String): Throwable(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package game | ||
|
||
import block_factory.BlockCreator | ||
import blocks.implementation.IBlock | ||
import board.Cell | ||
import game.exceptions.BlockCanMoveDownException | ||
import game.exceptions.EmptyCurrentBlockException | ||
import movements.Direction | ||
import movements.Position | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import score.Points | ||
import score.ScoreCalculator | ||
|
||
class GameWriteBlockTest { | ||
|
||
private lateinit var game: Game | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
game = Game(object : BlockCreator { | ||
override fun getBlock() = IBlock(Position(0, (GAME_COLUMNS / 2) - 2)) | ||
}, object : ScoreCalculator { | ||
override fun getScore(cleanedRows: Int) = Points(0) | ||
}) | ||
} | ||
|
||
@Test | ||
fun `non initialized block should not be written`() { | ||
Assertions.assertThrows(EmptyCurrentBlockException::class.java) { | ||
game.writeBlockToBoard() | ||
} | ||
} | ||
|
||
@Test | ||
fun `new block that can move next should not be written`() { | ||
game.getNextBlock() | ||
Assertions.assertThrows(BlockCanMoveDownException::class.java) { | ||
game.writeBlockToBoard() | ||
} | ||
} | ||
|
||
@Test | ||
fun `block that can be written and it writes appears as a new cell`() { | ||
// Create first block, move it down, write it, and then get a new one | ||
game.getNextBlock() | ||
for( i in 1 until GAME_ROWS - 1) | ||
game.moveBlock(Direction.DOWN) | ||
game.writeBlockToBoard() | ||
game.getNextBlock() | ||
// Expected: block saved at the bottom, and a new (current) block at the top | ||
val expectedGrid = MutableList(GAME_ROWS) { MutableList(GAME_COLUMNS) { GameCell(Cell.EMPTY, false) } } | ||
expectedGrid[GAME_ROWS - 1][(GAME_COLUMNS / 2) - 2] = GameCell(Cell.I_BLOCK, false) | ||
expectedGrid[GAME_ROWS - 1][(GAME_COLUMNS / 2) - 1] = GameCell(Cell.I_BLOCK, false) | ||
expectedGrid[GAME_ROWS - 1][(GAME_COLUMNS / 2)] = GameCell(Cell.I_BLOCK, false) | ||
expectedGrid[GAME_ROWS - 1][(GAME_COLUMNS / 2) + 1] = GameCell(Cell.I_BLOCK, false) | ||
expectedGrid[1][(GAME_COLUMNS / 2) - 2] = GameCell(Cell.I_BLOCK, true) | ||
expectedGrid[1][(GAME_COLUMNS / 2) - 1] = GameCell(Cell.I_BLOCK, true) | ||
expectedGrid[1][(GAME_COLUMNS / 2)] = GameCell(Cell.I_BLOCK, true) | ||
expectedGrid[1][(GAME_COLUMNS / 2) + 1] = GameCell(Cell.I_BLOCK, true) | ||
assertEquals(expectedGrid, game.getGrid()) | ||
} | ||
|
||
} |