from functools import partial from typing import (List, Optional, Tuple) from ground.hints import (Point, Scalar, Segment) from hypothesis import strategies from locus.core.hilbert import MAX_COORDINATE from locus.segmental import Tree from tests.strategies import (scalars_strategies, to_points, to_segments) from tests.utils import Strategy MIN_SEGMENTS_SIZE = 2 max_children_counts = (strategies.sampled_from( [2**power for power in range(1, 10)]) | strategies.integers(2, MAX_COORDINATE)) segments_strategies = scalars_strategies.map(to_segments) segments_lists = (segments_strategies.flatmap( partial(strategies.lists, min_size=MIN_SEGMENTS_SIZE))) trees = strategies.builds(Tree, segments_lists, max_children=max_children_counts) 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,
from functools import partial from typing import (List, Optional, Tuple) from ground.hints import (Box, Scalar) from hypothesis import strategies from locus.core.hilbert import MAX_COORDINATE from locus.r import Tree from tests.strategies import (scalars_strategies, to_boxes, to_points) from tests.utils import (Point, Strategy) MIN_BOXES_SIZE = 2 max_children_counts = (strategies.sampled_from( [2**power for power in range(1, 10)]) | strategies.integers(2, MAX_COORDINATE)) boxes_strategies = scalars_strategies.map(to_boxes) boxes_lists = (boxes_strategies.flatmap( partial(strategies.lists, min_size=MIN_BOXES_SIZE))) trees = strategies.builds(Tree, boxes_lists, max_children=max_children_counts) 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,
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)))
from hypothesis import strategies from tests.port_tests.factories import (scalars_to_nested_ported_sweep_events, scalars_to_ported_sweep_events) from tests.port_tests.hints import PortedSweepLineKey from tests.strategies import scalars_strategies from tests.utils import (identity, to_builder, to_pairs, to_triplets) sweep_events_strategies = ( scalars_strategies.map(scalars_to_ported_sweep_events)) sweep_events = sweep_events_strategies.flatmap(identity) sweep_line_keys_strategies = (sweep_events_strategies.map( to_builder(PortedSweepLineKey))) sweep_line_keys = sweep_line_keys_strategies.flatmap(identity) sweep_line_keys_pairs = sweep_line_keys_strategies.flatmap(to_pairs) sweep_line_keys_triplets = sweep_line_keys_strategies.flatmap(to_triplets) nested_sweep_events_strategies = ( scalars_strategies.map(scalars_to_nested_ported_sweep_events)) nested_sweep_line_keys_strategies = (nested_sweep_events_strategies.map( to_builder(PortedSweepLineKey))) nested_sweep_line_keys = nested_sweep_line_keys_strategies.flatmap(identity) nested_sweep_line_keys_pairs = ( nested_sweep_line_keys_strategies.flatmap(to_pairs)) non_sweep_line_keys = strategies.builds(object)
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)) polygons = polygons_strategies.flatmap(identity) polygons_pairs = polygons_strategies.flatmap(to_pairs) polygons_triplets = polygons_strategies.flatmap(to_triplets)
from tests.port_tests.factories import (scalars_to_ported_points_pairs, scalars_to_ported_segments) from tests.strategies import scalars_strategies from tests.utils import (identity, to_pairs, to_triplets) points_pairs = scalars_strategies.flatmap(scalars_to_ported_points_pairs) segments_strategies = scalars_strategies.map(scalars_to_ported_segments) segments = segments_strategies.flatmap(identity) segments_pairs = segments_strategies.flatmap(to_pairs) segments_triplets = segments_strategies.flatmap(to_triplets)
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))) non_empty_sweep_events_lists_with_indices_and_booleans_lists = ( non_empty_sweep_events_lists.flatmap( to_sweep_events_lists_with_indices_and_booleans_lists)) nested_sweep_events_lists = strategies.lists(nested_sweep_events) non_degenerate_nested_sweep_events = ( nested_sweep_events.filter(is_sweep_event_non_degenerate)) nested_sweep_events_pairs = (scalars_strategies.map( scalars_to_nested_ported_sweep_events).flatmap(to_pairs)) nested_sweep_events_pairs = ( nested_sweep_events_pairs.filter(are_non_overlapping_ported_sweep_events) | nested_sweep_events_pairs.filter( are_sweep_events_pair_with_different_polygon_types)) operations_types = ported_operations_types polygons = scalars_strategies.flatmap(scalars_to_ported_polygons) def scalars_to_trivial_operations( scalars: Strategy[Scalar]) -> Strategy[PortedOperation]: empty_polygons = strategies.builds(PortedPolygon, strategies.builds(list)) polygons = scalars_to_ported_polygons(scalars) non_empty_polygons = scalars_to_ported_polygons(scalars, min_size=1) def to_operation_with_non_overlapping_arguments(