diff --git a/tests/geo_ressources.py b/tests/geo_ressources.py index 7069642..a23fc18 100644 --- a/tests/geo_ressources.py +++ b/tests/geo_ressources.py @@ -6,16 +6,16 @@ LONDON = (51.509865, -0.118092) EXPECTED_LYON_PARIS = {Unit.KILOMETERS: 392.2172595594006, - Unit.METERS: 392217.2595594006, - Unit.MILES: 243.71250609539814, - Unit.NAUTICAL_MILES: 211.78037755311516, - Unit.FEET: 1286802.0326751503, - Unit.INCHES: 15441624.392102592, - Unit.RADIANS: 0.061562818679421795, - Unit.DEGREES: 3.5272896852600164} + Unit.METERS: 392217.2595594006, + Unit.MILES: 243.71250609539814, + Unit.NAUTICAL_MILES: 211.78037755311516, + Unit.FEET: 1286802.0326751503, + Unit.INCHES: 15441624.392102592, + Unit.RADIANS: 0.061562818679421795, + Unit.DEGREES: 3.5272896852600164} EXPECTED_LYON_NEW_YORK = {Unit.KILOMETERS: 6163.43638211, - Unit.METERS: 61634363.8211 } + Unit.METERS: 61634363.8211} EXPECTED_PARIS_NEW_YORK = {Unit.KILOMETERS: 5853.32898662, - Unit.METERS: 58533289.8662 } + Unit.METERS: 58533289.8662} EXPECTED_LONDON_PARIS = {Unit.KILOMETERS: 343.37455271} EXPECTED_LONDON_NEW_YORK = {Unit.KILOMETERS: 5586.48447423} diff --git a/tests/test_haversine.py b/tests/test_haversine.py index ae93adf..07fc867 100755 --- a/tests/test_haversine.py +++ b/tests/test_haversine.py @@ -4,6 +4,7 @@ from tests.geo_ressources import LYON, PARIS, NEW_YORK, LONDON, EXPECTED_LYON_PARIS + def haversine_test_factory(unit): def test(): expected = EXPECTED_LYON_PARIS[unit] @@ -81,6 +82,7 @@ def test_out_of_bounds(oob_from, oob_to): with pytest.raises(ValueError): haversine(oob_from, oob_to, normalize=False) + @pytest.mark.parametrize( "in_bounds_from,in_bounds_to", [ ((-90, 0), (0, 0)), diff --git a/tests/test_haversine_vector.py b/tests/test_haversine_vector.py index 0f84ce5..e10b080 100644 --- a/tests/test_haversine_vector.py +++ b/tests/test_haversine_vector.py @@ -4,6 +4,7 @@ from tests.geo_ressources import EXPECTED_LONDON_PARIS, EXPECTED_LYON_NEW_YORK, EXPECTED_LYON_PARIS, EXPECTED_LONDON_NEW_YORK, LYON, PARIS, NEW_YORK, LONDON + @pytest.mark.parametrize( 'unit', [Unit.KILOMETERS, Unit.METERS, Unit.INCHES] ) @@ -12,7 +13,8 @@ def test_lyon_paris(unit): expected_lyon_paris = EXPECTED_LYON_PARIS[unit] assert haversine_vector(LYON, PARIS, unit=unit) == expected_lyon_paris assert isinstance(unit.value, str) - assert haversine_vector(LYON, PARIS, unit=unit.value) == expected_lyon_paris + assert haversine_vector( + LYON, PARIS, unit=unit.value) == expected_lyon_paris return test_lyon_paris(unit) @@ -38,7 +40,8 @@ def test_normalization(oob_from, oob_to, proper_from, proper_to): """ normalized_during, normalized_already = ( haversine_vector([oob_from], [oob_to], Unit.DEGREES, normalize=True), - haversine_vector([proper_from], [proper_to], Unit.DEGREES, normalize=True), + haversine_vector([proper_from], [proper_to], + Unit.DEGREES, normalize=True), ) assert normalized_during == pytest.approx(normalized_already, abs=1e-10) @@ -68,11 +71,12 @@ def test_haversine_vector_comb(): [EXPECTED_LYON_NEW_YORK[unit], EXPECTED_LONDON_NEW_YORK[unit]] ] - assert_allclose( # See https://numpy.org/doc/stable/reference/generated/numpy.testing.assert_allclose.html#numpy.testing.assert_allclose + assert_allclose( # See https://numpy.org/doc/stable/reference/generated/numpy.testing.assert_allclose.html#numpy.testing.assert_allclose haversine_vector([LYON, LONDON], [PARIS, NEW_YORK], unit, comb=True), expected ) + def test_units_enum(): from haversine.haversine import _CONVERSIONS assert all(unit in _CONVERSIONS for unit in Unit) diff --git a/tests/test_inverse_haversine.py b/tests/test_inverse_haversine.py index 34cb6fb..7538ed9 100755 --- a/tests/test_inverse_haversine.py +++ b/tests/test_inverse_haversine.py @@ -5,6 +5,7 @@ from tests.geo_ressources import LYON, PARIS, NEW_YORK, LONDON + @pytest.mark.parametrize( "point, dir, dist, result", [ @@ -18,7 +19,8 @@ ], ) def test_inverse_kilometers(point, dir, dist, result): - assert isclose(inverse_haversine(point, dist, dir), result, rtol=1e-5).all() + assert isclose(inverse_haversine(point, dist, dir), + result, rtol=1e-5).all() @pytest.mark.parametrize( @@ -36,8 +38,10 @@ def test_back_and_forth(point, direction, distance, unit): def test_inverse_miles(): - assert isclose(inverse_haversine(PARIS, 50, Direction.NORTH, unit=Unit.MILES), (49.5803579218996, 2.3508), rtol=1e-5).all() + assert isclose(inverse_haversine(PARIS, 50, Direction.NORTH, + unit=Unit.MILES), (49.5803579218996, 2.3508), rtol=1e-5).all() def test_nautical_inverse_miles(): - assert isclose(inverse_haversine(PARIS, 10, Direction.SOUTH, unit=Unit.NAUTICAL_MILES), (48.69014586638915, 2.3508), rtol=1e-5).all() + assert isclose(inverse_haversine(PARIS, 10, Direction.SOUTH, + unit=Unit.NAUTICAL_MILES), (48.69014586638915, 2.3508), rtol=1e-5).all()