def test_piece_move(straight_piece: BoardPiece):
    old_blocks = straight_piece.blocks
    old_center = straight_piece.center
    straight_piece.move(1, 2)
    for old in old_blocks:
        assert old + BoardBlock(1, 2) in straight_piece.blocks
    assert straight_piece.center == old_center + BoardBlock(1, 2)
def test_drop_after_row_completed_3(board, line_shape):
    """
    |---   |          |      |
    |------|    --->  |      |
    |------|          |---   |
    |---   |          |---   |
    """
    board.spawn_position = BoardBlock(0, 0)

    board.spawn_piece(Straight)
    board.full_drop()
    board.spawn_piece(line_shape)
    board.full_drop()
    board.spawn_piece(line_shape)
    board.full_drop()
    board.spawn_piece(Straight)
    board.full_drop()

    assert board.any_rows_completed()
    assert board.clear_completed_rows() == 2
    # check that pieces above the cleared line has dropped
    assert (board.height - 1) in map(lambda block: block[1],
                                     board.get_blocks())
    assert (board.height - 2) in map(lambda block: block[1],
                                     board.get_blocks())
def test_rows_completed(board, line_shape):
    board.spawn_position = BoardBlock(0, 0)

    board.spawn_piece(line_shape)
    board.full_drop()
    assert board.any_rows_completed()
    assert board.clear_completed_rows() == 1
    assert not board.any_rows_completed()
    assert board.clear_completed_rows() == 0

    board.spawn_piece(line_shape)
    board.full_drop()
    board.spawn_piece(line_shape)
    board.full_drop()
    assert board.any_rows_completed()
    assert board.clear_completed_rows() == 2
def test_block_add(block):
    b = block + BoardBlock(1, 2)
    assert (b.x, b.y) == (1, 2)
    b += BoardBlock(-1, 2)
    assert (b.x, b.y) == (0, 4)
def straight_piece() -> BoardPiece:
    blocks = [BoardBlock(x, 0) for x in range(4)]
    center = BoardBlock(Straight.center[0], Straight.center[1])
    return BoardPiece(Straight(), blocks, center)
def block():
    return BoardBlock(0, 0)
def test_piece_init(straight_piece: BoardPiece):
    assert straight_piece.center == BoardBlock(Straight.center[0],
                                               Straight.center[1])
    assert straight_piece.blocks == [BoardBlock(x, 0) for x in range(4)]
    assert straight_piece.id == Straight().id