async def test_positions(self): p1 = Pointlike((2.3, 2.7)) p2 = Point2((-5.3, -7.9)) p3 = Point3((-2.7, 5.4, 133.2)) # Testing Pointlike assert p1 == Pointlike((2.3, 2.7)) assert p1.rounded == Pointlike((2, 3)) assert p1.position == p1 assert p1.distance_to(Pointlike((-0.7, 6.7))) == 5 assert p1.closest([ Pointlike((2, 2)), Pointlike((-2, -2)) ]) == Pointlike((2, 2)) assert p1.furthest([ Pointlike((2, 2)), Pointlike((-2, -2)) ]) == Pointlike((-2, -2)) assert p1.offset(Pointlike((-1, -1))) == Pointlike((1.3, 1.7)) assert p1.offset(Pointlike((-1, 1))) == Pointlike((1.3, 3.7)) assert p1.towards(Pointlike((2.3, 50)), 5) == Pointlike((2.3, 7.7)) # testing backwards aswell assert p1.towards(Pointlike((2.3, 50)), -5) == Pointlike((2.3, -2.3)) # Testing Point2 assert p2.x == -5.3 assert p2.y == -7.9 assert p2.to2 == p2 assert p2.to3 == Point3((-5.3, -7.9, 0)) assert (p2.neighbors4 == { Point2((-5.3, -6.9)), Point2((-5.3, -8.9)), Point2((-4.3, -7.9)), Point2((-6.3, -7.9)), }) assert p2.neighbors8 == (p2.neighbors4 | { Point2((-4.3, -6.9)), Point2((-4.3, -8.9)), Point2((-6.3, -6.9)), Point2((-6.3, -8.9)), }) # Testing Point3 assert p3.z == 133.2 assert p3.to3 == p3
class TestPosition(unittest.TestCase): @classmethod def setUpClass(cls): pass @classmethod def tearDownClass(cls): pass def setUp(self): self.p = Pointlike((2.3, 2.7)) self.p2 = Point2((-5.3, -7.9)) self.p3 = Point3((-2.7, 5.4, 133.2)) def tearDown(self): pass def test_Pointlike(self): self.assertEqual(self.p, Pointlike((2.3, 2.7))) self.assertEqual(self.p.rounded, Pointlike((2, 3))) self.assertEqual(self.p.position, self.p) self.assertEqual(self.p.distance_to(Pointlike((-0.7, 6.7))), 5) self.assertEqual( self.p.closest([Pointlike((2, 2)), Pointlike((-2, -2))]), Pointlike((2, 2))) self.assertEqual( self.p.furthest([Pointlike((2, 2)), Pointlike((-2, -2))]), Pointlike((-2, -2))) self.assertEqual(self.p.offset(Pointlike((-1, -1))), Pointlike((1.3, 1.7))) self.assertEqual(self.p.offset(Pointlike((-1, 1))), Pointlike((1.3, 3.7))) self.assertEqual(self.p.towards(Pointlike((2.3, 50)), 5), Pointlike((2.3, 7.7))) # testing backwards aswell self.assertEqual(self.p.towards(Pointlike((2.3, 50)), -5), Pointlike((2.3, -2.3))) def test_Point2(self): self.assertEqual(self.p2.x, -5.3) self.assertEqual(self.p2.y, -7.9) self.assertEqual(self.p2.to2, self.p2) self.assertEqual(self.p2.to3, Point3((-5.3, -7.9, 0))) self.assertEqual( self.p2.neighbors4, { Point2((-5.3, -6.9)), Point2((-5.3, -8.9)), Point2((-4.3, -7.9)), Point2((-6.3, -7.9)), }) self.assertEqual( self.p2.neighbors8, self.p2.neighbors4 | { Point2((-4.3, -6.9)), Point2((-4.3, -8.9)), Point2((-6.3, -6.9)), Point2((-6.3, -8.9)), }) def test_Point3(self): self.assertEqual(self.p3.z, 133.2) self.assertEqual(self.p3.to3, self.p3)