Пример #1
0
def test_handle_food_updating_score(fake_stdscr):
    game = core.Game(fake_stdscr)
    game.food.coord.y = game.snake.body[-1].y
    game.food.coord.x = game.snake.body[-1].x + 1
    game.snake.move()
    game.handle_food()
    assert game.score == 1 and game.food_counter == 0
Пример #2
0
def test_is_touching_food(fake_stdscr):
    game = core.Game(fake_stdscr)
    game.food.coord.y = game.snake.body[-1].y
    game.food.coord.x = game.snake.body[-1].x + 1
    assert not game.snake.is_touching_food(game.food)
    game.snake.move()
    assert game.snake.is_touching_food(game.food)
Пример #3
0
def test_render_food(fake_curses, fake_stdscr):
    game = core.Game(fake_stdscr)
    ui = user_interface.UserInterface(fake_stdscr)
    ui.render_food(game.food)
    assert (
        game.food.coord.y,
        game.food.coord.x * 2,
        "  ",
        None,
    ) in fake_stdscr.addstred
Пример #4
0
def test_move(current, potential, fake_stdscr):
    game = core.Game(fake_stdscr)
    if current == core.Direction.LEFT:
        game.set_direction(core.Direction.UP)
        for _ in range(5):
            game.snake.move()
    for direction, next_step in potential:
        game.snake.direction = current
        game.snake.move()
        before = game.snake.body.copy()
        game.set_direction(direction)
        game.snake.move()
        assert game.snake.body[-1] == before[-1] + next_step
Пример #5
0
def test_collision(fake_stdscr):
    game = core.Game(fake_stdscr)
    for direction in (
            core.Direction.RIGHT,
            core.Direction.UP,
            core.Direction.LEFT,
            core.Direction.DOWN,
    ):
        game.set_direction(direction)
        if direction == core.Direction.DOWN:
            with pytest.raises(core.CollisionError):
                game.snake.move()
        else:
            game.snake.move()
Пример #6
0
def test_pause(monkeypatch, fake_curses, fake_stdscr):
    monkeypatch.setattr(fake_stdscr, "getch", fake_getch_pause)
    game = core.Game(fake_stdscr)
    snake_before = game.snake.body
    game.pause()
    assert game.snake.body == snake_before
Пример #7
0
def test_handle_food_counter(before, after, fake_stdscr):
    game = core.Game(fake_stdscr)
    game.food_counter = before
    game.handle_food()
    assert game.food_counter == after
Пример #8
0
def test_set_direction_valid(current, valid, fake_stdscr):
    game = core.Game(fake_stdscr)
    for direction in valid:
        game.snake.direction = current
        game.set_direction(direction)
        assert game.snake.direction == direction
Пример #9
0
def test_set_direction(current, wanted, fake_stdscr):
    game = core.Game(fake_stdscr)
    game.snake.direction = current
    assert game.set_direction(wanted) is None
Пример #10
0
def test_restart(fake_stdscr):
    game = core.Game(fake_stdscr)
    game.restart()
    assert game.food_counter == 0 and game.score == 0
Пример #11
0
def test_get_next_step(direction, coords, fake_stdscr):
    game = core.Game(fake_stdscr)
    game.set_direction(direction)
    assert game.snake.get_next_step() == coords
Пример #12
0
def test_render_snake(fake_curses, fake_stdscr):
    game = core.Game(fake_stdscr)
    ui = user_interface.UserInterface(fake_stdscr)
    ui.render_snake(game.snake)
    for piece in game.snake.body:
        assert (piece.y, piece.x * 2, "  ", None) in fake_stdscr.addstred