Exemplo n.º 1
0
def test_zombie_move_choice():
    """
    Given the coordinates of the 2 humans, a zombie will move one square closer to the nearest one
    """
    zombie = Zombie()
    coordinates = [1, 2]
    human_coordinates = {Human(): [1, 3], Human(): [1, 0]}

    assert zombie.move(coordinates, None, human_coordinates) == [1, 3]
Exemplo n.º 2
0
def test_zombie_move():
    """
    Given the coordinates of the nearest human, a zombie will move one square closer
    """
    zombie = Zombie()
    coordinates = [1, 2]
    players_and_coordinates = {Human(): [1, 0]}

    assert zombie.move(coordinates, None, players_and_coordinates) == [1, 1]
Exemplo n.º 3
0
def test_zombie_move_random(random):
    """
    Given the coordinates of the 2 humans that are equidistance, a zombie will move one square closer to one at random
    """
    zombie = Zombie()
    coordinates = [1, 2]
    human_coordinates = {Human(): [1, 4], Human(): [1, 0]}

    random.choice.side_effect = side_effect
    assert zombie.move(coordinates, None, human_coordinates) == [1, 3]
    def test_center_zombies(self):

        # Assign
        settings = Settings()
        zombie = Zombie(settings)

        zombie.centerx = 5
        zombie.centery = 5

        #Act
        zombie.CenterZombie()

        # Assert
        self.assertTrue(zombie.center == 600)
Exemplo n.º 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
Exemplo n.º 6
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_zombies_on_the_screen(self):
        # Assign
        settings = Settings()
        zombie = Zombie(settings)

        # zombie.moving_right = True

        zombie.rect.right = 550
        zombie.screen_rect.right = 500
        settings.fleet_direction = -1

        # Act
        zombie.ZombiesOnTheScreen()

        # Assert
        self.assertTrue(settings.fleet_direction == 1)
Exemplo n.º 8
0
def test__random_closest_human_coordinates():
    """
    Given 2 humans equidistant and one further away
    Test returns random the two closest
    """
    zombie = Zombie()
    coordinates = [1, 2]
    human_1 = Human()
    human_2 = Human()
    human_3 = Human()

    human_coordinates = {human_1: [1, 4], human_2: [1, 0], human_3: [0, 0]}

    assert zombie._closest_human_coordinates(coordinates,
                                             human_coordinates) == {
                                                 human_1: [1, 4],
                                                 human_2: [1, 0]
                                             }
Exemplo n.º 9
0
def test_zombie_move_memory(random):
    """
    A zombie moved towards a human on the previous go
    Now it is equidistant from 2 humans, one of which was the one it chased the previous go
    It will move towards the one it faced the previous go.
    """
    zombie = Zombie()
    coordinates = [1, 1]
    mock_human_1 = Human()
    mock_human_2 = Human()

    human_coordinates_1 = {mock_human_1: [3, 1], mock_human_2: [3, 3]}

    human_coordinates_2 = {mock_human_1: [3, 1], mock_human_2: [2, 2]}

    random.choice.side_effect = side_effect
    new_coordinates = zombie.move(coordinates, None, human_coordinates_1)
    assert zombie.move(new_coordinates, None, human_coordinates_2) == [3, 1]
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
0
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
Exemplo n.º 13
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
Exemplo n.º 14
0
def test_grid_renders_with_zombie():
    # Given the means to start the program
    # When the user initiates the start
    # Then a zombie is occupying a single square

    zombie = Zombie()
    grid = Grid(size=[4, 3])
    grid.add_player(zombie, [0, 0])
    display = Display(grid)

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

    assert_frame_equal(display.render(), expected_df)
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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"
Exemplo n.º 17
0
def test__move_one_closer(x, y, expected):
    """
    Given a square in a certain dimension, returns one square closer to another square
    """
    zombie = Zombie()
    assert zombie._move_one_closer(x, y) == expected
Exemplo n.º 18
0
def set_up_grid():
    grid = Grid([4, 4])
    grid.players_and_coordinates[Human()] = [0, 0]
    grid.players_and_coordinates[Zombie()] = [1, 1]

    return grid
Exemplo n.º 19
0
def test_zombie_colour_default():
    zombie = Zombie()
    assert zombie.render == 'Z'