Skip to content

Commit

Permalink
Merge pull request #7 from jspeed-meyers/main
Browse files Browse the repository at this point in the history
Add test for utils.py
  • Loading branch information
luke-iqt committed Mar 17, 2021
2 parents 4cab902 + aa9e7d9 commit 4e87816
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ sudo raspi-config
- Camera
- Enable

### Testing with pytest

To run tests with pytest, run:

```bash
pytest
```


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==6.2.2
48 changes: 48 additions & 0 deletions tracker/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Unit tests for utils.py"""

import pytest

from utils import bearing, calc_travel, coordinate_distance, deg2rad, elevation


def test_deg2rad():
"""Unit tests for deg2rad()."""
# Note: python's math package includes a radians function that
# converts degrees to radians. This function could be eliminated
# to reduce custom code.
assert deg2rad(57.2958) == 1.0000003575641672
assert deg2rad(1) == 0.017453292519943295
assert deg2rad(-1) == -0.017453292519943295


@pytest.mark.skip(reason="Insufficient documentation to test. No docstrings.")
def test_elevation():
"""Unit test for elevation()."""
pass


def test_bearing():
"""Unit test for bearing()."""
# Example from: https://www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/
lat1, long1 = 39.099912, -94.581213
lat2, long2 = 38.627089, -90.200203
expected_bearing = 96.51262423499941
assert bearing(lat1, long1, lat2, long2) == expected_bearing


def test_coordinate_distance():
"""Unit test for coordinate_distance()."""
# Used this app to calculate distance: https://www.movable-type.co.uk/scripts/latlong.html
lat1, long1 = 39.099912, -94.581213
lat2, long2 = 38.627089, -90.200203
expected_distance = 382900.05037560174
assert coordinate_distance(lat1, long1, lat2, long2) == expected_distance


@pytest.mark.skip(reason="Insufficient documentation to test. What is lead_s?")
def test_calc_travel():
"""Unit test for calc_travel()."""
# note: the code in calc_travel is hard to understand because of the tangle
# of calculations. consider reformatting and explaining or explore the possibility
# using geopy
pass

0 comments on commit 4e87816

Please sign in to comment.