def test_equality(self): """testing if two polygons with the same vertices are equal""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 0) p3 = shapes.Point(1, 1) p4 = shapes.Point(0, 1) instance1 = shapes.Polygon(p1, p2, p3, p4) instance2 = shapes.Polygon(p1, p2, p3, p4) self.assertEqual(instance1, instance2)
def test_equality2(self): """testing if two polygon with the same vertices but with different order of entering those vertices are equal""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 0) p3 = shapes.Point(1, 1) p4 = shapes.Point(0, 1) instance1 = shapes.Polygon(p1, p2, p3, p4) instance2 = shapes.Polygon(p4, p3, p2, p1) self.assertEqual(instance1, instance2)
def test_for_polygon_and_polygon4(self): """the fourth test for checking if a given polygon is located inside another polygon with their edges intersecting each other """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol1 = shapes.Polygon(v1, v2, v3, v4, v5) v6 = shapes.Point(-0.5, -3) v7 = shapes.Point(-0.5, 3) v8 = shapes.Point(-5, 0) pol2 = shapes.Polygon(v6, v7, v8) self.assertFalse(operations.is_inside(pol2, pol1))
def test_for_polygon_and_polygon5(self): """the fifth test for checking if a given polygon is located inside another polygon with them being fully apart """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol1 = shapes.Polygon(v1, v2, v3, v4, v5) v6 = shapes.Point(-5, 5) v7 = shapes.Point(-5, 6) v8 = shapes.Point(-4, 5.5) pol2 = shapes.Polygon(v6, v7, v8) self.assertFalse(operations.is_inside(pol2, pol1))
def test_for_polygon_and_polygon3(self): """the third test for checking if a given polygon is located inside another given polygon with the first one being inside the second one but touching it in one vertex """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol1 = shapes.Polygon(v1, v2, v3, v4, v5) v6 = shapes.Point(-0.5, 0) v7 = shapes.Point(0.5, 0) v8 = shapes.Point(0, 1) pol2 = shapes.Polygon(v6, v7, v8) self.assertFalse(operations.is_inside(pol2, pol1))
def test_for_polygon_and_polygon2(self): """the second test to check if a given polygon is located inside another given polygon, with the second one being loceted inside the first one """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol1 = shapes.Polygon(v1, v2, v3, v4, v5) v6 = shapes.Point(-0.5, 0) v7 = shapes.Point(0.5, 0) v8 = shapes.Point(0, 0.5) pol2 = shapes.Polygon(v6, v7, v8) self.assertFalse(operations.is_inside(pol1, pol2))
def test_number_of_vertices(self): """testing the number_of_vertices method from Polygon class""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 0) p3 = shapes.Point(1, 1) p4 = shapes.Point(0, 1) instance = shapes.Polygon(p1, p2, p3, p4) self.assertEqual(instance.number_of_vertices, 4)
def test_perimeter(self): """Testing the 'perimeter' method of Polygon class""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 0) p3 = shapes.Point(1, 1) p4 = shapes.Point(0, 1) instance = shapes.Polygon(p1, p2, p3, p4) self.assertEqual(instance.perimeter, 4)
def test_for_line_and_polygon(self): """testing if a given infinite line is located inside a given polygon which should always return False """ line = shapes.Line(1, 0) v1 = shapes.Point(0, 0) v2 = shapes.Point(0, 1) v3 = shapes.Point(1, 1) pol = shapes.Polygon(v1, v2, v3) self.assertFalse(operations.is_inside(line, pol))
def test_for_point_and_rectangle2(self): """the second test for checking if a given point is inside a given rectangle, with the point being located on the perimeter of the rectangle """ point = shapes.Point(0.5, -1) v1 = shapes.Point(-1, -1) v2 = shapes.Point(1, -1) v3 = shapes.Point(1, 1) v4 = shapes.Point(-1, 1) rec = shapes.Polygon(v1, v2, v3, v4) self.assertFalse(operations.is_inside(point, rec))
def test_for_polygon_and_circle5(self): """the fifth test for checking if a given polygon is located inside a given circle with them being fully apart """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) circle = shapes.Circle(shapes.Point(5, 5), 1) self.assertFalse(operations.is_inside(pol, circle))
def test_for_point_and_rectangle1(self): """the first test for checking if a given point is inside a given rectangle, with the point being located inside the rectangle """ point = shapes.Point(0, 0) v1 = shapes.Point(-1, -1) v2 = shapes.Point(1, -1) v3 = shapes.Point(1, 1) v4 = shapes.Point(-1, 1) rec = shapes.Polygon(v1, v2, v3, v4) self.assertTrue(operations.is_inside(point, rec))
def test_for_point_and_rectangle3(self): """the third test for checking if a given point is inside a given rectangle with the point being located outside the rectangle """ point = shapes.Point(5, 5) v1 = shapes.Point(-1, -1) v2 = shapes.Point(1, -1) v3 = shapes.Point(1, 1) v4 = shapes.Point(-1, 1) rec = shapes.Polygon(v1, v2, v3, v4) self.assertFalse(operations.is_inside(point, rec))
def test_for_polygon_and_line(self): """test for checking if a given polygon is located inside a given line which should always return False """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) line = shapes.Line(1, 0) self.assertFalse(operations.is_inside(pol, line))
def test_for_point_and_polygon3(self): """the third test for checking if a given point is inside a given polygon, with the point being located outside the polygon """ point = shapes.Point(5, 5) v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) self.assertFalse(operations.is_inside(point, pol))
def test_for_polygon_and_point1(self): """the first test for checking if a given polygon is inside a given point, with the point being located inside the polygon """ point = shapes.Point(0, 0) v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) self.assertFalse(operations.is_inside(pol, point))
def test_for_circle_and_polygon3(self): """the third test for checking if a given circle is located inside a given polygon with the circle intersecting the polygon """ circle = shapes.Circle(shapes.Point(0, -3), 2) v1 = shapes.Point(-2, -2) v2 = shapes.Point(0, -4) v3 = shapes.Point(2, -2) v4 = shapes.Point(2, 2) v5 = shapes.Point(0, 4) v6 = shapes.Point(-2, 2) pol = shapes.Polygon(v1, v2, v3, v4, v5, v6) self.assertFalse(operations.is_inside(circle, pol))
def test_for_polygon_and_circle2(self): """the second test for checking if a given polygon is located inside a given circle with the circle being completely inside the polygon """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) circle = shapes.Circle(shapes.Point(0, 0), 0.1) self.assertFalse(operations.is_inside(pol, circle))
def test_for_polygon_and_circle4(self): """the fourth test for checking if a given polygon is located inside a given circle with the polygon being partly inside the circle but intersecting with it """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(pol, circle))
def test_for_polygon_and_circle3(self): """the third test for checking if a given polygon is located inside a given circle with the polygon being inside the circle but with one vertex touching the circle's perimeter """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -0.1) v3 = shapes.Point(0.1, -0.1) v4 = shapes.Point(0.1, 0) v5 = shapes.Point(0, 0.1) pol = shapes.Polygon(v1, v2, v3, v4, v5) circle = shapes.Circle(shapes.Point(0, 0), 1) self.assertFalse(operations.is_inside(pol, circle))
def test_for_circle_and_polygon4(self): """the fourth test for checking if a given circle is located inside a given polygon with them being fully apart """ circle = shapes.Circle(shapes.Point(10, 10), 1) v1 = shapes.Point(-2, -2) v2 = shapes.Point(0, -4) v3 = shapes.Point(2, -2) v4 = shapes.Point(2, 2) v5 = shapes.Point(0, 4) v6 = shapes.Point(-2, 2) pol = shapes.Polygon(v1, v2, v3, v4, v5, v6) self.assertFalse(operations.is_inside(circle, pol))
def test_for_polygon_and_circle1(self): """the first test for checking if a polygon is located inside a given circle with the polygon being located inside the circle completely """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) circle = shapes.Circle(shapes.Point(0, 0), 5) self.assertTrue(operations.is_inside(pol, circle))
def test_for_circle_and_polygon2(self): """the second test for checking if a given circle is located inside a given polygon with the circle being inside the polygon but touching one of its edges """ circle = shapes.Circle(shapes.Point(-1, 0), 2) v1 = shapes.Point(-2, -2) v2 = shapes.Point(0, -4) v3 = shapes.Point(2, -2) v4 = shapes.Point(2, 2) v5 = shapes.Point(0, 4) v6 = shapes.Point(-2, 2) pol = shapes.Polygon(v1, v2, v3, v4, v5, v6) self.assertFalse(operations.is_inside(circle, pol))
def test_for_circle_and_polygon1(self): """the first test for checking if a given circle is located inside a given polygon with the circle being fully inside the polygon """ circle = shapes.Circle(shapes.Point(0, 0), 1) v1 = shapes.Point(-2, -2) v2 = shapes.Point(0, -4) v3 = shapes.Point(2, -2) v4 = shapes.Point(2, 2) v5 = shapes.Point(0, 4) v6 = shapes.Point(-2, 2) pol = shapes.Polygon(v1, v2, v3, v4, v5, v6) self.assertTrue(operations.is_inside(circle, pol))
def test_edges(self): """Testing the 'edges' method from Polygon class""" p1 = shapes.Point(0, 0) p2 = shapes.Point(1, 0) p3 = shapes.Point(1, 1) p4 = shapes.Point(0, 1) instance = shapes.Polygon(p1, p2, p3, p4) expected = ( shapes.LineSegment(p4, p1), shapes.LineSegment(p1, p2), shapes.LineSegment(p2, p3), shapes.LineSegment(p3, p4), ) self.assertEqual(instance.edges, expected)
def test_for_linesegment_and_polygon4(self): """the fourth test for checking if a given line segment is located inside a given polygon with them being fully apart """ end1 = shapes.Point(10, 10) end2 = shapes.Point(11, 11) line = shapes.LineSegment(end1, end2) v1 = shapes.Point(-2, -2) v2 = shapes.Point(0, -4) v3 = shapes.Point(2, -2) v4 = shapes.Point(2, 2) v5 = shapes.Point(0, 4) v6 = shapes.Point(-2, 2) pol = shapes.Polygon(v1, v2, v3, v4, v5, v6) self.assertFalse(operations.is_inside(line, pol))
def test_for_polygon_and_rectangle4(self): """the fourth test for checking if a given polygon is located inside a given rectangle with their edges intersecting each other """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) v6 = shapes.Point(-0.5, 2) v7 = shapes.Point(-0.5, -2) v8 = shapes.Point(4, -2) v9 = shapes.Point(4, 2) rec = shapes.Rectangle(v6, v7, v8, v9) self.assertFalse(operations.is_inside(pol, rec))
def test_for_linesegment_and_polygon3(self): """the third test for checking if a given line segment is located inside a given polygon with the line segment intersecting the polygon """ end1 = shapes.Point(0, 1) end2 = shapes.Point(3, 2) line = shapes.LineSegment(end1, end2) v1 = shapes.Point(-2, -2) v2 = shapes.Point(0, -4) v3 = shapes.Point(2, -2) v4 = shapes.Point(2, 2) v5 = shapes.Point(0, 4) v6 = shapes.Point(-2, 2) pol = shapes.Polygon(v1, v2, v3, v4, v5, v6) self.assertFalse(operations.is_inside(line, pol))
def test_for_linesegment_and_polygon1(self): """the first test for checking if a given line segment is located inside a given polygon with the line segment being fully inside the polygon """ end1 = shapes.Point(0, 0) end2 = shapes.Point(1, 1) line = shapes.LineSegment(end1, end2) v1 = shapes.Point(-2, -2) v2 = shapes.Point(0, -4) v3 = shapes.Point(2, -2) v4 = shapes.Point(2, 2) v5 = shapes.Point(0, 4) v6 = shapes.Point(-2, 2) pol = shapes.Polygon(v1, v2, v3, v4, v5, v6) self.assertTrue(operations.is_inside(line, pol))
def test_for_polygon_and_rectangle5(self): """the fifth test for checking if a given polygon is located inside a given rectangle with them being fully apart """ v1 = shapes.Point(-1, 0) v2 = shapes.Point(0, -1) v3 = shapes.Point(1, -1) v4 = shapes.Point(1, 0) v5 = shapes.Point(0, 1) pol = shapes.Polygon(v1, v2, v3, v4, v5) v6 = shapes.Point(3.5, 2) v7 = shapes.Point(3.5, -2) v8 = shapes.Point(4, -2) v9 = shapes.Point(4, 2) rec = shapes.Rectangle(v6, v7, v8, v9) self.assertFalse(operations.is_inside(pol, rec))