Added Maidenhead unit tests.

pull/70/head
Christian Jacobs 2018-03-28 18:32:04 +01:00
rodzic 6834673e28
commit 785d3b320f
1 zmienionych plików z 50 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,50 @@
#!/usr/bin/env python3
# Copyright (C) 2018 Christian Thomas Jacobs.
# This file is part of PyQSO.
# PyQSO is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyQSO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyQSO. If not, see <http://www.gnu.org/licenses/>.
import unittest
import os
from pyqso.world_map import *
class TestMaidenhead(unittest.TestCase):
""" The unit tests for the Maidenhead class. """
def setUp(self):
""" Set up the Maidenhead object needed for the unit tests. """
self.maidenhead = Maidenhead()
def test_ll2gs(self):
""" Check that a latitude-longitude coordinate can correctly be converted to a Maidenhead grid square. """
latitude = 51.0593
longitude = -1.4262
assert self.maidenhead.ll2gs(latitude, longitude, subsquare=False) == "IO91"
assert self.maidenhead.ll2gs(latitude, longitude, subsquare=True) == "IO91gb"
def test_gs2ll(self):
gs4 = "JN05"
assert self.maidenhead.gs2ll(gs4) == (45.5, 1.0)
gs6 = "JN05aa"
assert self.maidenhead.gs2ll(gs6) == (45.020833333333336, 0.041666666666666664)
gs6 = "IO91gb"
print(self.maidenhead.gs2ll(gs6))
assert self.maidenhead.gs2ll(gs6) == (51.0625, -1.4583333333333335)
if(__name__ == '__main__'):
unittest.main()