From e97bdee247fe52ab7d687791e9e5b7c4b2410fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Arg=C3=BCeso?= Date: Mon, 13 Dec 2021 21:18:36 +0100 Subject: [PATCH] Update w2w_test.py Added test for distance calculation --- tests/w2w_test.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/w2w_test.py b/tests/w2w_test.py index 696791d..96c2ca1 100644 --- a/tests/w2w_test.py +++ b/tests/w2w_test.py @@ -4,8 +4,8 @@ from w2w.w2w import main from w2w.w2w import check_lcz_wrf_extent from w2w.w2w import wrf_remove_urban -from w2w.w2w import main from w2w.w2w import create_wrf_gridinfo +from w2w.w2w import calc_distance_coord import xarray @@ -120,3 +120,17 @@ def test_full_run_with_example_data(tmpdir): assert 'geo_em.d04_LCZ_params.nc' in contents assert 'geo_em.d04_NoUrban.nc' in contents assert 'geo_em.d04_LCZ_extent.nc' in contents + + +@pytest.mark.parametrize( + ('coords', 'expected'), + ( + pytest.param((89, 0, 90, 1), 111194, id='near northern pole'), + pytest.param((-89, 0, -90, 1), 111194, id='near southern pole'), + pytest.param((-60, -10, -70, -12), 1115764, id='southern eastern hemisphere'), + pytest.param((-1, 0, 1, 2), 314498, id='across equator'), + pytest.param((45, 179, 46, -179), 191461, id='across dateline') + ), +) +def test_calc_distance_coord(coords, expected): + assert calc_distance_coord(*coords) == pytest.approx(expected, abs=1)