Mercurial > hg > GlobalNeighbors
comparison tests/test_grid.py @ 5:7e27e874655b
test a larger grid + move distance insertion to its own function
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 15:16:10 -0700 |
parents | 49aae0c0293b |
children | 254195d0bac2 |
comparison
equal
deleted
inserted
replaced
4:8e130b7bfed9 | 5:7e27e874655b |
---|---|
7 import os | 7 import os |
8 import unittest | 8 import unittest |
9 from common import datafile | 9 from common import datafile |
10 from globalneighbors.grid import LatLonGrid | 10 from globalneighbors.grid import LatLonGrid |
11 from globalneighbors.locations import locations | 11 from globalneighbors.locations import locations |
12 from globalneighbors.read import read_cities | |
12 from globalneighbors.read import read_city_list | 13 from globalneighbors.read import read_city_list |
13 | 14 |
14 | 15 |
15 class TestGrid(unittest.TestCase): | 16 class TestGrid(unittest.TestCase): |
16 """test gridding functionality""" | 17 """test gridding functionality""" |
42 samplefile = datafile('sample.tsv') | 43 samplefile = datafile('sample.tsv') |
43 assert os.path.exists(samplefile) | 44 assert os.path.exists(samplefile) |
44 city_locations = locations(read_city_list(samplefile)) | 45 city_locations = locations(read_city_list(samplefile)) |
45 self.grid_locations(city_locations) | 46 self.grid_locations(city_locations) |
46 | 47 |
48 def test_10000(self): | |
49 """test 10000 cities""" | |
50 | |
51 filename = datafile('10000cities.tsv') | |
52 assert os.path.exists(filename) | |
53 with open(filename) as f: | |
54 city_locations = locations(read_cities(f)) | |
55 self.grid_locations(city_locations) | |
56 | |
57 | |
47 ### generic (utility) functions | 58 ### generic (utility) functions |
48 | 59 |
49 def grid_locations(self, locations): | 60 def grid_locations(self, locations): |
50 """grid locations + test created grid""" | 61 """grid locations + test created grid""" |
51 | 62 |
61 for i in range(grid.n[0]): | 72 for i in range(grid.n[0]): |
62 for j in range(grid.n[1]): | 73 for j in range(grid.n[1]): |
63 n_locations += len(grid[(i,j)]) | 74 n_locations += len(grid[(i,j)]) |
64 assert n_locations == len(locations) | 75 assert n_locations == len(locations) |
65 | 76 |
77 | |
78 | |
66 if __name__ == '__main__': | 79 if __name__ == '__main__': |
67 unittest.main() | 80 unittest.main() |