Exemple #1
0
    def test_init_required_fields_no_field(self, set_up,
                                           fixture_init_required_fields):
        """
        Initializes and no change the velocities when there is no
        `group_label` in the `mobility_group` column of the input DataFrame.
        """
        dist_title = fixture_init_required_fields[0]
        group_info = fixture_init_required_fields[2]

        mobility_groups = MobilityGroups(dist_title=dist_title,
                                         group_info=group_info)
        df = DataFrame({
            "mobility_group": [None for i in range(15)],
            "agent": [i for i in range(15)],
            "step": [i for i in range(15)]
        })
        df = AgentMovement.init_required_fields(df, pytest.box_size,
                                                mobility_groups)

        assert all(df["vy"] == inf) and all(df["vx"] == inf)
        assert set(["x", "y"]).issubset(df.columns)
Exemple #2
0
    def test_init_required_fields(self, set_up, fixture_init_required_fields):
        """
        Verifies whether init_required_fields creates the columns:
        `x`, `y`, `vx`, `vy` of an input DataFrame, and verifies whether the
        velocity distribution was applied.
        """
        dist_title = fixture_init_required_fields[0]
        group_info = fixture_init_required_fields[1]

        mobility_groups = MobilityGroups(dist_title=dist_title,
                                         group_info=group_info)
        df = DataFrame({
            "mobility_group": ["MG_1" for i in range(15)],
            "agent": [i for i in range(15)],
            "step": [i for i in range(15)]
        })
        df = AgentMovement.init_required_fields(df, pytest.box_size,
                                                mobility_groups)

        assert all(df.columns.values == pytest.expected_columns)
        assert all(df["vx"] != inf) and all(df["vy"] != inf)
Exemple #3
0
    def test_init_required_fields_field(self, set_up,
                                        fixture_init_required_fields):
        """
        Verifies whether are set the velocities of the agents for a group
        field and are initialized the others.
        """
        dist_title = fixture_init_required_fields[0]
        group_info = fixture_init_required_fields[2]

        mobility_groups = MobilityGroups(dist_title=dist_title,
                                         group_info=group_info)
        df = DataFrame({
            "mobility_group": ["MG_1" for i in range(15)],
            "agent": [i for i in range(15)],
            "step": [i for i in range(15)]
        })
        df.loc[0:9, "mobility_group"] = nan
        df = AgentMovement.init_required_fields(df, pytest.box_size,
                                                mobility_groups)

        assert all(df["vx"][0:10] == inf) and all(df["vy"][0:10] == inf)
        assert all(df["vx"][10:15] != inf) and all(df["vy"][10:15] != inf)
Exemple #4
0
    def test_init_required_fields_positions(self, set_up,
                                            fixture_init_required_fields):
        """
        Verifies whether `x`, `y` components of the agents are inside the
        `box_size`.
        """
        dist_title = fixture_init_required_fields[0]
        group_info = fixture_init_required_fields[1]

        mobility_groups = MobilityGroups(dist_title=dist_title,
                                         group_info=group_info)
        df = DataFrame({
            "mobility_group": ["MG_1" for i in range(15)],
            "agent": [i for i in range(15)],
            "step": [i for i in range(15)]
        })
        df = AgentMovement.init_required_fields(df, pytest.box_size,
                                                mobility_groups)

        assert all(df["x"] < pytest.box_size.right)
        assert all(df["x"] > pytest.box_size.left)
        assert all(df["y"] > pytest.box_size.bottom)
        assert all(df["y"] < pytest.box_size.top)
Exemple #5
0
    def test_init_required_fields_angles(self, set_up,
                                         fixture_init_required_fields):
        """
        Verifies whether the angles of the velocities of the agents are
        positives and minors than 2*pi.
        """
        dist_title = fixture_init_required_fields[0]
        group_info = fixture_init_required_fields[1]

        mobility_groups = MobilityGroups(dist_title=dist_title,
                                         group_info=group_info)
        df = DataFrame({
            "mobility_group": ["MG_1" for i in range(15)],
            "agent": [i for i in range(15)],
            "step": [i for i in range(15)]
        })
        df = AgentMovement.init_required_fields(df, pytest.box_size,
                                                mobility_groups)
        angles = Series(
            AgentMovement.angle(vx, vy)
            for (vx, vy) in zip(df["vx"], df["vy"]))

        assert all(angles.lt(2 * pi))
        assert all(angles.ge(0))