Beispiel #1
0
def test_properties(data: DataObject,
                    coordinates_limits_type_pair: Tuple[ScalarsLimitsType,
                                                        ScalarsLimitsType],
                    sizes_pair: SizesPair) -> None:
    (x_coordinates_limits_type,
     y_coordinates_limits_type) = coordinates_limits_type_pair
    ((x_coordinates, (min_x_value, max_x_value)),
     x_type) = x_coordinates_limits_type
    ((y_coordinates, (min_y_value, max_y_value)),
     y_type) = y_coordinates_limits_type
    min_size, max_size = sizes_pair

    strategy = multisegments(x_coordinates,
                             y_coordinates,
                             min_size=min_size,
                             max_size=max_size)

    result = data.draw(strategy)

    assert is_multisegment(result)
    assert has_valid_size(result.segments,
                          min_size=min_size,
                          max_size=max_size)
    assert multisegment_has_coordinates_types(result,
                                              x_type=x_type,
                                              y_type=y_type)
    assert multisegment_has_coordinates_in_range(result,
                                                 min_x_value=min_x_value,
                                                 max_x_value=max_x_value,
                                                 min_y_value=min_y_value,
                                                 max_y_value=max_y_value)
    assert segments_do_not_cross_or_overlap(result.segments)
Beispiel #2
0
def test_same_coordinates(data: DataObject,
                          coordinates_limits_type: ScalarsLimitsType,
                          sizes_pair: SizesPair) -> None:
    (coordinates, (min_value, max_value)), type_ = coordinates_limits_type
    min_size, max_size = sizes_pair

    strategy = multisegments(coordinates, min_size=min_size, max_size=max_size)

    result = data.draw(strategy)

    assert is_multisegment(result)
    assert has_valid_size(result.segments,
                          min_size=min_size,
                          max_size=max_size)
    assert multisegment_has_coordinates_types(result,
                                              x_type=type_,
                                              y_type=type_)
    assert multisegment_has_coordinates_in_range(result,
                                                 min_x_value=min_value,
                                                 max_x_value=max_value,
                                                 min_y_value=min_value,
                                                 max_y_value=max_value)
    assert segments_do_not_cross_or_overlap(result.segments)
Beispiel #3
0
def coordinates_to_polygons_with_multisegments(
        coordinates: Strategy[Scalar]) -> Strategy[PolygonWithMultisegment]:
    return strategies.tuples(planar.polygons(coordinates),
                             planar.multisegments(coordinates))
Beispiel #4
0
def coordinates_to_multisegments_with_segments(
        coordinates: Strategy[Scalar]) -> Strategy[MultisegmentWithSegment]:
    return strategies.tuples(planar.multisegments(coordinates),
                             planar.segments(coordinates))
Beispiel #5
0
def test_invalid_sizes(coordinates: Strategy[Scalar],
                       invalid_sizes_pair: SizesPair) -> None:
    min_size, max_size = invalid_sizes_pair

    with pytest.raises(ValueError):
        multisegments(coordinates, min_size=min_size, max_size=max_size)
Beispiel #6
0
def test_basic(coordinates: Strategy[Scalar], sizes_pair: SizesPair) -> None:
    min_size, max_size = sizes_pair

    result = multisegments(coordinates, min_size=min_size, max_size=max_size)

    assert isinstance(result, Strategy)
Beispiel #7
0
def coordinates_to_multipolygons_with_multisegments(
    coordinates: Strategy[Coordinate]
) -> Strategy[Tuple[Multipolygon, Multisegment]]:
    return strategies.tuples(planar.multipolygons(coordinates),
                             planar.multisegments(coordinates))
Beispiel #8
0
def to_multisegments_with_points(
        coordinates: Strategy[Scalar]) -> Strategy[Tuple[Multisegment, Point]]:
    return strategies.tuples(planar.multisegments(coordinates),
                             planar.points(coordinates))
Beispiel #9
0
            PortedSegment(PortedPoint(raw.start.x, raw.start.y),
                          PortedPoint(raw.end.x, raw.end.y)))


segments_pairs = planar.segments(coordinates).map(raw_segment_to_segments_pair)


def points_pair_to_coordinates(points_pair: BoundPortedPointsPair
                               ) -> Tuple[int, int]:
    bound, _ = points_pair
    return bound.x, bound.y


multipoints_pairs = planar.multipoints(coordinates).map(
        to_bound_ported_multipoints_pair)
multisegments_pairs = (planar.multisegments(coordinates)
                       .map(to_bound_ported_multisegments_pair))
source_categories_pairs = strategies.sampled_from(
        list(zip(bound_source_categories, ported_source_categories)))
site_events_pairs = strategies.builds(to_bound_with_ported_site_events_pair,
                                      points_pairs, points_pairs, sizes, sizes,
                                      booleans, source_categories_pairs)
site_events_lists_pairs = (strategies.lists(site_events_pairs)
                           .map(transpose_pairs))
empty_lists_pairs = to_pairs(strategies.builds(list))
empty_builders_pairs = strategies.builds(to_bound_with_ported_builders_pair,
                                         sizes, empty_lists_pairs)


def to_valid_multipoints_builders_pair(builders: BoundPortedBuildersPair,
                                       multipoints: BoundPortedPointsListsPair
                                       ) -> BoundPortedBuildersPair:
Beispiel #10
0
from hypothesis import strategies
from hypothesis_geometry import planar

from tests.port_tests.hints import (PortedCell, PortedDiagram, PortedEdge,
                                    PortedVertex)
from tests.port_tests.utils import (ported_source_categories,
                                    to_ported_multipoint,
                                    to_ported_multisegment)
from tests.strategies import (doubles, integers_32, sizes)
from tests.utils import to_maybe

booleans = strategies.booleans()
coordinates = doubles
empty_diagrams = strategies.builds(PortedDiagram)
source_categories = strategies.sampled_from(ported_source_categories)
cells = strategies.builds(PortedCell, sizes, source_categories)
vertices = strategies.builds(PortedVertex, coordinates, coordinates)
edges = strategies.builds(PortedEdge, to_maybe(vertices), cells, booleans,
                          booleans)
cells_lists = strategies.lists(cells)
edges_lists = strategies.lists(edges)
vertices_lists = strategies.lists(vertices)
diagrams = strategies.builds(PortedDiagram, cells_lists, edges_lists,
                             vertices_lists)
multipoints = planar.multipoints(integers_32).map(to_ported_multipoint)
multisegments = planar.multisegments(integers_32).map(to_ported_multisegment)