Add tests

Signed-off-by: Dawid SQ6EMM <sq6emm@hamradio.pl>
This commit is contained in:
Dawid SQ6EMM 2025-05-05 10:07:20 +02:00
parent 547ee643c2
commit a67daa1db3
2 changed files with 17 additions and 2 deletions

View file

@ -23,6 +23,10 @@ class Test_latlong_to_locator():
assert latlong_to_locator(48.51760, 9.40345, precision=8) == "JN48QM84"
assert latlong_to_locator(39.222916, -86.45416, 8) == "EM69SF53"
def test_latlong_to_locator_10chars_precision(self):
assert latlong_to_locator(45.83568, 68.52518, precision=10) == "MN45GU30AN"
assert latlong_to_locator(51.12492, 16.94183, 10) == "JO81LC39AX"
def test_latlong_to_locator_invalid_characters(self):
# throws ValueError in Python2 and TypeError in Python3

View file

@ -30,8 +30,7 @@ class Test_locator_to_latlong():
assert abs(latitude - 48.52083) < 0.00001
assert abs(longitude - 9.37500) < 0.00001
def test_locator_to_latlong_8chars(self):
def test_locator_to_latlong_8chars_precision(self):
latitude, longitude = locator_to_latlong("JN48QM84")
assert abs(latitude - 48.51875) < 0.00001
assert abs(longitude - 9.40416) < 0.00001
@ -40,6 +39,15 @@ class Test_locator_to_latlong():
assert abs(latitude - 39.222916) < 0.00001
assert abs(longitude + 86.45416) < 0.00001
def test_locator_to_latlong_10chars_precision(self):
latitude, longitude = locator_to_latlong("JO81LC39AX")
assert abs(latitude - 51.124913) < 0.000001
assert abs(longitude - 16.941840) < 0.000001
latitude, longitude = locator_to_latlong("MN45GU30AN")
assert abs(latitude - 45.835677) < 0.000001
assert abs(longitude - 68.525173) < 0.000001
def test_locator_to_latlong_consistency_checks_6chars_lower_left_corner(self):
latitude_4, longitude_4 = locator_to_latlong("JN48", center=False)
@ -97,6 +105,9 @@ class Test_locator_to_latlong():
with pytest.raises(ValueError):
latitude, longitude = locator_to_latlong("JN8QM1")
with pytest.raises(ValueError):
latitude, longitude = locator_to_latlong("JN8QM1AA")
def test_locator_to_latlong_invalid_characters(self):
with pytest.raises(ValueError):