def test_step_rotate_r() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) board = Board(seed=0) board.rotate = MagicMock() tetris.board = board # act tetris.step(constants.ROTATE_R) # assert board.rotate.assert_called_once_with(3)
def test_step_left() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) board = Board(seed=0) board.move_left = MagicMock() tetris.board = board # act tetris.step(constants.LEFT) # assert board.move_left.assert_called_once()
def test_step_down() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) board = Board(seed=0) board.move_down = MagicMock() tetris.board = board # act tetris.step(constants.DOWN) # assert board.move_down.assert_called_once()
def test_close() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) gui: Any = Gui(20, 10) gui.close = MagicMock() tetris.gui = gui # act tetris.close() # assert gui.close.assert_called_once() assert tetris.gui == None
def test_reset() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) tetris.glob_info['Score'] = 128 tetris.glob_info['Lines'] = 6 board = Board(seed=0) board.get_board = MagicMock() board.get_board.return_value = "TEST" tetris.board = board # act result = tetris.reset() # assert assert result == "TEST" assert tetris.glob_info['Score'] == 0 assert tetris.glob_info['Lines'] == 0
def test_render() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) board = Board(seed=0) board.get_board = MagicMock() board.get_board.return_value = "TEST" tetris.board = board gui = Gui(20, 10) gui.render = MagicMock() tetris.gui = gui # act tetris.render() # assert gui.render.assert_called_once()
def test_step_none() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) board = Board(seed=0) board.move_down = MagicMock() tetris.board = board # act tetris.step(constants.NONE) assert tetris.last_down == 1 tetris.step(constants.NONE) assert tetris.last_down == 2 tetris.step(constants.NONE) assert tetris.last_down == 3 tetris.step(constants.NONE) assert tetris.last_down == 4 # assert board.move_down.assert_not_called()
def test_step_get_info() -> None: # arrange tetris: TetrisBase = TetrisBase(seed=0) board = Board(seed=0) board.get_board = MagicMock() board.move_down = MagicMock() board.get_board.return_value = "TEST" board.move_down.return_value = {"lines": 1, "reward": 50, "done": True} tetris.board = board # act result = tetris.step(constants.DOWN) # assert assert result == ("TEST", 50, True, { 'Score': 50, 'Lines': 1, 'Next': 0, 'NewLine': True })
def test_play_done() -> None: # arrange game: TetrisBase = TetrisBase() movement: Movement = HumanMovement.base_movement() tetris: Human = Human(game, movement) movement.next = MagicMock() game.reset = MagicMock() game.step = MagicMock() game.render = MagicMock() game.close = MagicMock() movement.next.return_value = (0, False) game.step.return_value = (0, 0, True, 0) # act tetris.play() # assert game.reset.assert_called_once() game.step.assert_called_once() game.render.assert_called_once() game.close.assert_called_once()
def __init__(self) -> None: seed = np.random.randint(0, 1000) self.game: TetrisBase = TetrisBase(seed=seed)
def __init__(self) -> None: seed = np.random.randint(0, constants.MAX_INT) self.game: TetrisBase = TetrisBase(seed=seed)
def __init__(self) -> None: self.game: TetrisBase = TetrisBase()