Exemplo n.º 1
0
def test_game_implements_human_speed(mock_input, mock_random):
    # Given a program is starting
    # When I set the speed of a human
    # Then all humans will move at this speed
    """
    Set up game with 10 x 10 grid one human in position 5, 5 and no zombies
    Set their speed to 3
    Check that after 1 go their position will be 3 squares away in any direction
    """
    mock_random.randint.return_value = 5
    mock_inputs(mock_input, 10, 10, 1, 0, 3)

    game = Game()
    game.set_up()
    game.grid.players_move()
    new_coords = list(game.grid.players_and_coordinates.values())[0]

    diff_in_x_coords = abs(new_coords[0] - 5)
    diff_in_y_coords = abs(new_coords[1] - 5)

    # Human has either moved 3 in x direction, or 3 in y direction, or both
    # But Human has not stayed still

    assert diff_in_x_coords in [0, 3]
    assert diff_in_y_coords in [0, 3]
    assert [diff_in_x_coords, diff_in_y_coords] != [0, 0]
Exemplo n.º 2
0
def test_game_request_number_of_zombies(mock_input, mock_print):
    """
    Check that requesting the user for number of zombies as an input saves response
    """
    mock_input.return_value = 3
    game = Game()
    game._request_number_of_zombies()
    mock_print.assert_called_with("Please enter number of zombies")
    assert game.number_of_zombies == 3
Exemplo n.º 3
0
def test_game_request_human_speed(mock_input, mock_print):
    """
    Mock input value
    Call request_human_speed
    Assert that human_speed has been set
    """
    mock_input.return_value = 3
    game = Game()
    game._request_human_speed()
    assert game.human_speed == 3
Exemplo n.º 4
0
def test_game_request_dimensions(mock_input, mock_print):
    """
    Check that requesting the user for dimensions as an input saves response
    """
    mock_input.side_effect = [20, 40]
    game = Game()
    game._request_dimensions()
    mock_print.assert_has_calls(
        [call("Please enter width"),
         call("Please enter length")])
    assert game.dimensions == (20, 40)
Exemplo n.º 5
0
def test_game_inputs(mock_input, mock_print):
    # Given a terminal in the correct directory
    # When I trigger the start of the game
    # Then I will be asked for:
    #     - dimensions
    #     - number of humans
    #     - number of zombies
    mock_inputs(mock_input)
    game = Game()
    game.set_up()
    mock_print.assert_has_calls([
        call("Please enter width"),
        call("Please enter length"),
        call("Please enter number of humans"),
        call("Please enter number of zombies")
    ])
Exemplo n.º 6
0
def test_display_initial_display(mock_print, mock_input):
    """
    Create a game object with grid dimensions
    Expect initial_display to be called on the display object
    """
    # TODO: Question for Andy, what is a sensible way to test this method? This test is essentially replicated

    mock_input.return_value = None

    width = 3
    length = 3

    game = Game()
    game.grid = Mock(width=width, length=length)

    empty_row = ["." for i in range(width + 1)]
    df = pd.DataFrame(data=[empty_row for i in range(length + 1)])

    game.initial_display()
    mock_print.assert_called_with(
        f"Please adjust screen to the size of the below grid:\n{df}\nplease hit enter"
    )
Exemplo n.º 7
0
def test_game_plays(mock_input):
    # Given I have triggered the start of the game
    # Once I have input the paramaters
    # Then the game will play out on my screen
    mock_inputs(mock_input, 3, 3)
    game = Game()
    game.set_up()
    game.play()
    assert game.number_of_humans == 0
    assert game.number_of_zombies == 8
Exemplo n.º 8
0
def test_add_zombie(mock_random):
    #TODO: ask andy. Should I be testing the inability to add two zombies to the same square here?
    """
    Add two zombies to the grid
    Assert that add_player is called twice
    """
    mock_random.choice.side_effect = [1, 1, 2, 2]

    game = Game()
    game.number_of_zombies = 2

    grid = Mock(add_player=Mock(), unoccupied_coordinates=None)
    game.grid = grid

    game._add_zombies()

    assert grid.add_player.call_count == 2
Exemplo n.º 9
0
def set_up_game_with(mock_input,
                     mock_print,
                     dimensions=[4, 3],
                     number_of_humans=5,
                     number_of_zombies=3,
                     human_speed=1,
                     grid_class=False):
    # Create helper function to decouple tests
    mock_input.side_effect = [
        dimensions[0], dimensions[1], number_of_humans, number_of_zombies,
        human_speed
    ]
    game = Game()
    if grid_class:
        game.set_up(grid_class)
    else:
        game.set_up()
    return game
Exemplo n.º 10
0
def test_add_humans(mock_random):
    """
    Set the number of humans that should be in the game
    Assert this this number are indeed added
    """
    mock_random.randint.side_effect = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]

    game = Game()
    game.number_of_humans = 5
    game.grid = Mock(add_player=Mock())
    mock_human = Mock(side_effect=["h1", "h2", "h3", "h4", "h5"])

    game._add_humans(mock_human)

    game.grid.add_player.assert_has_calls([
        call("h1", [1, 1]),
        call("h2", [2, 2]),
        call("h3", [3, 3]),
        call("h4", [4, 4]),
        call("h5", [5, 5])
    ])
Exemplo n.º 11
0
def play_game(game=Game()):
    game.set_up()
    game.initial_display()
    game.play()