# Path: D3HRE/core/file_reading_utility.py
# def read_route_from_gpx(file):
#     """
#     Read route from gpx file
# 
#     :param file: str, path to the .gpx file
#     :return: numpy array, contains all routes
#     """
#     gpx_file = open(file)
#     gpx = gpxpy.parse(gpx_file)
#     all_routes = []
#     for route in gpx.routes:
#         route_list = []
#         for point in route.points:
#             route_list.append([point.latitude, point.longitude])
#         all_routes.append(route_list)
#     return  np.array(all_routes)


import os
import pytest
from D3HRE.core.route_utility import *
from D3HRE.core.file_reading_utility import read_route_from_gpx

opencpn_XML='-69.4565,20.7236,0. -68.3182,21.8401,0. '

def test_coordinates_processing():
    route = opencpn_coordinates_processing(opencpn_XML)
    assert route.shape[1] == 2 # return a (n, 2) np array
    assert route[0][0] == 20.7236


def test_gpx_route_reader():
    file_name = os.path.join(os.path.dirname(__file__), 'test.gpx')
    routes = read_route_from_gpx(file_name)
    assert len(routes[0]) == 30  # GPX reader can get right number of way points

# Path: D3HRE/core/file_reading_utility.py
# def read_route_from_gpx(file):
#     """
#     Read route from gpx file
# 
#     :param file: str, path to the .gpx file
#     :return: numpy array, contains all routes
#     """
#     gpx_file = open(file)
#     gpx = gpxpy.parse(gpx_file)
#     all_routes = []
#     for route in gpx.routes:
#         route_list = []
#         for point in route.points:
#             route_list.append([point.latitude, point.longitude])
#         all_routes.append(route_list)
#     return  np.array(all_routes)


# Path: tests/test_route_utility.py
import os
import pytest
from D3HRE.core.route_utility import *
from D3HRE.core.file_reading_utility import read_route_from_gpx


opencpn_XML='-69.4565,20.7236,0. -68.3182,21.8401,0. '

def test_coordinates_processing():
    route = opencpn_coordinates_processing(opencpn_XML)
    assert route.shape[1] == 2 # return a (n, 2) np array
    assert route[0][0] == 20.7236


def test_gpx_route_reader():
    file_name = os.path.join(os.path.dirname(__file__), 'test.gpx')
    routes = read_route_from_gpx(file_name)
    assert len(routes[0]) == 30  # GPX reader can get right number of way points

    assert routes[0][0][0] == pytest.approx(20.7236)