54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
"""This module asserts correct runtime behaviour of the :mod:`pyrate.plan.geometry` primitives for
|
|
locations, polygons and trajectories.
|
|
|
|
Quite a few tests are marked with ``@settings(max_examples=<some small count>)`` since this test suite makes
|
|
up a very large part of the total testing time and some tests just don't justify wasting many resources on
|
|
them due to very simple code being tested.
|
|
"""
|
|
|
|
# Python standard math
|
|
from math import isclose
|
|
|
|
# Typing
|
|
from typing import Union
|
|
|
|
# Hypothesis testing
|
|
from hypothesis import HealthCheck
|
|
from hypothesis import settings
|
|
|
|
# Package under test
|
|
from pyrate.plan.geometry import PolarLocation
|
|
from pyrate.plan.geometry import PolarPolygon
|
|
from pyrate.plan.geometry import PolarRoute
|
|
|
|
|
|
#: Tests that require the generation of cartesian routes are slow since the generation of examples is slow.
|
|
#: As polar routes, cartesian polygons and polar polygons depend on this, they are also run at reduced rate.
|
|
slow_route_max_examples = settings(
|
|
max_examples=int(settings().max_examples * 0.1), suppress_health_check=(HealthCheck.too_slow,)
|
|
)
|
|
|
|
|
|
#: A test that only tests very few examples since the property to be tested is rather trivial and we do not
|
|
#: want to invest significant amounts of time into it.
|
|
simple_property_only_few_examples = settings(
|
|
max_examples=int(max(5, settings().max_examples * 0.001)), suppress_health_check=(HealthCheck.too_slow,)
|
|
)
|
|
|
|
|
|
def is_near_special_point(polar_location: PolarLocation, tolerance: float = 1e-6) -> bool:
|
|
"""Checks if the given ``polar_location`` is within ``tolerance`` of the poles or +/- 180° longitude."""
|
|
return (
|
|
isclose(polar_location.latitude, -90, abs_tol=tolerance)
|
|
or isclose(polar_location.latitude, +90, abs_tol=tolerance)
|
|
or isclose(polar_location.longitude, -180, abs_tol=tolerance)
|
|
or isclose(polar_location.longitude, +180, abs_tol=tolerance)
|
|
)
|
|
|
|
|
|
def is_any_near_special_point(
|
|
polar_line_object: Union[PolarPolygon, PolarRoute], tolerance: float = 1e-6
|
|
) -> bool:
|
|
"""Checks if any point in in the given geometry ``is_near_special_point`` within the ``tolerance``."""
|
|
return any(is_near_special_point(location, tolerance) for location in polar_line_object.locations)
|