def test_move_shape_down_ends_game_if_not_possible(self): board = game_board.Board() board.start_game() board = _fill_in_board(board) with self.assertRaises(game_board.GameOverError): self.assertFalse(board.let_shape_fall())
def test_drop_shape(self): board = game_board.Board() board.start_game() falling_shape = board.falling_shape board.drop_shape() self.assertNotEqual(falling_shape, board.falling_shape)
def test_new_shape(self): board = game_board.Board() board.start_game() board.new_shape() self.assertIsNotNone(board.falling_shape) self.assertIsNotNone(board.next_shape)
def test_new_shape_cannot_be_placed(self): board = game_board.Board() board.start_game() board = _fill_in_board(board) with self.assertRaises(game_board.GameOverError): board.new_shape() self.assertIsNone(board.falling_shape)
def test_drop_shape_cannot_be_placed(self): board = game_board.Board() board.start_game() board = _fill_in_board(board) falling_shape = board.falling_shape with self.assertRaises(game_board.GameOverError): board.drop_shape() self.assertEqual(falling_shape, board.falling_shape)
def test_remove_completed_lines_one_line(self): board = game_board.Board() # Fill in bottom row of board last_row_index = game_board.NUM_ROWS - 1 for col_index in range(game_board.NUM_COLUMNS): block = pieces.Block(last_row_index, col_index, 3) board.array[last_row_index][col_index] = block board.remove_completed_lines() self.assertEqual(board.score, game_board.POINTS_PER_LINE) self.assertFalse( any([ any(board.array[row_index]) for row_index in range(game_board.NUM_ROWS) ]))
def test_move_shape_down_settles_shape(self): board = game_board.Board() board.start_game() bottom_blocks = board.falling_shape.bottom_blocks lowest_position = max([block.row_position for block in bottom_blocks]) # make sure board is empty self.assertFalse( any([ any(board.array[row_index]) for row_index in range(game_board.NUM_ROWS) ])) # move piece all the way down for _ in range(game_board.NUM_ROWS - lowest_position): board.let_shape_fall() # make sure new blocks exist in board self.assertTrue( any([ any(board.array[row_index]) for row_index in range(game_board.NUM_ROWS) ]))
def test_remove_completed_lines_one_line_with_block_above(self): board = game_board.Board() # Fill in bottom row of board last_row_index = game_board.NUM_ROWS - 1 for col_index in range(game_board.NUM_COLUMNS): block = pieces.Block(last_row_index, col_index, 3) board.array[last_row_index][col_index] = block # put in one extra block block = pieces.Block(last_row_index - 1, col_index, 3) board.array[last_row_index - 1][col_index] = block board.remove_completed_lines() self.assertEqual(board.score, game_board.POINTS_PER_LINE) self.assertTrue( any([ any(board.array[row_index]) for row_index in range(game_board.NUM_ROWS) ])) # this is where that extra block should be after falling self.assertTrue(board.array[last_row_index][col_index])
def test_move_shape_down_moves_shape_down_one_row(self): board = game_board.Board() board.start_game() self.assertTrue(board.let_shape_fall()) self.assertEqual(board.falling_shape.row_position, 1)
def test_rotate_shape_returns_false_if_not_successful(self): board = game_board.Board() board.start_game() board = _fill_in_board(board) self.assertFalse(board.rotate_shape())
def test_rotate_shape_returns_true_if_successful(self): board = game_board.Board() board.start_game() self.assertTrue(board.rotate_shape())