From 00af3c636d566d049f6a140c093af4e91d0482d5 Mon Sep 17 00:00:00 2001 From: Remi Salmon Date: Fri, 27 Oct 2023 21:13:38 -0600 Subject: [PATCH] Update tests --- test.sh | 11 +++++-- test/test.txt | 69 ------------------------------------------- tests/tests.txt | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 72 deletions(-) delete mode 100644 test/test.txt create mode 100644 tests/tests.txt diff --git a/test.sh b/test.sh index ee86ba5..e55a3bc 100755 --- a/test.sh +++ b/test.sh @@ -1,5 +1,10 @@ -#!/bin/bash +#!/usr/bin/env bash -python -m doctest -o IGNORE_EXCEPTION_DETAIL -f test/test.txt +python3.8 -m venv venv -[ $? -eq 0 ] && echo 'Test passed.' +source venv/bin/activate + +python -m pip install -U pip setuptools +python -m pip install -r requirements.txt + +python -m doctest -o IGNORE_EXCEPTION_DETAIL -f tests/tests.txt || exit 1 diff --git a/test/test.txt b/test/test.txt deleted file mode 100644 index 43b5b1c..0000000 --- a/test/test.txt +++ /dev/null @@ -1,69 +0,0 @@ -# doctest file for gpx_interpolate.py ->>> import numpy as np ->>> from gpx_interpolate import gpx_interpolate, gpx_calculate_distance, gpx_calculate_speed, gpx_remove_duplicates - ->>> gpx_data = {'lat':[0.0, 1.1, 1.1], 'lon':[0.0, 1.1, 1.1], 'ele':None, 'tstamp':[0.0, 1.1, 1.1], 'tzinfo':None} ->>> DIST, TIME, RES, NUM = 172973.4, 1.1, 10.0, 10 - -## test gpx_interpolate ->>> gpx_interpolate(gpx_data, res=0.0) -Traceback (most recent call last): - ... -ValueError: ... - ->>> gpx_interpolate(gpx_data, num=-1) -Traceback (most recent call last): - ... -ValueError: ... - ->>> gpx_data_interp = gpx_interpolate(gpx_data, res=RES) - ->>> len(gpx_data_interp['lat']) == len(gpx_data_interp['lon']) == len(gpx_data_interp['tstamp']) == np.ceil(DIST/RES) -True - ->>> gpx_data_interp = gpx_interpolate(gpx_data, num=NUM) - ->>> len(gpx_data_interp['lat']) == len(gpx_data_interp['lon']) == len(gpx_data_interp['tstamp']) == NUM -True - ->>> abs(gpx_data_interp['lat'][0]-gpx_data['lat'][0]) < 1e-6 -True - ->>> abs(gpx_data_interp['lat'][-1]-gpx_data['lat'][-1]) < 1e-6 -True - ->>> abs(gpx_data_interp['lon'][0]-gpx_data['lon'][0]) < 1e-6 -True - ->>> abs(gpx_data_interp['lon'][-1]-gpx_data['lon'][-1]) < 1e-6 -True - -## test gpx_calculate_distance ->>> gpx_dist = gpx_calculate_distance(gpx_data) - ->>> len(gpx_dist) == 3 -True - ->>> gpx_dist[0] == gpx_dist[2] == 0.0 -True - ->>> np.round(gpx_dist[1], decimals=1) == DIST -True - -## test gpx_calculate_speed ->>> gpx_speed = gpx_calculate_speed(gpx_data) - ->>> len(gpx_speed) == 3 -True - ->>> gpx_speed[0] == gpx_speed[2] == 0.0 -True - ->>> np.round(gpx_speed[1], decimals=1) == np.round(DIST/TIME, decimals=1) -True - -## test gpx_remove_duplicates ->>> gpx_data = gpx_remove_duplicates(gpx_data) - ->>> len(gpx_data['lat']) == len(gpx_data['lon']) == len(gpx_data['tstamp']) == 2 -True diff --git a/tests/tests.txt b/tests/tests.txt new file mode 100644 index 0000000..64032c3 --- /dev/null +++ b/tests/tests.txt @@ -0,0 +1,78 @@ +# doctest file for gpx_interpolate.py +>>> import numpy as np +>>> from gpx_interpolate import gpx_interpolate, gpx_calculate_distance, gpx_calculate_speed, gpx_remove_duplicates + +>>> test_data = {'lat': [0.0, 1.1, 1.1], 'lon': [0.0, 1.1, 1.1], 'ele': None, 'tstamp': [0.0, 1.1, 1.1], 'tzinfo': None} +>>> empty_data = {'lat': [], 'lon': [], 'ele': None, 'tstamp': None, 'tzinfo': None} +>>> DIST, TIME, RES, NUM = 172973.4, 1.1, 10.0, 10 + +## test gpx_interpolate +>>> gpx_interpolate(empty_data) == gpx_interpolate(empty_data, res=RES) == gpx_interpolate(empty_data, num=NUM) == empty_data +True + +>>> gpx_interpolate(test_data, res=0.0) +Traceback (most recent call last): + ... +OverflowError: ... + +>>> gpx_interpolate(test_data, res=-1.0) +Traceback (most recent call last): + ... +ValueError: ... + +>>> gpx_interpolate(test_data, num=-1) +Traceback (most recent call last): + ... +ValueError: ... + +>>> test_data_interp = gpx_interpolate(test_data, res=RES) + +>>> len(test_data_interp['lat']) == len(test_data_interp['lon']) == len(test_data_interp['tstamp']) == int(np.ceil(DIST/RES)) +True + +>>> test_data_interp = gpx_interpolate(test_data, num=NUM) + +>>> len(test_data_interp['lat']) == len(test_data_interp['lon']) == len(test_data_interp['tstamp']) == NUM +True + +>>> abs(test_data_interp['lat'][0]-test_data['lat'][0]) < 1e-6 +True + +>>> abs(test_data_interp['lat'][-1]-test_data['lat'][-1]) < 1e-6 +True + +>>> abs(test_data_interp['lon'][0]-test_data['lon'][0]) < 1e-6 +True + +>>> abs(test_data_interp['lon'][-1]-test_data['lon'][-1]) < 1e-6 +True + +## test gpx_calculate_distance +>>> test_dist = gpx_calculate_distance(test_data) + +>>> len(test_dist) == 3 +True + +>>> test_dist[0] == test_dist[2] == 0.0 +True + +>>> np.round(test_dist[1], decimals=1) == DIST +True + +## test gpx_calculate_speed +>>> test_speed = gpx_calculate_speed(test_data) + +>>> len(test_speed) == 3 +True + +>>> test_speed[0] == test_speed[2] == 0.0 +True + +>>> np.round(test_speed[1], decimals=1) == np.round(DIST/TIME, decimals=1) +True + +## test gpx_remove_duplicates +>>> test_data = gpx_remove_duplicates(test_data) + +>>> len(test_data['lat']) == len(test_data['lon']) == len(test_data['tstamp']) == 2 +True