Initial commit

This commit is contained in:
Chris Proctor
2025-07-28 13:29:18 -04:00
commit f7fd3e8a7e
18 changed files with 1313 additions and 0 deletions

48
tests/test_point.py Normal file
View File

@@ -0,0 +1,48 @@
from unittest import TestCase
from geometry.point import Point
from geometry.vector import Vector
class TestPoint(TestCase):
def setUp(self):
self.origin = Point((0, 0))
self.a = Point((4, 0))
self.b = Point((0, 3))
self.c = Point((5, 2))
self.v = Vector((1, 2))
def test_init_with_none(self):
origin = Point()
self.assertEqual(origin.x, 0)
def test_init_with_pair(self):
p = Point((4, 2))
self.assertEqual(p.x, 4)
def test_init_with_vector(self):
self.assertEqual(self.a, Point(Vector(self.a)))
def test_string_representation(self):
self.assertEqual(str(self.a), "(4, 0)")
def test_equality(self):
self.assertEqual(self.a, self.a)
self.assertNotEqual(self.a, self.b)
def test_addition_with_vector(self):
self.assertEqual(self.a + self.v, self.c)
def test_addition_with_invalid_type(self):
with self.assertRaises(TypeError):
self.a + self.a
def test_subtraction_with_point(self):
self.assertEqual(self.c - self.a, self.v)
def test_subtraction_with_vector(self):
self.assertEqual(self.c - self.v, self.a)
def test_subtraction_with_invalid_type(self):
with self.assertRaises(TypeError):
self.a - 4