first version of weather loader
This commit is contained in:
37
apps/weather/src/tests.py
Normal file
37
apps/weather/src/tests.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import unittest
|
||||
|
||||
from utils import format_coord, parse_coord
|
||||
|
||||
|
||||
class TestCoordinateFormatting(unittest.TestCase):
|
||||
|
||||
def test_round_trip(self):
|
||||
cases = [
|
||||
(52.25, 4.0, "N5225E0400"),
|
||||
(-13.5, -122.0, "S1350W12200"),
|
||||
(0.0, 0.0, "N0000E0000"),
|
||||
(51.75, 6.5, "N5175E0650"),
|
||||
(-0.25, 0.25, "S0025E0025"),
|
||||
]
|
||||
for lat, lon, expected in cases:
|
||||
with self.subTest(lat=lat, lon=lon):
|
||||
self.assertEqual(format_coord(lat, lon), expected)
|
||||
parsed_lat, parsed_lon = parse_coord(expected)
|
||||
print(f"Parsed: {parsed_lat}, {parsed_lon} from {expected}")
|
||||
self.assertAlmostEqual(parsed_lat, lat, places=6)
|
||||
self.assertAlmostEqual(parsed_lon, lon, places=6)
|
||||
|
||||
def test_invalid_length(self):
|
||||
with self.assertRaises(ValueError):
|
||||
parse_coord("N52E4") # too short, malformed
|
||||
|
||||
def test_negative_coordinates(self):
|
||||
coord = format_coord(-52.25, -4.0)
|
||||
self.assertEqual(coord, "S5225W0400")
|
||||
lat, lon = parse_coord(coord)
|
||||
self.assertAlmostEqual(lat, -52.25, places=6)
|
||||
self.assertAlmostEqual(lon, -4.0, places=6)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user