def test_update_velocities_group_field_and_indexes_not_None( self, fixture_update_velocities): """ Comparison of the angles of the agents after applying update velocities through a Kolmogorov-smirnov test. `indexes` and `group_field` are set not None. """ distribution = pytest.distrib sample_indexes = 500 delta_angles = pytest.delta_angles df = DataFrame(pytest.data_large_sample) df["mobility_profile"] = "MG_1" mobility_group_slice = 300 df.loc[0:mobility_group_slice - 1, "mobility_profile"] = "MG_2" angles_before = AgentMovement.vector_angles(df, ['vx', 'vy']) indexes = [i for i in range(sample_indexes + 1)] df = AgentMovement.update_velocities(df, distribution, pytest.angle_variance, indexes, "mobility_profile", "MG_2") angles_after = AgentMovement.vector_angles(df, ['vx', 'vy']) angle_variation_1 = angles_after[:mobility_group_slice] - \ angles_before[:mobility_group_slice] k, p_1 = kstest(angle_variation_1.values, delta_angles) angle_variation_2 = angles_after[mobility_group_slice:] - \ angles_before[mobility_group_slice:] k, p_2 = kstest(angle_variation_2.values, delta_angles) cond_1 = True if p_1 > 0.05 else False cond_2 = True if p_2 < 0.05 else False assert cond_1 and cond_2
def test_deviation_angle(self, input_df, expected_angle): """Verifies the deviation angle function in three different cases""" input_df["relative_angle"] = AgentMovement.vector_angles( input_df, ["x_relative", "y_relative"]) angle = AgentMovement.deviation_angle(input_df) assert round(angle, 12) == round(expected_angle, 12)
def test_update_velocities_angle_variance_zero_indexes_group_field_None( self, fixture_update_velocities): """ Verifies whether there are no changes in the velocities components when the standard deviation of the numpy normal distribution is set to zero `angle_variance=0.0`. `indexes` and `group_field` is se to None. """ df = DataFrame(pytest.data_large_sample) angles_before = AgentMovement.vector_angles(df, ['vx', 'vy']) df = AgentMovement.update_velocities(df, pytest.distrib, 0.0) angles_after = AgentMovement.vector_angles(df, ['vx', 'vy']) not_angle_variation = all( round(angles_before.head() - angles_after.head(), 7)) assert not_angle_variation == 0
def test_update_velocities_comparison_KS_test(self, fixture_update_velocities): """ Comparison of the angles of the agents after applying update velocities through a Kolmogorov-smirnov test. `indexes` and `group_field` are set to None. """ df = DataFrame(pytest.data_large_sample) angles_before = AgentMovement.vector_angles(df, ['vx', 'vy']) df = AgentMovement.update_velocities(df, pytest.distrib, pytest.angle_variance) angles_after = AgentMovement.vector_angles(df, ['vx', 'vy']) angle_variation = angles_after - angles_before k, p = kstest(angle_variation.values, pytest.delta_angles) cond = True if p > 0.05 else False assert cond
def test_vector_angles(self, input_df, expected_angle): """ Calculates the angle position of the agents with components `x` and `y` of the input DataFrame. """ angle = AgentMovement.vector_angles(input_df, ['x', 'y']) assert round(angle[0], decimals=10) == \ round(expected_angle, decimals=10)
def test_vector_angles_raise_error_correct_list( self, fixture_vector_angles_raise_error): """ Raises an exception when the input DataFrame columns are not in the list, `vx` and `vy` in this case. """ df = DataFrame(pytest.wrong_data) correct_list = pytest.correct_list with pytest.raises(ValueError): assert AgentMovement.vector_angles(df, correct_list)
def test_vector_angles_raise_error_wrong_list( self, fixture_vector_angles_raise_error): """ Raises an exception when the input list does not have correct columns names, `vx` and `vy` in this case. """ df = DataFrame(pytest.data) wrong_list = pytest.wrong_list with pytest.raises(ValueError): assert AgentMovement.vector_angles(df, wrong_list)
def test_update_velocities_group_field_None(self, fixture_update_velocities): """ Comparison of the angles of the agents after applying update velocities through a Kolmogorov-smirnov test. `group_field` is set to None. """ distribution = pytest.distrib sample_indexes = 400 df = DataFrame(pytest.data_large_sample) angles_before = AgentMovement.vector_angles( df, ['vx', 'vy'])[:sample_indexes] indexes = [i for i in range(sample_indexes + 1)] df = AgentMovement.update_velocities(df, distribution, pytest.angle_variance, indexes, None, None) angles_after = AgentMovement.vector_angles( df, ['vx', 'vy'])[:sample_indexes] angle_variation = angles_after - angles_before k, p = kstest(angle_variation.values, pytest.delta_angles) cond = True if p > 0.05 else False assert cond