Implement Unit Testing for fancymath #8

Merged
TimDiller merged 17 commits from unit_tests into main 2025-10-24 17:10:59 +00:00
6 changed files with 51 additions and 0 deletions
Showing only changes of commit 6ba84c9859 - Show all commits

View File

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

This should handle case where other is not a Vector.

This should handle case where `other` is not a `Vector`.
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__":
Review

Do we want to handle scalar multiplication here? If so we should implement __rmul__ and __imul__.

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)

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)