Exemplo n.º 1
0
class TestRectangle(unittest.TestCase):

    def setUp(self):
        self.rect = Rectangle(Point(10., 20.), Point(30., -5.))

    def test_inside_area(self):
        inside_points = [Point(*i) for i in [
            (10., 20.), (30., -5.), (18., 15.), (29., -1), (10., -3)]]
        outside_points = [Point(*i) for i in [
            (-10., -170.), (-70., 0.), (0., 40), (20., -10.), (50., 0.)]]
        for point_list, test_func in [(inside_points, 'assertTrue'),
                                      (outside_points, 'assertFalse')]:
            for p in point_list:
                with self.subTest("Area -> point: {}".format(p)):
                    getattr(self, test_func)(self.rect.inside_area(p))
                with self.subTest("Point -> area: {}".format(p)):
                    getattr(self, test_func)(p.inside_area(self.rect))

    def test_diagonal(self):
        self.assertAlmostEqual(self.rect.diagonal, 3411261.6697135763)
Exemplo n.º 2
0
class TestRectangle(unittest.TestCase):
    def setUp(self):
        self.rect = Rectangle(Point(10., 20.), Point(30., -5.))

    def test_inside_area(self):
        inside_points = [
            Point(*i)
            for i in [(10., 20.), (30., -5.), (18., 15.), (29., -1), (10., -3)]
        ]
        outside_points = [
            Point(*i)
            for i in [(-10., -170.), (-70., 0.), (0., 40), (20.,
                                                            -10.), (50., 0.)]
        ]
        for point_list, test_func in [(inside_points, 'assertTrue'),
                                      (outside_points, 'assertFalse')]:
            for p in point_list:
                with self.subTest("Area -> point: {}".format(p)):
                    getattr(self, test_func)(self.rect.inside_area(p))
                with self.subTest("Point -> area: {}".format(p)):
                    getattr(self, test_func)(p.inside_area(self.rect))

    def test_diagonal(self):
        self.assertAlmostEqual(self.rect.diagonal, 3411261.6697135763)
Exemplo n.º 3
0
 def setUp(self):
     self.rect = Rectangle(Point(10., 20.), Point(30., -5.))
Exemplo n.º 4
0
 def setUp(self):
     self.rect = Rectangle(Point(10., 20.), Point(30., -5.))