From 17f91f83919d78223f7f73421a7cb7472134caaf Mon Sep 17 00:00:00 2001 From: Pankaj Kumar Bind Date: Sat, 7 Mar 2026 22:48:10 +0530 Subject: [PATCH 1/2] fix: correct dead test functions for get_u/get_v in test_weather.py --- tests/test_weather.py | 58 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/tests/test_weather.py b/tests/test_weather.py index ed3dc34..686621c 100644 --- a/tests/test_weather.py +++ b/tests/test_weather.py @@ -1,7 +1,11 @@ +import math + import pytest from WeatherRoutingTool.weather import WeatherCond +SQRT2_2 = math.sqrt(2) / 2 + @pytest.mark.parametrize("u,v,theta_res", [(-1, -1, 45), (1, -1, 315), (1, 1, 225), (-1, 1, 135)]) def test_theta_from_uv(u, v, theta_res): @@ -10,15 +14,57 @@ def test_theta_from_uv(u, v, theta_res): assert theta_test == pytest.approx(theta_res) -@pytest.mark.parametrize("theta,windspeed,u_res", [(45, 1, -1), (315, 1, 1), (225, 1, 1), (135, 1, -1)]) -def get_u(theta, windspeed): +@pytest.mark.parametrize("theta,windspeed,u_res", [ + (0, 1, 0.0), # -sin(0) = 0 + (90, 1, -1.0), # -sin(90) = -1 + (180, 1, 0.0), # -sin(180) = 0 + (270, 1, 1.0), # -sin(270) = 1 + (45, 1, -SQRT2_2), # -sin(45) = -sqrt(2)/2 + (135, 1, -SQRT2_2), # -sin(135) = -sqrt(2)/2 + (225, 1, SQRT2_2), # -sin(225) = sqrt(2)/2 + (315, 1, SQRT2_2), # -sin(315) = sqrt(2)/2 +]) +def test_get_u(theta, windspeed, u_res): u_test = WeatherCond.get_u(theta, windspeed) - assert u_test == pytest.approx(u_test) + assert u_test == pytest.approx(u_res) -@pytest.mark.parametrize("theta,windspeed,u_res", [(45, 1, -1), (315, 1, -1), (225, 1, 1), (135, 1, 1)]) -def get_v(theta, windspeed): +@pytest.mark.parametrize("theta,windspeed,v_res", [ + (0, 1, -1.0), # -cos(0) = -1 + (90, 1, 0.0), # -cos(90) = 0 + (180, 1, 1.0), # -cos(180) = 1 + (270, 1, 0.0), # -cos(270) = 0 + (45, 1, -SQRT2_2), # -cos(45) = -sqrt(2)/2 + (135, 1, SQRT2_2), # -cos(135) = sqrt(2)/2 + (225, 1, SQRT2_2), # -cos(225) = sqrt(2)/2 + (315, 1, -SQRT2_2), # -cos(315) = -sqrt(2)/2 +]) +def test_get_v(theta, windspeed, v_res): v_test = WeatherCond.get_v(theta, windspeed) - assert v_test == pytest.approx(v_test) + assert v_test == pytest.approx(v_res) + + +@pytest.mark.parametrize("theta,windspeed", [ + (0, 1), (45, 1), (90, 1), (135, 1), + (180, 1), (225, 1), (270, 1), (315, 1), + (60, 5), (120, 0.5), +]) +def test_uv_magnitude_equals_windspeed(theta, windspeed): + u = WeatherCond.get_u(theta, windspeed) + v = WeatherCond.get_v(theta, windspeed) + + assert math.sqrt(u**2 + v**2) == pytest.approx(abs(windspeed)) + + +@pytest.mark.parametrize("theta,windspeed", [ + (0, 1), (45, 1), (90, 1), (135, 1), + (180, 1), (225, 1), (270, 1), (315, 1), + (60, 3), +]) +def test_uv_roundtrip_recovers_theta(theta, windspeed): + u = WeatherCond.get_u(theta, windspeed) + v = WeatherCond.get_v(theta, windspeed) + + assert WeatherCond.get_theta_from_uv(u, v) == pytest.approx(theta) From 4b2cf60ce6ac886f8731765c1ee15e1b83db8b92 Mon Sep 17 00:00:00 2001 From: Pankaj Kumar Bind <73558583+pankaj-bind@users.noreply.github.com> Date: Sat, 7 Mar 2026 22:58:19 +0530 Subject: [PATCH 2/2] Refactor parameterized tests for weather functions --- tests/test_weather.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/test_weather.py b/tests/test_weather.py index 686621c..c81dbbf 100644 --- a/tests/test_weather.py +++ b/tests/test_weather.py @@ -15,14 +15,14 @@ def test_theta_from_uv(u, v, theta_res): @pytest.mark.parametrize("theta,windspeed,u_res", [ - (0, 1, 0.0), # -sin(0) = 0 - (90, 1, -1.0), # -sin(90) = -1 - (180, 1, 0.0), # -sin(180) = 0 - (270, 1, 1.0), # -sin(270) = 1 - (45, 1, -SQRT2_2), # -sin(45) = -sqrt(2)/2 - (135, 1, -SQRT2_2), # -sin(135) = -sqrt(2)/2 - (225, 1, SQRT2_2), # -sin(225) = sqrt(2)/2 - (315, 1, SQRT2_2), # -sin(315) = sqrt(2)/2 + (0, 1, 0.0), + (90, 1, -1.0), + (180, 1, 0.0), + (270, 1, 1.0), + (45, 1, -SQRT2_2), + (135, 1, -SQRT2_2), + (225, 1, SQRT2_2), + (315, 1, SQRT2_2), ]) def test_get_u(theta, windspeed, u_res): u_test = WeatherCond.get_u(theta, windspeed) @@ -31,14 +31,14 @@ def test_get_u(theta, windspeed, u_res): @pytest.mark.parametrize("theta,windspeed,v_res", [ - (0, 1, -1.0), # -cos(0) = -1 - (90, 1, 0.0), # -cos(90) = 0 - (180, 1, 1.0), # -cos(180) = 1 - (270, 1, 0.0), # -cos(270) = 0 - (45, 1, -SQRT2_2), # -cos(45) = -sqrt(2)/2 - (135, 1, SQRT2_2), # -cos(135) = sqrt(2)/2 - (225, 1, SQRT2_2), # -cos(225) = sqrt(2)/2 - (315, 1, -SQRT2_2), # -cos(315) = -sqrt(2)/2 + (0, 1, -1.0), + (90, 1, 0.0), + (180, 1, 1.0), + (270, 1, 0.0), + (45, 1, -SQRT2_2), + (135, 1, SQRT2_2), + (225, 1, SQRT2_2), + (315, 1, -SQRT2_2), ]) def test_get_v(theta, windspeed, v_res): v_test = WeatherCond.get_v(theta, windspeed)