Skip to content

Commit

Permalink
add test_get_polygon_boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikmi committed Feb 2, 2024
1 parent 026354f commit f30c478
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
36 changes: 34 additions & 2 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

from tests.auxiliaries import time_preprocess
from tests.locations import BASIC_TEST_LOCATIONS, BOUNDARY_TEST_CASES, TEST_LOCATIONS
from timezonefinder.configs import INT2COORD_FACTOR, THRES_DTYPE_H, TIMEZONE_NAMES_FILE
from timezonefinder.configs import (
INT2COORD_FACTOR,
MAX_LAT_VAL_INT,
MAX_LNG_VAL_INT,
THRES_DTYPE_H,
TIMEZONE_NAMES_FILE,
)
from timezonefinder.timezonefinder import (
AbstractTimezoneFinder,
TimezoneFinder,
Expand Down Expand Up @@ -56,6 +62,14 @@ def check_pairwise_geometry(geometry_obj: List):
assert len(first_coord_pair) == 2, "the polygon does not consist of coordinate pairs as expected."


def is_valid_lng_int(x: int) -> bool:
return -MAX_LNG_VAL_INT <= x <= MAX_LNG_VAL_INT


def is_valid_lat_int(y: int) -> bool:
return -MAX_LAT_VAL_INT <= y <= MAX_LAT_VAL_INT


# tests for TimezonefinderL class
class BaseTimezoneFinderClassTest(unittest.TestCase):
in_memory_mode = False
Expand Down Expand Up @@ -216,7 +230,7 @@ def test_shortcut_boundary_result(self):
self.check_boundary(lng, lat, expected)

def test_certain_timezone_at(self):
print("\ntestin certain_timezone_at():") # expected equal results to timezone_at(), is just slower
print("\ntesting certain_timezone_at():") # expected equal results to timezone_at(), is just slower
self.run_location_tests(self.test_instance.certain_timezone_at, self.test_locations)

def test_overflow(self):
Expand Down Expand Up @@ -282,6 +296,24 @@ def test_get_geometry(self):
self.test_instance.get_geometry(tz_name=None, tz_id=nr_timezones, use_id=True, coords_as_pairs=False)
self.test_instance.get_geometry(tz_name="", tz_id=-1, use_id=True, coords_as_pairs=False)

# TODO add unit tests for all other binary data reading functions (all possible inputs)
def test_get_polygon_boundaries(self):
# boundaries should be defined for each polygon
instance = self.test_instance
nr_of_polygons = instance.nr_of_polygons
for poly_id in range(nr_of_polygons):
boundaries = instance.get_polygon_boundaries(poly_id=poly_id)
assert isinstance(boundaries, tuple)
assert len(boundaries) == 4
xmax, xmin, ymax, ymin = boundaries
# test value range:
assert is_valid_lat_int(ymin)
assert is_valid_lat_int(ymax)
assert is_valid_lng_int(xmin)
assert is_valid_lng_int(xmax)
assert ymin < ymax
assert xmin < xmax


class TimezonefinderClassTestMEM(TimezonefinderClassTest):
in_memory_mode = True
Expand Down
4 changes: 3 additions & 1 deletion timezonefinder/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
COORD2INT_FACTOR = 10**DECIMAL_PLACES_SHIFT
MAX_LNG_VAL = 180.0
MAX_LAT_VAL = 90.0
MAX_INT_VAL = int(MAX_LNG_VAL * COORD2INT_FACTOR)
MAX_LNG_VAL_INT = int(MAX_LNG_VAL * COORD2INT_FACTOR)
MAX_LAT_VAL_INT = int(MAX_LAT_VAL * COORD2INT_FACTOR)
MAX_INT_VAL = MAX_LNG_VAL_INT
assert MAX_INT_VAL < MAX_ALLOWED_COORD_VAL

# TYPES
Expand Down

0 comments on commit f30c478

Please sign in to comment.