def test_clear_rows(): grid = Grid() grid.current_block = BlockO(-1, 0) [grid.fall_block() for _ in range(rows + 1)] grid.current_block = BlockO(1, 0) [grid.fall_block() for _ in range(rows + 1)] grid.current_block = BlockO(3, 0) [grid.fall_block() for _ in range(rows + 1)] grid.current_block = BlockO(5, 0) [grid.fall_block() for _ in range(rows + 1)] grid.current_block = BlockL(4, 0) handle_key_space(grid) grid.current_block = BlockO(7, 0) [grid.fall_block() for _ in range(rows + 1)] assert grid.locks != {} assert grid.check_rows() == 2 assert grid.locks.keys() == { (4, rows - 1), (5, rows - 1), (6, rows - 1), (6, rows - 2), }
def test_key_left(): grid = Grid() grid.current_block = BlockO(0, 0) grid.fall_block() handle_key_left(grid) handle_key_left(grid) assert grid.current_block.col == -1
def test_key_space(): grid = Grid() grid.current_block = BlockO(3, -4) handle_key_space(grid) assert grid.colors[rows - 3][4] == Color.BLACK assert grid.colors[rows - 3][5] == Color.BLACK assert grid.colors[rows - 2][4] == BlockO.color assert grid.colors[rows - 2][5] == BlockO.color assert grid.colors[rows - 1][4] == BlockO.color assert grid.colors[rows - 1][5] == BlockO.color
def test_hit_bottom(): grid = Grid() grid.current_block = BlockO(3, -4) [grid.fall_block() for _ in range(rows + 2)] assert grid.colors[rows - 1][4] == BlockO.color assert grid.colors[rows - 1][5] == BlockO.color assert grid.colors[rows - 2][4] == BlockO.color assert grid.colors[rows - 2][5] == BlockO.color assert grid.locks[(4, rows - 1)] assert grid.locks[(5, rows - 1)]
def test_key_up(): grid = Grid() grid.current_block = BlockO(3, -3) grid.fall_block() grid.fall_block() handle_key_up(grid) grid.update_colors() assert grid.colors[0][4] == BlockO.color assert grid.colors[0][5] == BlockO.color assert grid.colors[1][4] == BlockO.color assert grid.colors[1][5] == BlockO.color
def test_fall(): grid = Grid() grid.current_block = BlockO(3, -3) grid.fall_block() assert grid.colors[0][4] == BlockO.color assert grid.colors[0][5] == BlockO.color grid.fall_block() grid.fall_block() assert grid.colors[0][4] == Color.BLACK assert grid.colors[0][5] == Color.BLACK assert grid.colors[1][4] == BlockO.color assert grid.colors[1][5] == BlockO.color
def test_key_left(): grid = Grid() grid.current_block = BlockO(5, 0) grid.fall_block() grid.fall_block() handle_key_left(grid) grid.update_colors() assert grid.colors[0][5] == Color.BLACK assert grid.colors[1][5] == Color.BLACK assert grid.colors[0][3] == BlockO.color assert grid.colors[0][4] == BlockO.color assert grid.colors[1][3] == BlockO.color assert grid.colors[1][4] == BlockO.color
def test_block_o(): t = BlockO(3, -4) assert [(4, -3), (5, -3), (4, -2), (5, -2)] == t.coordinates assert [(4, -3), (5, -3), (4, -2), (5, -2)] == t.rotate().coordinates