def test_decompose(self): #normal vector self.v.normalize() #change d to something thats not parallel to v self.d.y = 1 #expected parallel vector respara = Vector2D() respara.x = respara.y = 1.5 #expected perpendicullar vector resperp = Vector2D() resperp.x = 0.5 resperp.y = -0.5 para, perp = Vector2D.decompose(self.d, self.v) self.assertAlmostEqual(para, respara) self.assertAlmostEqual(perp, resperp)
def test_distance(self): dist = Vector2D.distance(self.v, self.d) self.assertAlmostEqual(dist, 4.242640687)
def test_dot(self): self.assertEqual(Vector2D.dot(self.v, self.d), 20)
def test_as_normalized(self): z = Vector2D.asNormalized(self.v) self.assertAlmostEqual(z.magnitude(), 1.0)