Пример #1
0
def test_moving_individual_points(poly: Polygon):

    assume(len(poly.points) > 3)

    poly.move_point(0, (25, 25))

    assert poly.points[0] == (25, 25)
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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)
Пример #6
0
def test_polygon_round_trips(poly: Polygon):
    assert poly == Polygon.from_data(poly.data)
Пример #7
0
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)
Пример #8
0
def polygons(draw):
    points = strategies.lists(coordinates, min_size=3)
    label = strategies.text()

    return Polygon(draw(points), draw(label))