def test__sub__(self): print("Testing __add__ method") twoD1 = TwoDPoint(1, 1) twoD2 = TwoDPoint(1, 0) twoD3 = TwoDPoint(0, 1) self.assertEqual(twoD1.__sub__(twoD2), twoD3) self.assertEqual(twoD1 - twoD2, twoD3) self.assertNotEqual(twoD1.__sub__(twoD3), twoD3) self.assertNotEqual(twoD1 - twoD1, twoD3) with self.assertRaises(ValueError) as assertStatement: twoD1 - "string" self.assertEqual("Subtraction is possibile only between TwoDPoint", str(assertStatement.exception)) print("Done testing __add__ method successfully")
class TestTwoDPoint(TestCase): def setUp(self) -> None: self.p1 = TwoDPoint(1, 2) self.p2 = TwoDPoint(1, 2) self.p3 = TwoDPoint(3, 2) def test_from_coordinates(self): list_of_points = [ TwoDPoint(0, 4), TwoDPoint(6, 4), TwoDPoint(6, 0), TwoDPoint(0, 0) ] self.assertEqual(TwoDPoint.from_coordinates([0, 4, 6, 4, 6, 0, 0, 0]), list_of_points) # TODO def test_eq(self): self.assertTrue(self.p1.__eq__(self.p2)) self.assertFalse(self.p1.__eq__(self.p3)) self.assertFalse(self.p3.__eq__(self.p2)) def test_ne(self): self.assertTrue(self.p1.__ne__(self.p3)) self.assertTrue(self.p2.__ne__(self.p3)) self.assertFalse(self.p1.__ne__(self.p2)) def test_str(self): self.assertEqual(self.p1.__str__(), "(1, 2)") def test_add(self): self.assertEqual(self.p1.__add__(self.p3), TwoDPoint(4, 4)) def test_sub(self): self.assertEqual(self.p3.__sub__(self.p1), TwoDPoint(2, 0))
def test__sub(self): point1 = TwoDPoint(3, 2) point2 = TwoDPoint(3, 2) self.assertTrue(point1.__sub__(point2).__eq__(TwoDPoint(0, 0)))