Ejemplo n.º 1
0
 def test_get_and_setitem(self):
     v = Vector(3, 5.3)
     self.assertEqual(v.x, v[0], v["x"])
     self.assertEqual(v.y, v[1], v["y"])
     v.x = 3.2
     v.y = 5
     self.assertEqual(v.x, v[0], v["x"])
     self.assertEqual(v.y, v[1], v["y"])
     v[0] = 0.9
     self.assertEqual(v.x, v[0], v["x"])
     v["x"] = 4.6
     self.assertEqual(v.x, v[0], v["x"])
Ejemplo n.º 2
0
 def test_funcs(self):
     v1 = Vector(5.3, 2.0)
     self.assertEqual(v1.as_ints(), Vector(5, 2))
     v2 = v1.copy()
     v2.x = 4.7
     self.assertNotEqual(v1.x, 4.7)
     v = Vector(6, 8)
     self.assertEqual(abs(v), v.magnitude(), 10.0)
     self.assertEqual(v.magnitude_squared(), v.magnitude()**2)
     self.assertEqual(abs(v), math.sqrt(v.magnitude_squared()))
     v.y = -5.3
     self.assertEqual(v.signs(), (1, -1))
     v.x = 0
     self.assertEqual(v.signs(), (0, -1))
     v1 = Vector(4.0, 2.0)
     v2 = Vector(3.0, 1.0)
     self.assertEqual((v1 - v2).manhattan_dist(), 2)
     v2.x = 2.0
     self.assertEqual((v1 - v2).manhattan_dist(), 3)
     self.assertEqual((v1 - v1).manhattan_dist(), 0)