def apply(boids, bj): pcj = Vector() for b in boids: if b != bj: pcj.sum(b.position) pcj = pcj.div(len(boids) - 1) return pcj.minus(bj.position).div(100)
def apply(boids, bj): pvj = Vector() for b in boids: if b != bj: pvj.sum(b.velocity) pvj.div(len(boids) - 1) return pvj.minus(bj.velocity).div(8)
def test_sum(self): # Given vector = Vector() vector_to_sum = Vector(2, 3) expected_x = vector.x + vector_to_sum.x expected_y = vector.y + vector_to_sum.y # When vector.sum(vector_to_sum) # Then self.assertEquals(vector.x, expected_x) self.assertEquals(vector.y, expected_y)
def test_vector_sum_checks_shapes(): """Shape rule: the vectors must be the same size.""" Vector.sum(v, w, m, y)
def test_vector_sum(): """vector_sum can take any number of vectors and add them together.""" assert Vector.sum(v, w, u, y, z) == Vector([12, 26, 35])