Exemplo n.º 1
0
    def test_avoid_agents_raise_error(self, fixture_avoid_agents_raise_error):
        """
        Raises an exception when the input DataFrame column `agent`
        does not exist.
        """
        df = DataFrame(pytest.data_without_agent)
        df_to_avoid = DataFrame(pytest.data_avoid)

        with pytest.raises(ValueError):
            assert AgentMovement.avoid_agents(df, df_to_avoid)
Exemplo n.º 2
0
    def test_avoid_agents_one_avoids_two(self,
                                         fixture_avoid_agents_same_rel_angles):
        """One agent avoids two agents with the same relative angles."""
        df = DataFrame(pytest.data)
        df_to_avoid = DataFrame(pytest.data_avoid)
        df = AgentMovement.avoid_agents(df, df_to_avoid)
        expected_angle = 5 * pi / 4

        assert round(df.vx[0], 12) == round(cos(expected_angle), 12)
        assert round(df.vy[0], 12) == round(sin(expected_angle), 12)
Exemplo n.º 3
0
    def test_avoid_agents_one_avoids_four_in_each_axis(
            self, fixture_avoid_agents_one_avoids_four_in_each_axis):
        """One agent avoids four agents in each axis."""
        df = DataFrame(pytest.data)
        df_to_avoid = DataFrame(pytest.data_avoid)
        df = AgentMovement.avoid_agents(df, df_to_avoid)
        expected_angle = pi / 4

        assert round(abs(df.vx[0]), 12) == round(cos(expected_angle), 12)
        assert round(abs(df.vy[0]), 12) == round(sin(expected_angle), 12)
Exemplo n.º 4
0
    def test_avoid_agents_two_avoid_one(
            self, fixture_avoid_agents_two_agents_avoid_one):
        """Two agents avoid one agent with the same relative angle."""
        df = DataFrame(pytest.data)
        df_to_avoid = DataFrame(pytest.data_avoid)
        df = AgentMovement.avoid_agents(df, df_to_avoid)
        expected_angles = [pi / 2, pi / 2]

        for i in range(len(expected_angles)):
            assert round(df.vx[i], 12) == round(cos(expected_angles[i]), 12)
            assert round(df.vy[i], 12) == round(sin(expected_angles[i]), 12)
Exemplo n.º 5
0
    def test_avoid_agents_two_avoid_one_different_rel_angles(
            self, fixture_avoid_agents_different_rel_angles):
        """Two agents avoid one agent with different relative angles."""
        df = DataFrame(pytest.data)
        df_to_avoid = DataFrame(pytest.data_avoid)
        df = AgentMovement.avoid_agents(df, df_to_avoid)
        expected_angles = [3 * pi / 2, 7 * pi / 4]

        for i in range(len(expected_angles)):
            assert round(df.vx[i], 12) == round(cos(expected_angles[i]), 12)
            assert round(df.vy[i], 12) == round(sin(expected_angles[i]), 12)
Exemplo n.º 6
0
    def test_avoid_agents_one_avoids_two_different_rel_angles(
            self, fixture_avoid_agents_one_avoids_two):
        """
            One agent avoids two agents with different relative angles."""
        df = DataFrame(pytest.data)
        df_to_avoid = DataFrame(pytest.data_avoid)
        new_df = AgentMovement.avoid_agents(df, df_to_avoid)
        condition = round(new_df.vx[new_df.agent == 1][0] - -1.0, 7) == round(
            new_df.vy[new_df.agent == 1][0] - 0, 7) == 0

        assert condition
Exemplo n.º 7
0
    def test_avoid_agents_one_agent_between_two(
            self, fixture_avoid_agents_one_agent_between_two):
        """
        One agent avoids two agents diametrically opposite, i.e., with
        0 and pi relatives angles respectively.
        """
        df = DataFrame(pytest.data)
        df_to_avoid = DataFrame(pytest.data_avoid)
        df = AgentMovement.avoid_agents(df, df_to_avoid)
        expected_angle = pi / 2

        assert round(df.vx[0], 12) == round(sqrt(2) * cos(expected_angle), 12)
        assert round(abs(df.vy[0]),
                     12) == round(sqrt(2) * sin(expected_angle), 12)
Exemplo n.º 8
0
    def test_avoid_agents_one_avoids_three(
            self, fixture_avoid_agents_one_agent_avoids_three):
        """
            One agent avoids three agents with different relative angles.
        """
        df = DataFrame(pytest.data)
        df_to_avoid = DataFrame(pytest.data_avoid)
        df = AgentMovement.avoid_agents(df, df_to_avoid)
        expected_angle = pi

        assert round(df.vx[0], 12) ==  \
               round(sqrt(2)*cos(expected_angle), 12)
        assert round(df.vy[0], 12) == \
               round(sqrt(2)*sin(expected_angle), 12)