-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_cHaversine.py
More file actions
48 lines (38 loc) · 1.47 KB
/
test_cHaversine.py
File metadata and controls
48 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import print_function
import math
from cHaversine import haversine
import unittest
paris = (48.8567, 2.3508)
london = (51.5072, 0.1275)
tokyo = (35.6833, 139.6833)
cape_town = (-33.9253, 18.4239)
denver = (39.7392, -104.9903)
santiago = (-70.6667, -33.45)
class TestCHaversine(unittest.TestCase):
def test_paris_to_cape_town(self):
dist = haversine(paris, cape_town)
known_dist = 9336 * 1000
self.assertTrue(abs(dist - known_dist) < 5000)
def test_tokyo_to_santiago(self):
dist = haversine(tokyo, santiago)
known_dist = 16090 * 1000
self.assertTrue(abs(dist - known_dist) < 5000)
def test_0_to_1(self):
dist = haversine((0, 0), (1, 1))
known_dist = 156900
self.assertTrue(abs(dist - known_dist) < 1000)
def test_small_distance(self):
# floats will store these two coordinates as the same value, resulting
# in dist = 0.
# doubles are able to distinguish these two points.
dist = haversine((39, -88.97223382), (39, -88.972237))
self.assertTrue(dist > 0)
def test_same_coords(self):
# distance between a coord and itself should not be NaN
dist = haversine((39.11, -86.7), (39.11, -86.7))
self.assertFalse(math.isnan(dist))
def test_very_small_distance(self):
dist = haversine((39.8862855,-86.0395778),(39.8862855,-86.0395777))
self.assertFalse(math.isnan(dist))
if __name__ == '__main__':
unittest.main()