def test_invalid_sizes(coordinates: Strategy[Scalar],
                       invalid_sizes_pair: SizesPair) -> None:
    min_size, max_size = invalid_sizes_pair

    with pytest.raises(ValueError):
        contours(coordinates,
                 min_size=min_size,
                 max_size=max_size)
def test_non_valid_sizes(coordinates: Strategy[Scalar],
                         non_valid_sizes_pair: SizesPair) -> None:
    min_size, max_size = non_valid_sizes_pair

    with pytest.warns(HypothesisWarning) as warnings:
        contours(coordinates,
                 min_size=min_size,
                 max_size=max_size)

    assert len(warnings) == 1
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 = contours(coordinates,
                        min_size=min_size,
                        max_size=max_size)

    result = data.draw(strategy)

    assert is_contour(result)
    assert contour_has_valid_sizes(result,
                                   min_size=min_size,
                                   max_size=max_size)
    assert contour_has_coordinates_types(result,
                                         x_type=type_,
                                         y_type=type_)
    assert contour_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 are_vertices_strict(result.vertices)
    assert is_contour_non_self_intersecting(result)
    assert is_contour_counterclockwise(result)
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 = contours(x_coordinates, y_coordinates,
                        min_size=min_size,
                        max_size=max_size)

    result = data.draw(strategy)

    assert is_contour(result)
    assert contour_has_valid_sizes(result,
                                   min_size=min_size,
                                   max_size=max_size)
    assert contour_has_coordinates_types(result,
                                         x_type=x_type,
                                         y_type=y_type)
    assert contour_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 is_contour_strict(result)
    assert is_contour_non_self_intersecting(result)
    assert is_contour_counterclockwise(result)
def test_basic(coordinates: Strategy[Scalar],
               sizes_pair: SizesPair) -> None:
    min_size, max_size = sizes_pair

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

    assert isinstance(result, Strategy)
Exemplo n.º 6
0
from hypothesis import strategies
from hypothesis_geometry import planar

from tests.binding_tests.utils import (bound_fill_kinds, bound_polygon_kinds)
from tests.integration_tests.utils import (
    to_bound_with_ported_linear_rings_pair,
    to_bound_with_ported_multipolygons_pair,
    to_bound_with_ported_points_lists_pair, to_bound_with_ported_polygons_pair,
    to_bound_with_ported_wagyus_pair)
from tests.port_tests.utils import (ported_fill_kinds, ported_polygon_kinds)
from tests.strategies import coordinates

booleans = strategies.booleans()
wagyus_pairs = strategies.builds(to_bound_with_ported_wagyus_pair, booleans)
linear_rings_points_pairs = (
    planar.contours(coordinates).map(to_bound_with_ported_points_lists_pair))
linear_rings_pairs = (
    linear_rings_points_pairs.map(to_bound_with_ported_linear_rings_pair))
polygons_pairs = (
    planar.polygons(coordinates).map(to_bound_with_ported_polygons_pair))
polygon_kinds_pairs = strategies.sampled_from(
    list(zip(bound_polygon_kinds, ported_polygon_kinds)))
multipolygons_pairs = (planar.multipolygons(coordinates).map(
    to_bound_with_ported_multipolygons_pair))
fill_kinds_pairs = strategies.sampled_from(
    list(zip(bound_fill_kinds, ported_fill_kinds)))
Exemplo n.º 7
0
from typing import (List, Tuple)

from hypothesis import strategies
from hypothesis_geometry import planar

from tests.port_tests.utils import (ported_polygon_kinds,
                                    to_ported_linear_rings_points,
                                    to_ported_polygon_linear_rings)
from tests.strategies import coordinates
from tests.utils import Strategy
from wagyu.enums import PolygonKind
from wagyu.linear_ring import LinearRing
from wagyu.local_minimum import LocalMinimumList

linear_rings_points = (
    planar.contours(coordinates).map(to_ported_linear_rings_points))
linear_rings = strategies.builds(LinearRing, linear_rings_points)
polygon_kinds = strategies.sampled_from(ported_polygon_kinds)
linear_rings_lists = (
    planar.polygons(coordinates).map(to_ported_polygon_linear_rings))
empty_local_minimum_lists = strategies.builds(LocalMinimumList)


def to_local_minimum_list(
    linear_rings_with_polygon_kinds: List[Tuple[LinearRing, PolygonKind]]
) -> LocalMinimumList:
    result = LocalMinimumList()
    for linear_ring, polygon_kind in linear_rings_with_polygon_kinds:
        result.add_linear_ring(linear_ring, polygon_kind)
    return result
Exemplo n.º 8
0
from _wagyu import (LinearRing, Polygon, Wagyu)
from hypothesis import strategies
from hypothesis_geometry import planar

from tests.binding_tests.utils import (bound_polygon_kinds,
                                       to_bound_points_list,
                                       to_bound_polygon_linear_rings)
from tests.strategies import coordinates

polygon_kinds = strategies.sampled_from(bound_polygon_kinds)
linear_rings_points = planar.contours(coordinates).map(to_bound_points_list)
linear_rings = strategies.builds(LinearRing, linear_rings_points)
linear_rings_lists = (
    planar.polygons(coordinates).map(to_bound_polygon_linear_rings))
polygons = strategies.builds(Polygon, linear_rings_lists)
empty_wagyus = strategies.builds(Wagyu)
Exemplo n.º 9
0
from sect.triangulation import constrained_delaunay_triangles

from tests.pode_tests.config import (MAX_CONTOUR_SIZE, MAX_COORDINATE,
                                     MAX_HOLES_SIZE, MIN_CONTOUR_SIZE,
                                     MIN_COORDINATE, MIN_HOLES_SIZE)
from pode.utils import joined_constrained_delaunay_triangles

T = TypeVar('T')

TRIANGULAR_CONTOUR_SIZE = 3
RECTANGLE_CONTOUR_SIZE = 4
MIN_PARTITION_SIZE = 1

nonnegative_integers = st.integers(min_value=0)
fractions = st.fractions(MIN_COORDINATE, MAX_COORDINATE)
raw_fraction_contours = planar.contours(fractions)
fractions_contours = st.builds(Contour.from_raw, raw_fraction_contours)
fraction_triangles = st.builds(
    Polygon.from_raw,
    planar.polygons(fractions, max_size=TRIANGULAR_CONTOUR_SIZE))
convex_divisors = st.sampled_from(
    [constrained_delaunay_triangles, joined_constrained_delaunay_triangles])

coordinates_strategies_factories = {
    int: st.integers,
    Fraction: st.fractions,
    float: st.floats
}
coordinates_strategies = st.sampled_from([
    factory(MIN_COORDINATE, MAX_COORDINATE)
    for factory in coordinates_strategies_factories.values()
Exemplo n.º 10
0
from hypothesis_geometry import planar
from hypothesis_geometry.hints import Contour

from tests.strategies import floats
from tests.utils import (BoundPoint,
                         BoundPortedPointsListsPair,
                         PortedPoint)


def to_bound_with_ported_contours(raw: Contour) -> BoundPortedPointsListsPair:
    return ([BoundPoint(x, y) for x, y in raw],
            [PortedPoint(x, y) for x, y in raw])


contours_pairs = planar.contours(floats).map(to_bound_with_ported_contours)