add tests for adding Vectors

This commit is contained in:
2025-10-24 09:58:26 -05:00
parent 6d98c08e89
commit 6ba84c9859
2 changed files with 18 additions and 0 deletions

View File

@@ -30,6 +30,12 @@ class Vector(object):
s = "Vector(x=%s, y=%s, z=%s)" % (self.x, self.y, self.z)
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__":
v1 = Vector(3, 4, 0)

View File

@@ -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)