def test_neighbours_center(self): lat_lon = _location.LatLon(0, 0) self.assertEqual( lat_lon.neighbours(), set([ _location.LatLon(-1, -2), _location.LatLon(-1, 0), _location.LatLon(-1, 2), _location.LatLon(0, -2), _location.LatLon(0, 2), _location.LatLon(1, -2), _location.LatLon(1, 0), _location.LatLon(1, 2) ]))
def test_neighbours_right_end(self): lat_lon = _location.LatLon(48, 180) self.assertEqual( lat_lon.neighbours(), set([ _location.LatLon(47, 178), _location.LatLon(47, 180), _location.LatLon(47, -178), _location.LatLon(48, 178), _location.LatLon(48, -178), _location.LatLon(49, 178), _location.LatLon(49, 180), _location.LatLon(49, -178) ]))
def test_neighbours_somewhere_in_the_middle(self): lat_lon = _location.LatLon(48, 10) self.assertEqual( lat_lon.neighbours(), set([ _location.LatLon(47, 8), _location.LatLon(47, 10), _location.LatLon(47, 12), _location.LatLon(48, 8), _location.LatLon(48, 12), _location.LatLon(49, 8), _location.LatLon(49, 10), _location.LatLon(49, 12) ]))
def test_hash_int(self): hashes = set() conflicts = [] for lat in range(-90, 91): for lon in range(-180, 180): lat_lon = _location.LatLon(lat, lon) h = hash(lat_lon) if lat_lon in hashes: print("conflict {}".format(lat_lon)) conflicts.append(lat_lon) else: hashes.add(lat_lon) self.assertEqual( len(conflicts), 0, "{} conflicting {}".format(len(hashes), len(conflicts)))
def test_neighbours_bottom_end(self): lat_lon = _location.LatLon(-90, 10) self.assertEqual( lat_lon.neighbours(), set([ _location.LatLon(-89, 8), _location.LatLon(-89, 10), _location.LatLon(-89, 12), _location.LatLon(-90, 8), _location.LatLon(-90, 12), ]))