Devuan fork of gpsd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
5.1 KiB

  1. #!/usr/bin/env python
  2. #
  3. # Test gps/misc.py
  4. #
  5. # This code runs compatibly under Python 2 and 3.x for x >= 2.
  6. # Preserve this property!
  7. from __future__ import absolute_import, print_function, division
  8. import sys
  9. import gps.misc
  10. errors = 0
  11. # values from here: https://en.wikipedia.org/wiki/Decimal_degrees#Precision
  12. # Note the wikipedia numbers are NOT ellipsoid corrected:
  13. # EarthDistanceSmall() is ellipsoid corrected.
  14. tests = [
  15. # slow convergence
  16. (0.00000000, 0.00000000, 0.50000000, 179.5000000, 19936288),
  17. # failure to converge, happens at antipodal points
  18. # fall back to EarthDistanceSmall()
  19. # the real answer should be 19944127
  20. (0.00000000, 0.00000000, 0.50000000, 179.7000000, 19870094),
  21. # boston to new york
  22. (42.3541165, -71.0693514, 40.7791472, -73.9680804, 298396),
  23. # equator 10 degree
  24. (0.00000000, 0.00000000, 10.00000000, 0.00000000, 1105854),
  25. (0.00000000, 0.00000000, 0.00000000, 10.00000000, 1113194),
  26. (0.00000000, 0.00000000, 10.00000000, 10.00000000, 1565109),
  27. # 23N 10 degree
  28. (23.00000000, 0.00000000, 33.00000000, 0.00000000, 1108210),
  29. (23.00000000, 0.00000000, 23.00000000, 10.00000000, 1025026),
  30. (23.00000000, 0.00000000, 33.00000000, 10.00000000, 1480049),
  31. # 45N 10 degree
  32. (45.00000000, 0.00000000, 55.00000000, 0.00000000, 1112285),
  33. (45.00000000, 0.00000000, 45.00000000, 10.00000000, 787967),
  34. (45.00000000, 0.00000000, 55.00000000, 10.00000000, 1320437),
  35. # 67N 10 degree
  36. (67.00000000, 0.00000000, 77.00000000, 0.00000000, 1115839),
  37. (67.00000000, 0.00000000, 67.00000000, 10.00000000, 435729),
  38. (67.00000000, 0.00000000, 77.00000000, 10.00000000, 1164036),
  39. # equator 5 degree
  40. (0.00000000, 0.00000000, 5.00000000, 0.00000000, 552885),
  41. (0.00000000, 0.00000000, 0.00000000, 5.00000000, 556597),
  42. (0.00000000, 0.00000000, 5.00000010, 5.00000000, 784028),
  43. # 23N 5 degree
  44. (23.00000000, 0.00000000, 28.00000000, 0.00000000, 553904),
  45. (23.00000000, 0.00000000, 23.00000000, 5.00000000, 512587),
  46. (23.00000000, 0.00000000, 28.00000000, 5.00000000, 747800),
  47. # 45N 5 degree
  48. (45.00000000, 0.00000000, 50.00000000, 0.00000000, 555902),
  49. (45.00000000, 0.00000000, 45.00000000, 5.00000000, 394171),
  50. (45.00000000, 0.00000000, 50.00000000, 5.00000000, 671179),
  51. # 67N 5 degree
  52. (67.00000000, 0.00000000, 72.00000000, 0.00000000, 557775),
  53. (67.00000000, 0.00000000, 67.00000000, 5.00000000, 218040),
  54. (67.00000000, 0.00000000, 72.00000000, 5.00000000, 590565),
  55. # equator 1 degree
  56. (0.00000000, 0.00000000, 1.00000000, 0.00000000, 110574),
  57. (0.00000000, 0.00000000, 0.00000000, 1.00000000, 111319),
  58. (0.00000000, 0.00000000, 1.00000010, 1.00000000, 156899),
  59. # 23N 1 degree
  60. (23.00000000, 0.00000000, 24.00000000, 0.00000000, 110751),
  61. (23.00000000, 0.00000000, 23.00000000, 1.00000000, 102522),
  62. (23.00000000, 0.00000000, 24.00000000, 1.00000000, 150659),
  63. # 45N 1 degree
  64. (45.00000000, 0.00000000, 46.00000000, 0.00000000, 111141),
  65. (45.00000000, 0.00000000, 45.00000000, 1.00000000, 78846),
  66. (45.00000000, 0.00000000, 46.00000000, 1.00000000, 135869),
  67. # 67N 1 degree
  68. (67.00000000, 0.00000000, 68.00000000, 0.00000000, 111528),
  69. (67.00000000, 0.00000000, 67.00000000, 1.00000000, 43619),
  70. (67.00000000, 0.00000000, 68.00000000, 1.00000000, 119427),
  71. # equator 10e-7
  72. (0.00000000, 0.00000000, 0.00000010, 0.00000000, 0.011057),
  73. (0.00000000, 0.00000000, 0.00000000, 0.00000010, 0.011132),
  74. (0.00000000, 0.00000000, 0.00000010, 0.00000010, 0.015690),
  75. # 23N 10e-7
  76. (23.00000000, 0.00000000, 23.00000010, 0.00000000, 0.011074),
  77. (23.00000000, 0.00000000, 23.00000000, 0.00000010, 0.010252),
  78. (23.00000000, 0.00000000, 23.00000010, 0.00000010, 0.015091),
  79. # 45N 10e-7
  80. (45.00000000, 0.00000000, 45.00000010, 0.00000000, 0.011113),
  81. (45.00000000, 0.00000000, 45.00000000, 0.00000010, 0.007885),
  82. (45.00000000, 0.00000000, 45.00000010, 0.00000010, 0.013626),
  83. # 67N 10e-7
  84. (67.00000000, 0.00000000, 67.00000010, 0.00000000, 0.011152),
  85. (67.00000000, 0.00000000, 67.00000000, 0.00000010, 0.004360),
  86. (67.00000000, 0.00000000, 67.00000010, 0.00000010, 0.011974),
  87. ]
  88. # EarthDistanceSmall
  89. for (lat1, lon1, lat2, lon2, dist) in tests:
  90. distance = gps.misc.EarthDistanceSmall((lat1, lon1), (lat2, lon2))
  91. # compare to 1%
  92. diff = dist - distance
  93. max_diff = dist * 0.01
  94. if abs(diff) > max_diff:
  95. sys.stderr.write(
  96. "misc small: %.8f %.8f, %.8f %.8f, expected %.7f got %.7f\n"
  97. % (lat1, lon1, lat2, lon2, dist, distance))
  98. errors += 1
  99. # EarthDistance
  100. for (lat1, lon1, lat2, lon2, dist) in tests:
  101. distance = gps.misc.EarthDistance((lat1, lon1), (lat2, lon2))
  102. # compare to 0.001%
  103. diff = dist - distance
  104. max_diff = dist * 0.00001
  105. if abs(diff) > max_diff:
  106. sys.stderr.write(
  107. "misc large: %.8f %.8f, %.8f %.8f, expected %.7f got %.7f\n"
  108. % (lat1, lon1, lat2, lon2, dist, distance))
  109. errors += 1
  110. if errors:
  111. print("test_misc.py: failed")
  112. sys.exit(1)
  113. else:
  114. print("test_misc.py: OK")
  115. sys.exit(0)