mirror of
https://github.com/dh1tw/pyhamtools.git
synced 2026-04-07 07:24:03 +00:00
support for 4, 6, 8 char precision maidenhead locator conversions
# fixes bug report #30
This commit is contained in:
parent
84d88faf69
commit
5ec3461d03
7 changed files with 188 additions and 47 deletions
|
|
@ -14,7 +14,12 @@ class Test_calculate_distance():
|
|||
|
||||
assert abs(calculate_distance("JN48QM", "FN44AB") - 5965) < 1
|
||||
assert abs(calculate_distance("FN44AB", "JN48QM") - 5965) < 1
|
||||
assert abs(calculate_distance("JN48QM", "QF67bf") - 16467) < 1
|
||||
assert abs(calculate_distance("JN48QM", "QF67BF") - 16467) < 1
|
||||
assert abs(calculate_distance("JN48QM84", "QF67BF84") - 16467) < 1
|
||||
assert abs(calculate_distance("JN48QM84", "QF67BF") - 16464) < 1
|
||||
assert abs(calculate_distance("JN48QM84", "QF67") - 16506) < 1
|
||||
assert abs(calculate_distance("JN48QM", "QF67") - 16508) < 1
|
||||
assert abs(calculate_distance("JN48", "QF67") - 16535) < 1
|
||||
|
||||
def test_calculate_distance_invalid_inputs(self):
|
||||
with pytest.raises(AttributeError):
|
||||
|
|
|
|||
|
|
@ -8,10 +8,20 @@ class Test_latlong_to_locator():
|
|||
assert latlong_to_locator(-89.97916, -179.95833) == "AA00AA"
|
||||
assert latlong_to_locator(89.97916, 179.9583) == "RR99XX"
|
||||
|
||||
def test_latlong_to_locator_normal_case(self):
|
||||
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):
|
||||
|
||||
assert latlong_to_locator(48.52083, 9.3750000) == "JN48QM"
|
||||
assert latlong_to_locator(48.5, 9.0) == "JN48MM" #center of the square
|
||||
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"
|
||||
|
||||
def test_latlong_to_locator_invalid_characters(self):
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import pytest
|
||||
import maidenhead
|
||||
from pyhamtools.locator import locator_to_latlong
|
||||
from pyhamtools.consts import LookupConventions as const
|
||||
|
||||
|
||||
class Test_locator_to_latlong():
|
||||
|
||||
def test_locator_to_latlong_edge_cases(self):
|
||||
def test_locator_to_latlong_min_max_cases(self):
|
||||
latitude, longitude = locator_to_latlong("AA00AA")
|
||||
assert abs(latitude + 89.97916) < 0.00001
|
||||
assert abs(longitude +179.95833) < 0.0001
|
||||
|
|
@ -13,23 +15,71 @@ class Test_locator_to_latlong():
|
|||
assert abs(latitude - 89.97916) < 0.00001
|
||||
assert abs(longitude - 179.9583) < 0.0001
|
||||
|
||||
def test_locator_to_latlong_normal_case(self):
|
||||
|
||||
latitude, longitude = locator_to_latlong("JN48QM")
|
||||
assert abs(latitude - 48.52083) < 0.00001
|
||||
assert abs(longitude - 9.3750000) < 0.0001
|
||||
def test_locator_to_latlong_4chars_precision(self):
|
||||
|
||||
latitude, longitude = locator_to_latlong("JN48")
|
||||
assert abs(latitude - 48.5) < 0.001
|
||||
assert abs(longitude - 9.000) < 0.001
|
||||
assert abs(latitude - 48.5) < 0.1
|
||||
assert abs(longitude - 9.0) < 0.1
|
||||
|
||||
def test_locator_to_latlong_mixed_signs(self):
|
||||
latitude, longitude = locator_to_latlong("JN48", center=False)
|
||||
assert abs(latitude - 48) < 0.1
|
||||
assert abs(longitude - 8) < 0.1
|
||||
|
||||
def test_locator_to_latlong_6chars_precision(self):
|
||||
latitude, longitude = locator_to_latlong("JN48QM")
|
||||
assert abs(latitude - 48.52083) < 0.00001
|
||||
assert abs(longitude - 9.37500) < 0.00001
|
||||
|
||||
def test_locator_to_latlong_8chars(self):
|
||||
|
||||
latitude, longitude = locator_to_latlong("JN48QM84")
|
||||
assert abs(latitude - 48.51875) < 0.00001
|
||||
assert abs(longitude - 9.40416) < 0.00001
|
||||
|
||||
latitude, longitude = locator_to_latlong("EM69SF53")
|
||||
assert abs(latitude - 39.222916) < 0.00001
|
||||
assert abs(longitude + 86.45416) < 0.00001
|
||||
|
||||
def test_locator_to_latlong_consistency_checks_6chars_lower_left_corner(self):
|
||||
|
||||
latitude_4, longitude_4 = locator_to_latlong("JN48", center=False)
|
||||
latitude_6, longitude_6 = locator_to_latlong("JN48AA", center=False)
|
||||
|
||||
assert latitude_4 == latitude_6
|
||||
assert longitude_4 == longitude_6
|
||||
|
||||
def test_locator_to_latlong_consistency_checks_8chars_lower_left_corner(self):
|
||||
|
||||
latitude_6, longitude_6 = locator_to_latlong("JN48AA", center=False)
|
||||
latitude_8, longitude_8 = locator_to_latlong("JN48AA00", center=False)
|
||||
|
||||
assert latitude_6 == latitude_8
|
||||
assert longitude_6 == longitude_8
|
||||
|
||||
def test_locator_to_latlong_consistency_checks_against_maidenhead(self):
|
||||
|
||||
locs = ["JN48", "EM69", "JN48QM", "EM69SF", "AA00AA", "RR99XX", "JN48QM84", "EM69SF53"]
|
||||
|
||||
# lower left (south/east) corner
|
||||
for loc in locs:
|
||||
lat, lon = locator_to_latlong(loc, center=False)
|
||||
lat_m, lon_m = maidenhead.to_location(loc)
|
||||
assert abs(lat - lat_m) < 0.00001
|
||||
assert abs(lon - lon_m) < 0.00001
|
||||
|
||||
# center of square
|
||||
for loc in locs:
|
||||
lat, lon = locator_to_latlong(loc) # default: center=True
|
||||
lat_m, lon_m = maidenhead.to_location(loc, center=True)
|
||||
assert abs(lat - lat_m) < 0.1
|
||||
assert abs(lon - lon_m) < 0.1
|
||||
|
||||
def test_locator_to_latlong_upper_lower_chars(self):
|
||||
|
||||
latitude, longitude = locator_to_latlong("Jn48qM")
|
||||
assert abs(latitude - 48.52083) < 0.00001
|
||||
assert abs(longitude - 9.3750000) < 0.0001
|
||||
|
||||
|
||||
def test_locator_to_latlong_wrong_amount_of_characters(self):
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
|
|
@ -43,12 +93,27 @@ class Test_locator_to_latlong():
|
|||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("JN8Q")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("JN8QM1")
|
||||
|
||||
def test_locator_to_latlong_invalid_characters(self):
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("21XM99")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("48")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("JNJN")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("JN4848")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("JN48QMaa")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
latitude, longitude = locator_to_latlong("****")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue