2015-12-19 04:19:48 +01:00
|
|
|
# Project imports
|
|
|
|
import os
|
2015-12-19 09:04:44 +01:00
|
|
|
import random
|
2015-12-19 04:19:48 +01:00
|
|
|
import re
|
2015-12-19 09:04:44 +01:00
|
|
|
import sys
|
2015-12-19 04:19:48 +01:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
|
|
|
|
|
|
|
import helper
|
|
|
|
from elodie import geolocation
|
|
|
|
|
|
|
|
os.environ['TZ'] = 'GMT'
|
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
|
2015-12-19 04:19:48 +01:00
|
|
|
def test_decimal_to_dms():
|
|
|
|
|
2015-12-19 09:04:44 +01:00
|
|
|
for x in range(0, 1000):
|
|
|
|
target_decimal_value = random.uniform(0.0, 180.0)
|
|
|
|
if(x % 2 == 1):
|
|
|
|
target_decimal_value = target_decimal_value * -1
|
|
|
|
|
|
|
|
dms = geolocation.decimal_to_dms(target_decimal_value)
|
2016-06-21 20:19:40 +02:00
|
|
|
|
|
|
|
check_value = (dms[0] + dms[1] / 60 + dms[2] / 3600) * dms[3]
|
2015-12-19 09:04:44 +01:00
|
|
|
|
|
|
|
target_decimal_value = round(target_decimal_value, 8)
|
|
|
|
check_value = round(check_value, 8)
|
2015-12-19 04:19:48 +01:00
|
|
|
|
2015-12-19 09:04:44 +01:00
|
|
|
assert target_decimal_value == check_value, '%s does not match %s' % (check_value, target_decimal_value)
|
2015-12-27 09:10:19 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
def test_dms_string_latitude():
|
2015-12-27 09:10:19 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
for x in range(0, 5):
|
|
|
|
target_decimal_value = random.uniform(0.0, 180.0)
|
|
|
|
if(x % 2 == 1):
|
|
|
|
target_decimal_value = target_decimal_value * -1
|
2015-12-27 09:10:19 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
dms = geolocation.decimal_to_dms(target_decimal_value)
|
|
|
|
dms_string = geolocation.dms_string(target_decimal_value, 'latitude')
|
2015-12-27 09:10:19 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
check_value = 'N' if target_decimal_value >= 0 else 'S'
|
|
|
|
|
|
|
|
assert check_value in dms_string, '%s not in %s' % (check_value, dms_string)
|
|
|
|
assert str(dms[0]) in dms_string, '%s not in %s' % (dms[0], dms_string)
|
|
|
|
|
|
|
|
def test_dms_string_longitude():
|
|
|
|
|
|
|
|
for x in range(0, 5):
|
|
|
|
target_decimal_value = random.uniform(0.0, 180.0)
|
|
|
|
if(x % 2 == 1):
|
|
|
|
target_decimal_value = target_decimal_value * -1
|
|
|
|
|
|
|
|
dms = geolocation.decimal_to_dms(target_decimal_value)
|
|
|
|
dms_string = geolocation.dms_string(target_decimal_value, 'longitude')
|
2015-12-27 09:10:19 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
check_value = 'E' if target_decimal_value >= 0 else 'W'
|
2015-12-27 09:10:19 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
assert check_value in dms_string, '%s not in %s' % (check_value, dms_string)
|
|
|
|
assert str(dms[0]) in dms_string, '%s not in %s' % (dms[0], dms_string)
|