Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions tests/test_weather.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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),
(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)

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),
(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)

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)
Loading