def test_moving_individual_points(poly: Polygon): assume(len(poly.points) > 3) poly.move_point(0, (25, 25)) assert poly.points[0] == (25, 25)
def test_polygon_closed_property(poly: Polygon): # polygon has to have more points than to be closed assume(len(poly.points) > 2) assert poly.closed == (poly.points[0] == poly.points[-1]) # manually close it & test it worked poly.append(poly.points[0]) assert poly.closed
def test_that_adding_point_close_by_closes(poly: Polygon): assume(len(poly.points) > 3) start_point = poly.points[0] max_dist = poly.close_threshold approximate_nearby = (start_point[0] + max_dist // 2, start_point[1]) poly.append(approximate_nearby) assert poly.closed
def test_that_polygon_doesnt_close_if_only_two_points(poly: Polygon): assume(len(poly.points) == 1) start_point = poly.points[0] max_dist = poly.close_threshold approximate_nearby = (start_point[0] + max_dist // 2, start_point[1]) poly.append(approximate_nearby) assert not poly.closed
def test_polygon_does_not_accept_other_shapes(box: BoundingBox, point: Point): with pytest.raises(ValueError): Polygon.from_data(box.data) with pytest.raises(ValueError): Polygon.from_data(point.data)
def test_polygon_round_trips(poly: Polygon): assert poly == Polygon.from_data(poly.data)
def test_that_polygon_doesnt_close_if_only_two_points(poly: Polygon): if len(poly.points) > 1: poly.points = poly.points[:1] start_point = poly.points[0] max_dist = poly.close_threshold approximate_nearby = (start_point[0] + max_dist // 2, start_point[1]) poly.append(approximate_nearby) assert not poly.closed @given(poly=infer) @example(poly=Polygon()) def test_getting_xy_lists_works(poly: Polygon): xlist, ylist = poly.xy_lists assert all(x == xy[0] for x, xy in zip(xlist, poly.points)) assert all(y == xy[1] for y, xy in zip(ylist, poly.points)) @given(box=infer, point=infer) def test_polygon_does_not_accept_other_shapes(box: BoundingBox, point: Point): with pytest.raises(ValueError): Polygon.from_data(box.data) with pytest.raises(ValueError): Polygon.from_data(point.data)
def polygons(draw): points = strategies.lists(coordinates, min_size=3) label = strategies.text() return Polygon(draw(points), draw(label))