def test_all_lon_in_point_one_increments(self): acc = 3 random.seed(360) total_length = 0 count = 0 max = 0 min = 999999 for i in range (-1800,1800): count = count + 1 test_lat = (random.random() * 180) - 90 test_lon = i / 10 geohexa = latlon_to_geohexa(test_lat, test_lon, accuracy=acc) if (len(geohexa) > max): max = len(geohexa) if (len(geohexa) < min): min = len(geohexa) lat, lon = geohexa_to_latlon(geohexa) error = distance(test_lat, test_lon, lat, lon) self.assertTrue (error < acc) total_length = total_length + len(geohexa) self.assertEqual (max, 10) print('\nTotal length of geohexa for all lon in 0.1 increments at', acc, 'meter accuracy:',total_length) print('Average length of geohexa:', total_length/count) print('Min length of geohexa:', min) print('Max length of geohexa:', max, '\n')
def test_geohexa_to_latlon_within_specification(self): lat, lon = geohexa_to_latlon('zz') self.assertTrue( isinstance(lat, float) ) self.assertTrue( isinstance(lon, float) ) self.assertTrue( lat >= -90) self.assertTrue( lat <= 90) self.assertTrue( lon >= -180) self.assertTrue( lon <= 180)
def test_four_digit_geohexa(self): lat, lon = geohexa_to_latlon('Qarj') self.assertTrue( isinstance(lat, float) ) self.assertTrue( isinstance(lon, float) ) self.assertTrue (lon != 0) self.assertTrue (lat != 0) geohexa = latlon_to_geohexa(lat,lon, 0) self.assertTrue (geohexa.lower() == 'Qarj'.lower())
def test_many_random_lat_lons_near_north_pole(self): random.seed(42) total_length = 0 for i in range (0,MANY): test_lat = (random.random() * 10) + 80 test_lon = (random.random() * 360) - 180 geohexa = latlon_to_geohexa(test_lat, test_lon, accuracy=ACCURACY) lat, lon = geohexa_to_latlon(geohexa) error = distance(test_lat, test_lon, lat, lon) self.assertTrue (error < ACCURACY) total_length = total_length + len(geohexa) print('\nTotal length of geohexa for', MANY, 'random co-ordinates near the North Pole at', ACCURACY, 'meter accuracy:',total_length) print('Average length of geohexa:', total_length/MANY, '\n')
def test_latlon_to_geohexa_and_back_accuracy_for_millimeter(self): test_lat, test_lon = -46.896522, 168.130336 # NZ Oyster Bar geohexa = latlon_to_geohexa(test_lat, test_lon, accuracy=MM) lat, lon = geohexa_to_latlon(geohexa) error = distance(test_lat, test_lon, lat, lon) self.assertTrue (error < MM)
def test_latlon_to_geohexa_and_back_accuracy_for_meter(self): test_lat, test_lon = 64.123565, -21.805507 # Reykjavik Brewery geohexa = latlon_to_geohexa(test_lat, test_lon, accuracy=METER) lat, lon = geohexa_to_latlon(geohexa) error = distance(test_lat, test_lon, lat, lon) self.assertTrue (error < METER)
def test_latlon_to_geohexa_and_back_accuracy_for_ten_km(self): test_lat, test_lon = 1.285864, 103.851831 # Singapore Boat Quay geohexa = latlon_to_geohexa(test_lat, test_lon, accuracy=TEN_KM) lat, lon = geohexa_to_latlon(geohexa) error = distance(test_lat, test_lon, lat, lon) self.assertTrue (error < TEN_KM)
def test_all_third_and_fourth_digit_geohexa(self): for c in base36digits: for d in base36digits: lat, lon = geohexa_to_latlon('00'+c+d) geohexa = latlon_to_geohexa(lat, lon) self.assertEqual(geohexa.lower(), '00'+c+d)
def test_all_two_digit_geohexa(self): for c in base36digits: for d in base36digits: lat, lon = geohexa_to_latlon(c+d) geohexa = latlon_to_geohexa(lat, lon) self.assertEqual(geohexa.lower(), c+d)
def test_three_digit_geohexa(self): lat, lon = geohexa_to_latlon('Tim') self.assertTrue( isinstance(lat, float) ) self.assertTrue( isinstance(lon, float) )
def test_single_null_geohexa(self): lat, lon = geohexa_to_latlon('') self.assertTrue (lat == 0) self.assertTrue (lon == 0)
def test_case_insensitive_input_ok(self): lat1, lon1 = geohexa_to_latlon('iilloo') lat2, lon2 = geohexa_to_latlon('IILLOO') self.assertTrue (lat1 == lat2) self.assertTrue (lon1 == lon2)