from typing import Tuple

from hypothesis import given

from gon.base import (Point,
                      Polygon)
from tests.utils import (equivalence,
                         implication)
from . import strategies


@given(strategies.polygons)
def test_vertices(polygon: Polygon) -> None:
    assert all(vertex in polygon
               for vertex in polygon.border.vertices)
    assert all(vertex in polygon
               for hole in polygon.holes
               for vertex in hole.vertices)


@given(strategies.polygons_with_points)
def test_convex_hull(polygon_with_point: Tuple[Polygon, Point]) -> None:
    polygon, point = polygon_with_point

    assert implication(point in polygon, point in polygon.convex_hull)


@given(strategies.polygons_with_points)
def test_indexing(polygon_with_point: Tuple[Polygon, Point]) -> None:
    polygon, point = polygon_with_point

    before_indexing = point in polygon

    polygon.index()

    after_indexing = point in polygon

    assert equivalence(before_indexing, after_indexing)

[((12, 1, 12, 27), 'hypothesis.given', 'given', ({(12, 7, 12, 26): 'strategies.polygons'}, {}), '(strategies.polygons)', False, 'from hypothesis import given\n'), ((21, 1, 21, 39), 'hypothesis.given', 'given', ({(21, 7, 21, 38): 'strategies.polygons_with_points'}, {}), '(strategies.polygons_with_points)', False, 'from hypothesis import given\n'), ((28, 1, 28, 39), 'hypothesis.given', 'given', ({(28, 7, 28, 38): 'strategies.polygons_with_points'}, {}), '(strategies.polygons_with_points)', False, 'from hypothesis import given\n'), ((25, 11, 25, 70), 'tests.utils.implication', 'implication', ({(25, 23, 25, 39): '(point in polygon)', (25, 41, 25, 69): '(point in polygon.convex_hull)'}, {}), '(point in polygon, point in polygon.convex_hull)', False, 'from tests.utils import equivalence, implication\n'), ((38, 11, 38, 55), 'tests.utils.equivalence', 'equivalence', ({(38, 23, 38, 38): 'before_indexing', (38, 40, 38, 54): 'after_indexing'}, {}), '(before_indexing, after_indexing)', False, 'from tests.utils import equivalence, implication\n')]