Skip to content

Commit

Permalink
Complete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lycantropos committed Jan 9, 2021
1 parent 5198b63 commit d63e738
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
22 changes: 11 additions & 11 deletions tests/planar_tests/test_segments_intersections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from hypothesis import given

from bentley_ottmann.planar import segments_intersections
from tests.utils import is_point
from tests.utils import (is_point,
segments_pair_intersections)
from . import strategies


Expand Down Expand Up @@ -47,24 +48,23 @@ def test_step(context: Context,
assert (next_result.keys()
== (result.keys()
| set(chain.from_iterable(
context.segments_intersections(last_segment.start,
last_segment.end,
segment.start,
segment.end)
segments_pair_intersections(last_segment.start,
last_segment.end,
segment.start,
segment.end)
for segment in rest_segments))))
assert all(segment_id < next_segment_id == len(segments) - 1
for point, intersections in next_result.items()
for segment_id, next_segment_id in (intersections
- result.get(point, set())))
assert all(
point
in context.segments_intersections(segments[segment_id].start,
assert all(point
in segments_pair_intersections(segments[segment_id].start,
segments[segment_id].end,
segments[next_segment_id].start,
segments[next_segment_id].end)
for point, intersections in next_result.items()
for segment_id, next_segment_id in (intersections
- result.get(point, set())))
for point, intersections in next_result.items()
for segment_id, next_segment_id in (intersections
- result.get(point, set())))


@given(strategies.degenerate_segments_lists)
Expand Down
20 changes: 19 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
Tuple,
TypeVar)

from ground.base import get_context
from ground.base import (Relation,
get_context)
from ground.hints import Coordinate
from hypothesis import strategies
from hypothesis.strategies import SearchStrategy
Expand Down Expand Up @@ -86,3 +87,20 @@ def reverse_segment_coordinates(segment: Segment) -> Segment:

def reverse_point_coordinates(point: Point) -> Point:
return Point(point.y, point.x)


def segments_pair_intersections(first_start: Point,
first_end: Point,
second_start: Point,
second_end: Point) -> Tuple[Point, ...]:
relation = context.segments_relation(first_start, first_end, second_start,
second_end)
if relation is Relation.DISJOINT:
return ()
elif relation is Relation.TOUCH or relation is Relation.CROSS:
return context.segments_intersection(first_start, first_end,
second_start, second_end),
else:
_, first_point, second_point, _ = sorted([first_start, first_end,
second_start, second_end])
return first_point, second_point

0 comments on commit d63e738

Please sign in to comment.