Example #1
0
def test_add_human_off_grid():
    """
    A player should not be able to be added out of bounds
    """
    mock_human = Mock()
    starting_coordinates = [5, 5]
    grid = Grid(size=[4, 4])
    with pytest.raises(ValueError):
        grid.add_player(mock_human, starting_coordinates)
Example #2
0
def test_add_human():
    """
    Add human to the grid
    Check that the are stored
    """
    mock_human = Mock(render='H')
    starting_coordinates = [1, 2]
    grid = Grid(size=[4, 4])
    grid.add_player(mock_human, starting_coordinates)
    assert [1, 2] == grid.players_and_coordinates[mock_human]
Example #3
0
def test_add_player_adds_two_humans_to_same_square():
    """
    Bug fix - code should not error in this scenario
    Create 4x4 grid
    Add 2 humans on the same square [0, 0]
    Assert that unoccupied_coordinates does not include [0, 0]
    """
    grid = Grid([4, 4])
    grid.add_player(Mock(render="H"), [0, 0])
    grid.add_player(Mock(render="H"), [0, 0])
    assert [0, 0] not in grid.unoccupied_coordinates
def test_human_does_not_move_if_wall(mock_random):
    # Given a program in progress
    # When a human moves into a wall
    # Then the human will not move on that go
    mock_random.randint.return_value = 0
    human = Human()
    grid = Grid(size=[4, 3])
    grid.add_player(human, [0, 0])
    grid.players_move()
    display = Display(grid)
    rendered_display = display.render()
    assert rendered_display[0].loc[0] == "H"
Example #5
0
def test_convert_if_needed_nothing_to_convert():
    """
    If 2 zombies and a human are on the same square
    The human becomes a zombie
    """
    grid = Grid(size=[4, 4])
    grid.add_player(Human(), [2, 2])
    grid.add_player(Zombie(), [2, 2])
    grid.add_player(Zombie(), [2, 2])
    grid.convert_if_needed()

    players = grid.players_and_coordinates.keys()
    assert len([x for x in players if type(x) == Human]) == 0
    assert len([x for x in players if type(x) == Zombie]) == 3
Example #6
0
def test_convert_if_needed():
    """
    Create a grid with a human and a zombie with the same coordinates
    Assert that the human turns into a zombie
    """

    coordinates = [2, 2]
    grid = Grid(size=[4, 4])
    grid.add_player(Human(), coordinates)
    grid.add_player(Zombie(), coordinates)

    grid.convert_if_needed()
    players = grid.players_and_coordinates.keys()
    assert len([x for x in players if type(x) == Zombie]) == 2
Example #7
0
def test_convert_if_needed():
    """
    Create a grid with a human and a zombie with the same coordinates
    Assert that the human turns into a zombie
    """
    mock_human = Mock(render='Z')
    mock_zombie = Mock(render="H")
    coordinates = [2, 2]
    grid = Grid(size=[4, 4])
    grid.add_player(mock_human, coordinates)
    grid.add_player(mock_zombie, coordinates)

    grid.convert_if_needed()
    assert len(grid.zombie_coordinates) == 2
Example #8
0
def test_add_player_removes_coordinates_from_blank_square_coordinates():
    """
    Create a grid 4 x 4
    Add a zombie at 0, 0
    Add a human at 0, 1
    Assert both have been removed from blank_square_coordinates
    Assert total number of blank squares has been reduced by 2
    """
    grid = Grid([4, 4])
    grid.add_player(Mock(render="H"), [0, 0])
    grid.add_player(Mock(render="Z"), [0, 1])
    assert [0, 0] not in grid.unoccupied_coordinates
    assert [0, 1] not in grid.unoccupied_coordinates
    assert len(grid.unoccupied_coordinates) == 14
Example #9
0
def test_convert_if_needed_converts_one():
    """
    If 1 zombie and a 2 humans are on the same square
    One human becomes a zombie, the other doesn't
    """
    grid = Grid(size=[4, 4])
    grid.add_player(Human(), [2, 2])
    grid.add_player(Human(), [2, 2])
    grid.add_player(Zombie(), [2, 2])
    grid.convert_if_needed()

    players = grid.players_and_coordinates.keys()
    assert len([x for x in players if type(x) == Human]) == 1
    assert len([x for x in players if type(x) == Zombie]) == 2
def test_grid_renders_with_human():
    # Given the means to start the program
    # When the user initiates the start
    # Then a human is occupying a single square
    human = Human()
    grid = Grid(size=[4, 3])
    grid.add_player(human, [0, 0])
    display = Display(grid)

    top_row = ["H", ".", ".", "."]
    row = [".", ".", ".", "."]
    expected_df = pd.DataFrame([top_row, row, row])

    assert_frame_equal(display.render(), expected_df)
def test_zombie_turns_human_into_zombie():
    # Given a program in progress
    # When a zombie occupies the same square as the human
    # Then the human will become a zombie
    human = Human()
    zombie = Zombie()
    grid = Grid(size=[4, 3])
    grid.add_player(human, [0, 0])
    grid.add_player(zombie, [0, 0])
    grid.convert_if_needed()
    zombies = [
        x for x in grid.players_and_coordinates.keys() if type(x) == Zombie
    ]
    assert len(zombies) == 2
Example #12
0
def test_convert_if_needed_converts_two():
    """
    If 2 zombies and a 2 humans are on the same square
    Both humans become zombies
    """
    grid = Grid(size=[4, 4])
    grid.add_player(Human(), [2, 2])
    grid.add_player(Human(), [2, 2])
    grid.add_player(Zombie(), [2, 2])
    grid.add_player(Zombie(), [2, 2])
    grid.convert_if_needed()

    players = grid.players_and_coordinates.keys()
    assert len([x for x in players if type(x) == Human]) == 0
    assert len([x for x in players if type(x) == Zombie]) == 4
def test_human_moves_one_space():
    #TODO: to ask andy. There were times when this test passed and failed randomly
    # Given a program in progress
    # When it is time for a new go or turn
    # Then the human will move 1 pace in a random direction (N, NE, E, SE, S, SW, W, NW)
    human = Human()
    grid = Grid(size=[4, 3])
    grid.add_player(human, [2, 1])
    grid.players_move()
    display = Display(grid)
    rendered_display = display.render()

    possible_human_coordinates = [[2, 0], [3, 0], [3, 1], [3, 2], [2, 2],
                                  [1, 2], [1, 1], [1, 0]]
    result = []
    for coordinates in possible_human_coordinates:
        result.append(rendered_display[coordinates[0]].loc[coordinates[1]])
    assert "H" in result
def test_grid_renders_with_zombie_and_human():
    # Given the means to start the program
    # When the user initiates the start
    # Then the human and zombie are on different squares

    zombie = Zombie()
    human = Human()
    grid = Grid(size=[4, 3])
    grid.add_player(zombie, [0, 0])
    grid.add_player(human, [0, 2])
    display = Display(grid)
    rendered_display = display.render()

    top_row = ["Z", ".", ".", "."]
    bottom_row = ["H", ".", ".", "."]
    row = [".", ".", ".", "."]
    expected_df = pd.DataFrame([top_row, row, bottom_row])

    assert_frame_equal(rendered_display, expected_df)
def test_zombie_moves_towards_human(mock_move):
    # Given a program in progress
    # When it is time for a new go or turn
    # Then the zombie will move 1 pace towards the human
    """
    Set up the game with Human on 0, 0 and zombie on 0, 2
    Ensure that human will not move on their go
    Call players-move()
    Assert that zombie is at 0, 1
    """
    mock_move.return_value = [0, 0]

    human = Human()
    zombie = Zombie()
    grid = Grid(size=[4, 3])
    grid.add_player(human, [0, 0])
    grid.add_player(zombie, [0, 2])
    grid.players_move()
    display = Display(grid)
    rendered_display = display.render()

    assert rendered_display[0].loc[1] == "Z"
Example #16
0
def test_convert_if_needed_more_than_one_convert():
    """
    Create a grid with 3 humans and 3 zombies, each pair with the same coordinates
    Assert that each human turns into a zombie
    """

    coordinates_1 = [2, 2]
    coordinates_2 = [3, 3]
    coordinates_3 = [1, 1]

    grid = Grid(size=[4, 4])

    grid.add_player(Human(), coordinates_1)
    grid.add_player(Zombie(), coordinates_1)
    grid.add_player(Human(), coordinates_2)
    grid.add_player(Zombie(), coordinates_2)
    grid.add_player(Human(), coordinates_3)
    grid.add_player(Zombie(), coordinates_3)

    grid.convert_if_needed()
    players = grid.players_and_coordinates.keys()
    assert len([x for x in players if type(x) == Zombie]) == 6