test_location.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import pytest
  2. from termux_log_location import *
  3. @pytest.mark.parametrize(('a', 'hav'), [
  4. [math.pi*0, 0 ],
  5. [math.pi/2, 1/2],
  6. [math.pi*1, 1 ],
  7. [math.pi*3/2, 1/2],
  8. [math.pi*2, 0 ],
  9. [math.pi/-2, 1/2],
  10. [math.pi*-1, 1 ],
  11. [math.pi*-3/2, 1/2],
  12. [math.pi*-2, 0 ],
  13. ])
  14. def test_haversine(a, hav):
  15. assert Location.haversine(a) == pytest.approx(hav)
  16. @pytest.mark.parametrize(('a'), [0, 1, 2, math.pi])
  17. def test_haversine_inv(a):
  18. assert Location.haversine_inv(Location.haversine(a)) == pytest.approx(a)
  19. LINZ = Location(latitude=48.3069, longitude=14.2858, altitude=266)
  20. INNSBRUCK = Location(latitude=47.2692, longitude=11.4041, altitude=574)
  21. STEPHENS_CATHEDRAL = Location(latitude=48.2084, longitude=16.3735, altitude=178)
  22. VIENNA_STATE_OPERA = Location(latitude=48.2033, longitude=16.3692, altitude=173)
  23. @pytest.mark.parametrize(('a', 'b', 'd'), [
  24. [INNSBRUCK, LINZ, 244238],
  25. [LINZ, INNSBRUCK, 244238],
  26. [STEPHENS_CATHEDRAL, LINZ, 154938],
  27. [STEPHENS_CATHEDRAL, VIENNA_STATE_OPERA, 650],
  28. ])
  29. def test_haversine_distance_metres(a, b, d):
  30. assert Location.haversine_distance_metres(a, b) == pytest.approx(d, abs=1)