Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
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
    })
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
 def __init__(self) -> None:
     seed = np.random.randint(0, 1000)
     self.game: TetrisBase = TetrisBase(seed=seed)
Ejemplo n.º 11
0
 def __init__(self) -> None:
     seed = np.random.randint(0, constants.MAX_INT)
     self.game: TetrisBase = TetrisBase(seed=seed)
Ejemplo n.º 12
0
 def __init__(self) -> None:
     self.game: TetrisBase = TetrisBase()