Implement Unit Testing for fancymath
#8
@@ -30,6 +30,12 @@ class Vector(object):
|
|||||||
s = "Vector(x=%s, y=%s, z=%s)" % (self.x, self.y, self.z)
|
s = "Vector(x=%s, y=%s, z=%s)" % (self.x, self.y, self.z)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def __add__(self, other):
|
||||||
|
|
|||||||
|
x = self.x + other.x
|
||||||
|
y = self.y + other.y
|
||||||
|
z = self.z + other.z
|
||||||
|
return self.__class__(x, y, z)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
corran
commented
Do we want to handle scalar multiplication here? If so we should implement Do we want to handle scalar multiplication here? If so we should implement `__rmul__` and `__imul__`.
|
|||||||
v1 = Vector(3, 4, 0)
|
v1 = Vector(3, 4, 0)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from fancymath.vector import Vector
|
||||||
|
|
||||||
|
|
||||||
|
class TestVector(unittest.TestCase):
|
||||||
|
def test_add_vector(self):
|
||||||
|
v1 = Vector(1, 2, 3)
|
||||||
|
v2 = Vector(-3, -2, -1)
|
||||||
|
v3 = v1 + v2
|
||||||
|
self.assertIsInstance(v3, Vector)
|
||||||
|
self.assertEqual(v3.x, v1.x + v2.x)
|
||||||
|
|||||||
Reference in New Issue
Block a user
This should handle case where
otheris not aVector.