def test_flip_twice_doesnt_change_surface_area(self, *points): points = list(points) poly = Polygon(points.copy()) poly.flip() poly.flip() self.assertEqual(poly.area(), poly.area())
def test_area(): points = [(0, 0), (2, 0), (2, 2), (0, 2)] polygon = Polygon(points) with pytest.raises(NotImplementedError) as e: polygon.area() assert str(e.value) == 'Method area should be defined in the child class.'
def test_clockwise_square(self): square = Polygon(vertex_positions=[ (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), ][::-1]) origin = (0.0, 0.0) self.assertEqual(square.winding_number(origin), -1) self.assertEqual(square.area(), -4.0)
def test_double_square(self): square = Polygon(vertex_positions=[ (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), ] * 2) origin = (0.0, 0.0) self.assertEqual(square.winding_number(origin), 2) self.assertEqual(square.area(), 8.0)
def test_simple_square(self): square = Polygon(vertex_positions=[ (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), ]) origin = (0.0, 0.0) self.assertEqual(square.winding_number(origin), 1) self.assertEqual(square.area(), 4.0)
def test_clockwise_square(self): square = Polygon( vertex_positions=[ (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), ][::-1] ) origin = (0.0, 0.0) self.assertEqual(square.winding_number(origin), -1) self.assertEqual(square.area(), -4.0)
def test_double_square(self): square = Polygon( vertex_positions=[ (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), ] * 2 ) origin = (0.0, 0.0) self.assertEqual(square.winding_number(origin), 2) self.assertEqual(square.area(), 8.0)
def test_simple_square(self): square = Polygon( vertex_positions=[ (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), ] ) origin = (0.0, 0.0) self.assertEqual(square.winding_number(origin), 1) self.assertEqual(square.area(), 4.0)
def test_numpy_compatibility(self): square = Polygon(vertex_positions=numpy.array( [ [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0], ], dtype=numpy.float64, )) origin = numpy.array([0.0, 0.0], dtype=numpy.float64) self.assertEqual(square.winding_number(origin), 1) self.assertEqual(square.area(), 4.0)
def test_numpy_compatibility(self): square = Polygon( vertex_positions=numpy.array( [ [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0], ], dtype=numpy.float64, ) ) origin = numpy.array([0.0, 0.0], dtype=numpy.float64) self.assertEqual(square.winding_number(origin), 1) self.assertEqual(square.area(), 4.0)
def test_right_angle_triangle_area_correct(self): points = [[1, 1], [3, 3], [3, 1]] expected_area = 2 poly = Polygon(points) self.assertEqual(expected_area, poly.area())
def test_rectangle_area_correct(self): points = [[0, 0], [0, 3], [1, 3], [1, 0]] expected_area = 3 poly = Polygon(points) self.assertEqual(expected_area, poly.area())
def test_square_area_correct(self): points = [[0, 0], [0, 1], [1, 1], [1, 0]] expected_area = 1 poly = Polygon(points) self.assertEqual(expected_area, poly.area())