|
@@ -0,0 +1,37 @@
|
|
|
+import pytest
|
|
|
+
|
|
|
+from termux_log_location import *
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(('a', 'hav'), [
|
|
|
+ [math.pi*0, 0 ],
|
|
|
+ [math.pi/2, 1/2],
|
|
|
+ [math.pi*1, 1 ],
|
|
|
+ [math.pi*3/2, 1/2],
|
|
|
+ [math.pi*2, 0 ],
|
|
|
+ [math.pi/-2, 1/2],
|
|
|
+ [math.pi*-1, 1 ],
|
|
|
+ [math.pi*-3/2, 1/2],
|
|
|
+ [math.pi*-2, 0 ],
|
|
|
+])
|
|
|
+def test_haversine(a, hav):
|
|
|
+ assert Location.haversine(a) == pytest.approx(hav)
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(('a'), [0, 1, 2, math.pi])
|
|
|
+def test_haversine_inv(a):
|
|
|
+ assert Location.haversine_inv(Location.haversine(a)) == pytest.approx(a)
|
|
|
+
|
|
|
+LINZ = Location(latitude=48.3069, longitude=14.2858, altitude=266)
|
|
|
+INNSBRUCK = Location(latitude=47.2692, longitude=11.4041, altitude=574)
|
|
|
+STEPHENS_CATHEDRAL = Location(latitude=48.2084, longitude=16.3735, altitude=178)
|
|
|
+VIENNA_STATE_OPERA = Location(latitude=48.2033, longitude=16.3692, altitude=173)
|
|
|
+
|
|
|
+@pytest.mark.parametrize(('a', 'b', 'd'), [
|
|
|
+ [INNSBRUCK, LINZ, 244238],
|
|
|
+ [LINZ, INNSBRUCK, 244238],
|
|
|
+ [STEPHENS_CATHEDRAL, LINZ, 154938],
|
|
|
+ [STEPHENS_CATHEDRAL, VIENNA_STATE_OPERA, 650],
|
|
|
+])
|
|
|
+def test_haversine_distance_metres(a, b, d):
|
|
|
+ assert Location.haversine_distance_metres(a, b) == pytest.approx(d, abs=1)
|