コード例 #1
0
ファイル: boids.py プロジェクト: JamesDWatson/BoidsAssessment
def animate(frame):
    Bird.update_boids(no_boids, boid)
    position = [0] * no_boids
    for i in range(no_boids):
        position[i] = (boid[i].x_pos, boid[i].y_pos)
    scatter.set_offsets(list(position))
コード例 #2
0
def test_update_boids():
    random.seed(0)
    boids = [Bird(config, no_boids), Bird(config, no_boids)]
    Bird.update_boids(2, boids)
    assert abs(boids[0].x_pos - -23.68) < 0.1
    assert abs(boids[0].y_pos - 517.72) < 0.1
コード例 #3
0
ファイル: boids.py プロジェクト: JamesDWatson/BoidsAssessment
import yaml
import random
from boids.classes import Bird
import os

 # Import variables from yaml file.
_ROOT = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(_ROOT,'config.yaml')) as config_file:
        config = yaml.load(config_file)
#no_boids = int(arguments.number)
no_boids = config['no_boids']   #Need to get this from the command line.

# Initialise an array of boids, specified by the Bird class.
boid = [0] * no_boids
for x in range(no_boids):
        boid[x] = Bird(config, no_boids) 

figure=plt.figure()
axes=plt.axes(xlim=(config['x_lim'][0],config['x_lim'][1]), ylim=(config['y_lim'][0],config['y_lim'][1]))
scatter=axes.scatter([0] * no_boids,[0] * no_boids)

def animate(frame):
    Bird.update_boids(no_boids, boid)
    position = [0] * no_boids
    for i in range(no_boids):
        position[i] = (boid[i].x_pos, boid[i].y_pos)
    scatter.set_offsets(list(position))

anim = animation.FuncAnimation(figure, animate,
                                   frames=50, interval=50)
コード例 #4
0
def test_vel_matching():
    assert_equal(0, Bird(config, 50).vel_matching([10, 10], [10, 10], 1, 1))
コード例 #5
0
def test_vel_change():
    random.seed(0)  #Use the same seed when the test is run.
    boid1 = Bird(config, no_boids)
    boid2 = Bird(config, no_boids)
    delta_velx = boid1.vel_change(boid2)[0]  #should be in some range.
    assert abs(delta_velx - -0.0999) < 0.1
コード例 #6
0
def test_vel_change_avoid_2():  # Check for non-zero value for inside radius.
    assert abs(Bird.vel_change_avoid([10, 10], 1000)[0]) > 0
コード例 #7
0
def test_rand_generation():  #Check correct random numbers are generated.
    for i in range(10):
        assert Bird(config, 10).x_pos < config['x_pos_bound'][1]
        assert Bird(config, 10).x_pos > config['x_pos_bound'][0]
コード例 #8
0
def test_vel_change_avoid(
):  # No change in velocity if outside the chosen radius.
    assert_equal(0, Bird.vel_change_avoid([10, 10], 1))
コード例 #9
0
def test_update_boid_2():
    with assert_raises(TypeError) as exception:
        boid = [0] * no_boids
        Bird(config, 50).update_boids('example', boid)
コード例 #10
0
def test_update_boid():
    with assert_raises(TypeError) as exception:
        Bird(config, 50).update_boids(2, 'example')
コード例 #11
0
def test_vel_change_fails_wrong_type():
    with assert_raises(TypeError) as exception:
        Bird(config, 50).vel_change('example')
コード例 #12
0
def test_command_fails_non_numerical_input(
):  #Tests that the argument is a valid place.
    with assert_raises(TypeError) as exception:
        Bird(config, '10.1')