Exemplo n.º 1
0
def scalars_to_trees_with_boxes(
        scalars: Strategy[Scalar],
        *,
        min_size: int = MIN_BOXES_SIZE,
        max_size: Optional[int] = None) -> Strategy[Tuple[Tree, Box]]:
    boxes = to_boxes(scalars)
    return strategies.tuples(
        strategies.builds(Tree,
                          strategies.lists(boxes,
                                           min_size=min_size,
                                           max_size=max_size),
                          max_children=max_children_counts), boxes)


trees_with_boxes = scalars_strategies.flatmap(scalars_to_trees_with_boxes)


def scalars_to_trees_with_points(
        scalars: Strategy[Scalar],
        *,
        min_size: int = MIN_BOXES_SIZE,
        max_size: Optional[int] = None) -> Strategy[Tuple[Tree, Point]]:
    return (strategies.tuples(
        strategies.builds(Tree,
                          strategies.lists(to_boxes(scalars),
                                           min_size=min_size,
                                           max_size=max_size),
                          max_children=max_children_counts),
        to_points(scalars)))
Exemplo n.º 2
0
from functools import partial

from hypothesis import strategies

from tests.port_tests.factories import scalars_to_ported_polygons
from tests.port_tests.hints import PortedPolygon
from tests.port_tests.utils import (ported_operations_types,
                                    to_non_overlapping_ported_polygons_pair)
from tests.strategies import scalars_strategies
from tests.utils import (identity, pack, to_pairs)

operations_types = ported_operations_types
empty_polygons = strategies.builds(PortedPolygon, strategies.builds(list))
polygons = scalars_strategies.flatmap(scalars_to_ported_polygons)
non_empty_polygons_strategies = (scalars_strategies.map(
    partial(scalars_to_ported_polygons, min_size=1)))
non_empty_polygons = non_empty_polygons_strategies.flatmap(identity)
polygons_pairs = (strategies.tuples(empty_polygons, non_empty_polygons)
                  | strategies.tuples(non_empty_polygons, empty_polygons)
                  | non_empty_polygons_strategies.flatmap(to_pairs).map(
                      pack(to_non_overlapping_ported_polygons_pair)))
Exemplo n.º 3
0
def scalars_to_trees_with_segments(
        scalars: Strategy[Scalar],
        *,
        min_size: int = MIN_SEGMENTS_SIZE,
        max_size: Optional[int] = None) -> Strategy[Tuple[Tree, Segment]]:
    segments = to_segments(scalars)
    return strategies.tuples(
        strategies.builds(Tree,
                          strategies.lists(segments,
                                           min_size=min_size,
                                           max_size=max_size),
                          max_children=max_children_counts), segments)


trees_with_segments = (
    scalars_strategies.flatmap(scalars_to_trees_with_segments))


def scalars_to_trees_with_points(
        scalars: Strategy[Scalar],
        *,
        min_size: int = MIN_SEGMENTS_SIZE,
        max_size: Optional[int] = None) -> Strategy[Tuple[Tree, Point]]:
    return (strategies.tuples(
        strategies.builds(Tree,
                          strategies.lists(to_segments(scalars),
                                           min_size=min_size,
                                           max_size=max_size),
                          max_children=max_children_counts),
        to_points(scalars)))
Exemplo n.º 4
0
from typing import List

from hypothesis import strategies

from tests.port_tests.factories import (scalars_to_ported_points,
                                        scalars_to_ported_points_lists)
from tests.port_tests.hints import (PortedContour, PortedPoint, PortedPolygon)
from tests.strategies import (booleans, non_negative_integers,
                              non_negative_integers_lists, scalars_strategies)
from tests.utils import (MAX_CONTOURS_COUNT, Strategy, identity, to_builder,
                         to_pairs, to_triplets)

booleans = booleans
non_negative_integers = non_negative_integers
non_negative_integers_lists = non_negative_integers_lists
points = scalars_strategies.flatmap(scalars_to_ported_points)


def to_contours(
        points_lists: Strategy[List[PortedPoint]],
        holes_lists: Strategy[List[int]] = non_negative_integers_lists,
        are_externals: Strategy[bool] = booleans) -> Strategy[PortedContour]:
    return strategies.builds(PortedContour, points_lists, holes_lists,
                             are_externals)


contours_lists_strategies = (scalars_strategies.map(
    scalars_to_ported_points_lists).map(to_contours).map(
        partial(strategies.lists, max_size=MAX_CONTOURS_COUNT)))
contours_lists = contours_lists_strategies.flatmap(identity)
polygons_strategies = contours_lists_strategies.map(to_builder(PortedPolygon))
Exemplo n.º 5
0
from typing import Tuple

from hypothesis import strategies

from tests.port_tests.hints import PortedBoundingBox
from tests.strategies import scalars_strategies
from tests.utils import (Scalar,
                         Strategy)


def scalars_to_quadruples(scalars: Strategy[Scalar]
                          ) -> Strategy[Tuple[Scalar, Scalar, Scalar, Scalar]]:
    return strategies.tuples(scalars, scalars, scalars, scalars)


scalars_quadruples = scalars_strategies.flatmap(scalars_to_quadruples)


def scalars_to_bounding_boxes(scalars: Strategy[Scalar]
                              ) -> Strategy[PortedBoundingBox]:
    return strategies.builds(PortedBoundingBox, scalars, scalars, scalars,
                             scalars)


bounding_boxes = scalars_strategies.flatmap(scalars_to_bounding_boxes)
Exemplo n.º 6
0
from typing import Tuple

from hypothesis import strategies

from tests.port_tests.factories import (scalars_to_ported_points,
                                        scalars_to_ported_points_pairs,
                                        scalars_to_ported_points_triplets)
from tests.strategies import scalars_strategies
from tests.utils import (Scalar,
                         Strategy)


def scalars_to_pairs(scalars: Strategy[Scalar]
                     ) -> Strategy[Tuple[Scalar, Scalar]]:
    return strategies.tuples(scalars, scalars)


scalars_pairs = scalars_strategies.flatmap(scalars_to_pairs)
points = scalars_strategies.flatmap(scalars_to_ported_points)
points_pairs = scalars_strategies.flatmap(scalars_to_ported_points_pairs)
points_triplets = scalars_strategies.flatmap(scalars_to_ported_points_triplets)
Exemplo n.º 7
0
                                        scalars_to_ported_polygons,
                                        scalars_to_ported_sweep_events)
from tests.port_tests.hints import (PortedOperation, PortedOperationType,
                                    PortedPolygon, PortedSweepEvent)
from tests.port_tests.utils import (are_non_overlapping_ported_sweep_events,
                                    ported_operations_types,
                                    to_non_overlapping_ported_polygons_pair)
from tests.strategies import (booleans, scalars_strategies)
from tests.utils import (Scalar, Strategy,
                         are_sweep_events_pair_with_different_polygon_types,
                         cleave_in_tuples, compose, identity,
                         is_sweep_event_non_degenerate,
                         to_double_nested_sweep_events, to_maybe, to_pairs,
                         to_triplets)

points = scalars_strategies.flatmap(scalars_to_ported_points)
sweep_events = scalars_strategies.flatmap(scalars_to_ported_sweep_events)
nested_sweep_events = (
    scalars_strategies.flatmap(scalars_to_nested_ported_sweep_events))
maybe_nested_sweep_events = to_maybe(nested_sweep_events)
non_empty_sweep_events_lists = strategies.lists(sweep_events, min_size=1)


def to_sweep_events_lists_with_indices_and_booleans_lists(
    events: List[PortedSweepEvent]
) -> Strategy[Tuple[List[PortedSweepEvent], int, List[bool]]]:
    return strategies.tuples(
        strategies.just(events), strategies.integers(0,
                                                     len(events) - 1),
        strategies.lists(booleans, min_size=len(events), max_size=len(events)))
Exemplo n.º 8
0
from tests.port_tests.factories import (scalars_to_acyclic_ported_sweep_events,
                                        scalars_to_nested_ported_sweep_events,
                                        scalars_to_plain_ported_sweep_events,
                                        scalars_to_ported_points,
                                        scalars_to_ported_sweep_events)
from tests.port_tests.utils import (ported_edges_types, ported_polygons_types)
from tests.strategies import (booleans, non_negative_integers,
                              scalars_strategies)
from tests.utils import (cleave_in_tuples, identity, to_maybe, to_pairs,
                         to_triplets)

booleans = booleans
non_negative_integers = non_negative_integers
polygons_types = ported_polygons_types
edges_types = ported_edges_types
points = scalars_strategies.flatmap(scalars_to_ported_points)
leaf_sweep_events = (scalars_strategies.flatmap(
    partial(scalars_to_plain_ported_sweep_events, children=strategies.none())))
leaf_sweep_events_with_points = scalars_strategies.flatmap(
    cleave_in_tuples(
        partial(scalars_to_plain_ported_sweep_events,
                children=strategies.none()), scalars_to_ported_points))
acyclic_sweep_events = (
    scalars_strategies.flatmap(scalars_to_acyclic_ported_sweep_events))
sweep_events_strategies = (
    scalars_strategies.map(scalars_to_ported_sweep_events))
sweep_events = sweep_events_strategies.flatmap(identity)
sweep_events_pairs = sweep_events_strategies.flatmap(to_pairs)
sweep_events_triplets = sweep_events_strategies.flatmap(to_triplets)
nested_sweep_events = (
    scalars_strategies.flatmap(scalars_to_nested_ported_sweep_events))