예제 #1
0
def test_new_boids_fly_away_neighbours_regression():
    '''
    Unit test - Fly away from neighbours method - fixture
    '''
    regression_data = yaml.load(open(os.path.join(
                                os.path.dirname(__file__),
                                'fixtures/fixture_fly_away_neighbours.yml')))
    boid_data_before = regression_data["before"]

    boid_positions_before, boid_velocities_before = boid_data_before

    test_boids_master = BoidsMaster()
    test_boids_master.set_boids(np.array(boid_positions_before),
                                np.array(boid_velocities_before))
    test_boids_master.fly_away_from_neighbours()
    test_boids_master.update_positions()

    boid_positions_after = test_boids_master.positions.tolist()
    boid_velocities_after = test_boids_master.velocities.tolist()

    boid_data = (boid_positions_after, boid_velocities_after)
    #
    # print(len(boid_data_before))
    # print(len(boid_velocities_after))

    for after, before in zip(regression_data["after"], boid_data):
        for after_value, before_value in zip(after, before):
            assert_almost_equal(after_value, before_value, delta=0.01)
예제 #2
0
def test_new_boids_match_speed_regression():
    '''
    Unit test - Match speed with neighbours - fixture
    '''
    regression_data = yaml.load(open(os.path.join(os.path.dirname(__file__),
                                     'fixtures/fixture_match_speed.yml')))
    boid_data_before = regression_data["before"]

    boid_positions_before, boid_velocities_before = boid_data_before

    test_boids_master = BoidsMaster()
    test_boids_master.set_boids(np.array(boid_positions_before),
                                np.array(boid_velocities_before))
    test_boids_master.match_speed_w_neighbours()
    test_boids_master.update_positions()

    boid_positions_after = test_boids_master.positions.tolist()
    boid_velocities_after = test_boids_master.velocities.tolist()

    boid_data = (boid_positions_after, boid_velocities_after)

    for after, before in zip(regression_data["after"], boid_data):
        for after_value, before_value in zip(after, before):
            assert_almost_equal(after_value, before_value, delta=0.01)