From 922ed4d39429b01d142f1b02e1e98bee50fd04fa Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Fri, 24 Oct 2025 09:33:33 -0500 Subject: [PATCH 01/12] initial commit test suite --- src/fancymath/math.py | 8 ++++++++ test/test_math.py | 0 test/test_util.py | 0 test/test_vector.py | 0 4 files changed, 8 insertions(+) create mode 100644 test/test_math.py create mode 100644 test/test_util.py create mode 100644 test/test_vector.py diff --git a/src/fancymath/math.py b/src/fancymath/math.py index eafeaf8..b807566 100644 --- a/src/fancymath/math.py +++ b/src/fancymath/math.py @@ -15,6 +15,14 @@ def fact(n: int) -> int: return n * fact(n - 1) +def is_even(x): + return x % 2 == 0 + + +def is_odd(x): + return x % 2 == 1 + + if __name__ == '__main__': n = 5 assert fact(n) == 120 diff --git a/test/test_math.py b/test/test_math.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_util.py b/test/test_util.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_vector.py b/test/test_vector.py new file mode 100644 index 0000000..e69de29 -- 2.50.1 From 56c892d944d594b04bbf922325b822c6dd6e143c Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Fri, 24 Oct 2025 09:34:21 -0500 Subject: [PATCH 02/12] make test folder importable --- test/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/__init__.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 -- 2.50.1 From 6d98c08e89ff885b572beb806c87b4d296d7a276 Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Fri, 24 Oct 2025 09:46:21 -0500 Subject: [PATCH 03/12] tests for is_even and is_odd --- test/test_math.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_math.py b/test/test_math.py index e69de29..5e102a8 100644 --- a/test/test_math.py +++ b/test/test_math.py @@ -0,0 +1,25 @@ +import unittest + +from fancymath.math import is_even, is_odd + + +class TestMath(unittest.TestCase): + def test_is_even(self): + "Test the is_even function" + self.assertTrue(is_even(2)) + self.assertTrue(is_even(-4)) + self.assertTrue(is_even(0)) + self.assertFalse(is_even(1)) + self.assertFalse(is_even(2.5)) + + def test_is_odd(self): + "Test the is_odd function" + self.assertTrue(is_odd(3)) + self.assertTrue(is_odd(-5)) + self.assertFalse(is_odd(0)) + self.assertFalse(is_odd(2)) + self.assertFalse(is_odd(2.5)) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file -- 2.50.1 From 6ba84c98590e1d6ea760dd64dacf152bf49acf68 Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Fri, 24 Oct 2025 09:58:26 -0500 Subject: [PATCH 04/12] 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) -- 2.50.1 From 352480ac14c8daa5509b269cdf67a6ee2baf3f18 Mon Sep 17 00:00:00 2001 From: David Moody Date: Fri, 24 Oct 2025 10:08:28 -0500 Subject: [PATCH 05/12] add test_dot_product to test_vector.py --- test/test_vector.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_vector.py b/test/test_vector.py index 1f4ae0c..04d7304 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -10,3 +10,11 @@ class TestVector(unittest.TestCase): v3 = v1 + v2 self.assertIsInstance(v3, Vector) self.assertEqual(v3.x, v1.x + v2.x) + + def test_dot_product(self): + v1 = Vector(1, 2, 3) + v2 = Vector(-3, -2, -1) + v3 = v1.dot(v2) + self.assertEqual(v3,v1.x * v2.x + v1.y * v2.y + v1.z * v2.z) + vzero = Vector(0, 0, 0) + self.assertEqual(v1.dot(vzero),0) -- 2.50.1 From 35a1705570a52bf065f8336141461b0a102cc313 Mon Sep 17 00:00:00 2001 From: Ambar de Santiago Date: Fri, 24 Oct 2025 11:10:39 -0400 Subject: [PATCH 06/12] Add unit test for Vecotr.abs method --- test/test_vector.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_vector.py b/test/test_vector.py index 1f4ae0c..db0ab24 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -10,3 +10,11 @@ class TestVector(unittest.TestCase): v3 = v1 + v2 self.assertIsInstance(v3, Vector) self.assertEqual(v3.x, v1.x + v2.x) + + def test_abs(self): + v1 = Vector(0, 0, 0) + v2 = Vector(1, 2, 2) + v3 = Vector(1, -2, 2) + self.assertEqual(v1.abs, 0) + self.assertEqual(v1.abs, 3) + \ No newline at end of file -- 2.50.1 From 13ac74132c8496cb924f98a568ebb56dfa4ee64a Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Fri, 24 Oct 2025 16:13:25 +0100 Subject: [PATCH 07/12] Add cross-product and tests --- test/test_vector.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/test_vector.py b/test/test_vector.py index 1f4ae0c..3606b6d 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -4,6 +4,28 @@ from fancymath.vector import Vector class TestVector(unittest.TestCase): + def test_cross_product(self): + # given + v1 = Vector(1, 2, 3) + v2 = Vector(3, 2, 1) + + # when + v3 = v1 * v2 + + # then + self.assertIsInstance(v3, Vector) + self.assertEqual(v3.x, -4) + self.assertEqual(v3.y, 8) + self.assertEqual(v3.z, -4) + + def test_cross_product_failure(self): + v1 = Vector(1, 2, 3) + v2 = (3, 2, 1) + + with self.assertRaises(TypeError): + v1 * v2 + + def test_add_vector(self): v1 = Vector(1, 2, 3) v2 = Vector(-3, -2, -1) -- 2.50.1 From b61324180727188fb947e46cb3a36aa7e29e2457 Mon Sep 17 00:00:00 2001 From: Ambar de Santiago Date: Fri, 24 Oct 2025 11:17:40 -0400 Subject: [PATCH 08/12] Add unit test for Vector.abs --- test/test_vector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_vector.py b/test/test_vector.py index db0ab24..7f0896e 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -16,5 +16,5 @@ class TestVector(unittest.TestCase): v2 = Vector(1, 2, 2) v3 = Vector(1, -2, 2) self.assertEqual(v1.abs, 0) - self.assertEqual(v1.abs, 3) - \ No newline at end of file + self.assertEqual(v2.abs, 3) + self.assertEqual(v2.abs, v3.abs) \ No newline at end of file -- 2.50.1 From 4d5e2db71adc7d9e4467d9b07ff72950070b16b1 Mon Sep 17 00:00:00 2001 From: Tim Diller Date: Fri, 24 Oct 2025 10:11:43 -0500 Subject: [PATCH 09/12] add test for proper failure of Vector.dot --- test/test_vector.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_vector.py b/test/test_vector.py index 04d7304..d3b0f65 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -11,6 +11,11 @@ class TestVector(unittest.TestCase): self.assertIsInstance(v3, Vector) self.assertEqual(v3.x, v1.x + v2.x) + def test_dot_failure(self): + with self.assertRaises(ValueError): + v1 = Vector(1, 2, 3) + v1.dot(3) + def test_dot_product(self): v1 = Vector(1, 2, 3) v2 = Vector(-3, -2, -1) -- 2.50.1 From 437be17f51b8bc7fbf9e79cceff3769e98ac04de Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Fri, 24 Oct 2025 16:21:50 +0100 Subject: [PATCH 10/12] Add cross product impleimentation --- src/fancymath/vector.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fancymath/vector.py b/src/fancymath/vector.py index 6c10466..c027e5b 100644 --- a/src/fancymath/vector.py +++ b/src/fancymath/vector.py @@ -36,6 +36,14 @@ class Vector(object): z = self.z + other.z return self.__class__(x, y, z) + def __mul__(self, other): + if not isinstance(other, Vector): + return NotImplemented + x = self.y * other.z - self.z * other.y + y = self.z * other.x - self.x * other.z + z = self.x * other.y - self.y * other.x + return self.__class__(x, y, z) + if __name__ == "__main__": v1 = Vector(3, 4, 0) -- 2.50.1 From 79b6c10b70ef37ce67698a9d69f8cb68a64dd56e Mon Sep 17 00:00:00 2001 From: Ambar de Santiago Date: Fri, 24 Oct 2025 11:38:26 -0400 Subject: [PATCH 11/12] Corrected syntax for vecotr.abs() test --- test/test_vector.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_vector.py b/test/test_vector.py index 7f0896e..aeb002f 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -15,6 +15,6 @@ class TestVector(unittest.TestCase): v1 = Vector(0, 0, 0) v2 = Vector(1, 2, 2) v3 = Vector(1, -2, 2) - self.assertEqual(v1.abs, 0) - self.assertEqual(v2.abs, 3) - self.assertEqual(v2.abs, v3.abs) \ No newline at end of file + self.assertEqual(v1.abs(), 0) + self.assertEqual(v2.abs(), 3) + self.assertEqual(v2.abs(), v3.abs()) \ No newline at end of file -- 2.50.1 From 66123f60647f8cad6bd1f56ca7e66d6146fbbf7f Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Fri, 24 Oct 2025 16:54:47 +0100 Subject: [PATCH 12/12] Add subtests for test_cross_product. --- test/test_vector.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/test/test_vector.py b/test/test_vector.py index 5238172..4af67c9 100644 --- a/test/test_vector.py +++ b/test/test_vector.py @@ -5,18 +5,22 @@ from fancymath.vector import Vector class TestVector(unittest.TestCase): def test_cross_product(self): - # given - v1 = Vector(1, 2, 3) - v2 = Vector(3, 2, 1) + # Dictionary of (v1, v2): v3 + values = { + (Vector(1, 2, 3), Vector(3, 2, 1)): Vector(-4, 8, -4), + (Vector(0, 0, 0), Vector(1, 2, 3)): Vector(0, 0, 0), + (Vector(1, 0, 0), Vector(1, 0, 0)): Vector(0, 0, 0), + } - # when - v3 = v1 * v2 + for inputs, expected in values.items(): + v1, v2 = inputs + with self.subTest(v1=v1, v2=v2): + v3 = v1 * v2 - # then - self.assertIsInstance(v3, Vector) - self.assertEqual(v3.x, -4) - self.assertEqual(v3.y, 8) - self.assertEqual(v3.z, -4) + self.assertIsInstance(v3, Vector) + self.assertEqual(v3.x, expected.x) + self.assertEqual(v3.y, expected.y) + self.assertEqual(v3.z, expected.z) def test_cross_product_failure(self): v1 = Vector(1, 2, 3) @@ -40,7 +44,7 @@ class TestVector(unittest.TestCase): self.assertEqual(v1.abs(), 0) self.assertEqual(v2.abs(), 3) self.assertEqual(v2.abs(), v3.abs()) - + def test_dot_failure(self): with self.assertRaises(ValueError): v1 = Vector(1, 2, 3) -- 2.50.1