# Path: gtfspy/util.py
# TORADIANS = 3.141592653589793 / 180.
# EARTH_RADIUS = 6378137.
#     R2 = EARTH_RADIUS * cos(lat * TORADIANS)
# def set_process_timezone(TZ):
# def wgs84_distance(lat1, lon1, lat2, lon2):
# def wgs84_height(meters):
# def wgs84_width(meters, lat):
# def create_file(fname=None, fname_tmp=None, tmpdir=None,
#                 save_tmpfile=False, keepext=False):
# def execute(cur, *args):
# def to_date_string(date):
# def ut_to_utc_datetime_str(time_ut):
# def str_time_to_day_seconds(time):
# def day_seconds_to_str_time(ds):
# def makedirs(path):
# def timeit(method):
#     def timed(*args, **kw):
# def corrupted_zip(zip_path):
# def source_csv_to_pandas(path, table, read_csv_args=None):
# def write_shapefile(data, shapefile_path):
# def zip_open(z, filename):
# def draw_net_using_node_coords(net):
# def make_sure_path_exists(path):
# def difference_of_pandas_dfs(df_self, df_other, col_names=None):
# def graph_has_node(g, node):
# def graph_node_attrs(g, node):
# class SystemTime(ctypes.Structure):


import unittest
import os
import pandas as pd
from gtfspy import util



class TestUtil(unittest.TestCase):

    @staticmethod
    def _approximately_equal(a, b):
        return abs(a - b) / float(abs(a + b)) < 1e-2

    def test_ut_to_utc_datetime_str(self):
        time_ut = 1438300800 + 24299
        assert util.ut_to_utc_datetime_str(time_ut) == "Jul 31 2015 06:44:59"

    def test_wgs84_width(self):
        lat = 60.4192161560059
        lon = 25.3302955627441
        # Test going 100m east
        width = util.wgs84_width(100, lat)
        lon2 = lon + width
        d = util.wgs84_distance(lat, lon, lat, lon2)
        self.assertTrue(self._approximately_equal(d, 100))
        # Test going 100m south
        height = util.wgs84_height(100)
        lat2 = lat + height
        d = util.wgs84_distance(lat, lon, lat2, lon)
        self.assertTrue(self._approximately_equal(d, 100))

    def test_day_seconds_to_str_time(self):

# Path: gtfspy/util.py
# TORADIANS = 3.141592653589793 / 180.
# EARTH_RADIUS = 6378137.
#     R2 = EARTH_RADIUS * cos(lat * TORADIANS)
# def set_process_timezone(TZ):
# def wgs84_distance(lat1, lon1, lat2, lon2):
# def wgs84_height(meters):
# def wgs84_width(meters, lat):
# def create_file(fname=None, fname_tmp=None, tmpdir=None,
#                 save_tmpfile=False, keepext=False):
# def execute(cur, *args):
# def to_date_string(date):
# def ut_to_utc_datetime_str(time_ut):
# def str_time_to_day_seconds(time):
# def day_seconds_to_str_time(ds):
# def makedirs(path):
# def timeit(method):
#     def timed(*args, **kw):
# def corrupted_zip(zip_path):
# def source_csv_to_pandas(path, table, read_csv_args=None):
# def write_shapefile(data, shapefile_path):
# def zip_open(z, filename):
# def draw_net_using_node_coords(net):
# def make_sure_path_exists(path):
# def difference_of_pandas_dfs(df_self, df_other, col_names=None):
# def graph_has_node(g, node):
# def graph_node_attrs(g, node):
# class SystemTime(ctypes.Structure):


# Path: gtfspy/test/test_util.py
import unittest
import os
import pandas as pd
from gtfspy import util




class TestUtil(unittest.TestCase):

    @staticmethod
    def _approximately_equal(a, b):
        return abs(a - b) / float(abs(a + b)) < 1e-2

    def test_ut_to_utc_datetime_str(self):
        time_ut = 1438300800 + 24299
        assert util.ut_to_utc_datetime_str(time_ut) == "Jul 31 2015 06:44:59"

    def test_wgs84_width(self):
        lat = 60.4192161560059
        lon = 25.3302955627441
        # Test going 100m east
        width = util.wgs84_width(100, lat)
        lon2 = lon + width
        d = util.wgs84_distance(lat, lon, lat, lon2)
        self.assertTrue(self._approximately_equal(d, 100))
        # Test going 100m south
        height = util.wgs84_height(100)
        lat2 = lat + height
        d = util.wgs84_distance(lat, lon, lat2, lon)
        self.assertTrue(self._approximately_equal(d, 100))

    def test_day_seconds_to_str_time(self):

        str_time = util.day_seconds_to_str_time(25 * 3600 + 59 * 60 + 10)