From f876f8847b3509705a04c9f4cc8fe048846ad5b9 Mon Sep 17 00:00:00 2001 From: Ashley Barnes <53282288+ashjbarnes@users.noreply.github.com> Date: Mon, 4 Sep 2023 14:03:24 +1000 Subject: [PATCH] =?UTF-8?q?=CE=91dd=20test=20for=20quad=20area=20function?= =?UTF-8?q?=20(#61)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added test for test quad area * remove placeholder tests trivial * reformat with black * Update tests/test_grid_generation.py Co-authored-by: Navid C. Constantinou * Update tests/test_grid_generation.py Co-authored-by: Navid C. Constantinou * Update tests/test_grid_generation.py Co-authored-by: Navid C. Constantinou * Update tests/test_grid_generation.py Co-authored-by: Navid C. Constantinou --------- Co-authored-by: Navid C. Constantinou --- .gitignore | 2 +- tests/test_grid_generation.py | 32 ++++++++++++++++++++++++++++++++ tests/test_trivial.py | 15 --------------- 3 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 tests/test_grid_generation.py delete mode 100644 tests/test_trivial.py diff --git a/.gitignore b/.gitignore index bd56f086..705e79b5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ _build regional_mom6/_version.py regional_mom6.egg-info .pytest_cache -env +.env diff --git a/tests/test_grid_generation.py b/tests/test_grid_generation.py new file mode 100644 index 00000000..742865ba --- /dev/null +++ b/tests/test_grid_generation.py @@ -0,0 +1,32 @@ +import numpy as np +import pytest +from regional_mom6 import angle_between +from regional_mom6 import quad_area + + +@pytest.mark.parametrize( + ("v1", "v2", "v3", "true_angle"), + [ + ([1, 0, 0], [0, 1, 0], [0, 0, 1], np.pi / 2), + ([1, 0, 0], [1, 1, 0], [0, 1, 1], np.pi / 4), + ], +) +def test_angle_between(v1, v2, v3, true_angle): + assert np.isclose(angle_between(v1, v2, v3), true_angle) + + +# create a lat-lon mesh that covers 1/4 of the North Hemisphere +lon, lat = np.meshgrid(np.linspace(0, 90, 5), np.linspace(0, 90, 5)) + + +@pytest.mark.parametrize( + ("lat", "lon", "true_area"), + [ + (lat, lon, 0.5 * np.pi), + ], +) +def test_quad_area(lat, lon, true_area): + assert np.isclose(np.sum(quad_area(lat, lon)), true_area) + + +# what to return when pytest passes diff --git a/tests/test_trivial.py b/tests/test_trivial.py deleted file mode 100644 index 7661dbea..00000000 --- a/tests/test_trivial.py +++ /dev/null @@ -1,15 +0,0 @@ -import numpy as np -import pytest -from regional_mom6 import angle_between - - -# placeholder trivial test test -@pytest.mark.parametrize( - ("v1", "v2", "v3", "true_angle"), - [ - ([1, 0, 0], [0, 1, 0], [0, 0, 1], np.pi / 2), - ([1, 0, 0], [1, 1, 0], [0, 1, 1], np.pi / 4), - ], -) -def test_angle_between(v1, v2, v3, true_angle): - assert np.isclose(angle_between(v1, v2, v3), true_angle)