From 6ba84c98590e1d6ea760dd64dacf152bf49acf68 Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Fri, 24 Oct 2025 09:58:26 -0500 Subject: [PATCH] add tests for adding Vectors --- src/fancymath/vector.py | 6 ++++++ test/test_vector.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/fancymath/vector.py b/src/fancymath/vector.py index f7c21db..6c10466 100644 --- a/src/fancymath/vector.py +++ b/src/fancymath/vector.py @@ -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) diff --git a/test/test_vector.py b/test/test_vector.py index e69de29..1f4ae0c 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -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)