2014-09-21 19:45:43 +02:00
|
|
|
import pytest
|
|
|
|
|
from pyhamtools.locator import latlong_to_locator
|
|
|
|
|
from pyhamtools.consts import LookupConventions as const
|
|
|
|
|
|
|
|
|
|
class Test_latlong_to_locator():
|
|
|
|
|
|
|
|
|
|
def test_latlong_to_locator_edge_cases(self):
|
|
|
|
|
assert latlong_to_locator(-89.97916, -179.95833) == "AA00AA"
|
|
|
|
|
assert latlong_to_locator(89.97916, 179.9583) == "RR99XX"
|
|
|
|
|
|
2024-06-01 00:33:10 +02:00
|
|
|
def test_latlong_to_locator_4chars_precision(self):
|
|
|
|
|
|
|
|
|
|
assert latlong_to_locator(48.52083, 9.3750000, precision=4) == "JN48"
|
|
|
|
|
assert latlong_to_locator(39.222916, -86.45416, 4) == "EM69"
|
|
|
|
|
|
|
|
|
|
def test_latlong_to_locator_6chars_precision(self):
|
2014-09-21 19:45:43 +02:00
|
|
|
|
|
|
|
|
assert latlong_to_locator(48.52083, 9.3750000) == "JN48QM"
|
|
|
|
|
assert latlong_to_locator(48.5, 9.0) == "JN48MM" #center of the square
|
2024-06-01 00:33:10 +02:00
|
|
|
assert latlong_to_locator(39.222916, -86.45416, 6) == "EM69SF"
|
|
|
|
|
|
|
|
|
|
def test_latlong_to_locator_8chars_precision(self):
|
|
|
|
|
assert latlong_to_locator(48.51760, 9.40345, precision=8) == "JN48QM84"
|
|
|
|
|
assert latlong_to_locator(39.222916, -86.45416, 4) == "EM69SF53"
|
2014-09-21 19:45:43 +02:00
|
|
|
|
|
|
|
|
def test_latlong_to_locator_invalid_characters(self):
|
|
|
|
|
|
2018-01-27 19:52:27 +01:00
|
|
|
# throws ValueError in Python2 and TypeError in Python3
|
|
|
|
|
with pytest.raises(Exception):
|
2014-09-21 19:45:43 +02:00
|
|
|
latlong_to_locator("JN48QM", "test")
|
|
|
|
|
|
2018-01-27 19:52:27 +01:00
|
|
|
# throws ValueError in Python2 and TypeError in Python3
|
|
|
|
|
with pytest.raises(Exception):
|
2014-09-21 19:45:43 +02:00
|
|
|
latlong_to_locator("", "")
|
|
|
|
|
|
|
|
|
|
def test_latlong_to_locator_out_of_boundry(self):
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
|
latlong_to_locator(-90, -180)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
|
latlong_to_locator(90, 180)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
|
latlong_to_locator(10000, 120000)
|