Mercurial > hg > GlobalNeighbors
diff tests/test_distance.py @ 3:49aae0c0293b
improved test coverage
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 14:48:31 -0700 |
parents | 1b94f3bf97e5 |
children | 254195d0bac2 |
line wrap: on
line diff
--- a/tests/test_distance.py Sat Jun 24 14:04:00 2017 -0700 +++ b/tests/test_distance.py Sat Jun 24 14:48:31 2017 -0700 @@ -10,6 +10,7 @@ from globalneighbors import distance from globalneighbors.constants import Rearth from globalneighbors.locations import locations +from globalneighbors.read import read_cities from globalneighbors.read import read_city_list from globalneighbors.schema import primary_key @@ -17,6 +18,7 @@ data = os.path.join(here, 'data') full_tsv_lines = 149092 + class DistanceTests(unittest.TestCase): # created with @@ -28,6 +30,9 @@ full_tsv = os.path.join(data, 'cities1000.txt') full_tsv_lines = 149092 + # here's a smaller one + moderate_tsv = os.path.join(data, '10000cities.tsv') + def test_haversine(self): # a simple canned case @@ -102,6 +107,26 @@ for i in range(1, len(distances)): assert distances[i] >= distances[i-1] + def test_10000cities(self): + """a moderate size test""" + + assert os.path.exists(self.moderate_tsv) + with open(self.moderate_tsv) as f: + cities = locations(read_cities(f)) + + # test over different values of # of neighbors + for k in (10, 100, 1000): + neighbors = distance.calculate_neighbors(cities, + k=k) + + # ensure you have no more neighbors than you ask for + assert max([len(value) for value in neighbors.values()]) <= k + + # assert distances increase + for value in neighbors.values(): + distances = [i[-1] for i in value] + assert distances == sorted(distances) + if __name__ == '__main__': unittest.main()