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