From 671cdb60dcb872ca53c2260e8bd0b25af455a67c Mon Sep 17 00:00:00 2001
From: Marco Matthies <71844+marcom@users.noreply.github.com>
Date: Wed, 19 Feb 2025 11:05:49 +0100
Subject: [PATCH] Rearrange weather unit tests

---
 test/landscape_tests.jl |  2 +-
 test/runtests.jl        |  3 +++
 test/weather_tests.jl   | 27 +++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 test/weather_tests.jl

diff --git a/test/landscape_tests.jl b/test/landscape_tests.jl
index a500e52..7f1fe42 100644
--- a/test/landscape_tests.jl
+++ b/test/landscape_tests.jl
@@ -64,7 +64,7 @@ end
     @test Ps.distancetoedge((6,6), model) == 20m
 end
 
-@testset "Weather initialisation" begin
+@testset "Weather interface" begin
     # these tests are specific to the Jena weather file
     model = inittestmodel()
     @test length(model.weather) == 59
diff --git a/test/runtests.jl b/test/runtests.jl
index f30aca6..a655c01 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -92,6 +92,9 @@ end
         include("landscape_tests.jl")
         include("simulation_tests.jl")
     end
+    @testset "Weather model" begin
+        include("weather_tests.jl")
+    end
     @testset "Nature model" begin
         include("nature_tests.jl")
     end
diff --git a/test/weather_tests.jl b/test/weather_tests.jl
new file mode 100644
index 0000000..4f838c5
--- /dev/null
+++ b/test/weather_tests.jl
@@ -0,0 +1,27 @@
+
+@testset "Constructor and interface" begin
+    float3 = [0.0, 1.0, 2.0]
+    missing3 = Union{Missing,Float64}[missing, missing, missing]
+    weather = Weather(; firstdate = Date("2000-01-01"),
+                      lastdate = Date("2000-01-03"),
+                      windspeed = missing3,
+                      precipitation = float3,
+                      sunshine = missing3,
+                      cloudcover = missing3,
+                      humidity = missing3,
+                      meantemp = float3,
+                      maxtemp = float3,
+                      mintemp = float3,
+                      evapotranspiration = float3)
+    date = Date("2000-01-02")
+    @test length(weather) == 3
+    @test Ps.daynumber(weather, date) == 2
+    @test Ps.windspeed(weather, date) |> ismissing
+    @test Ps.precipitation(weather, date) == 1.0
+    @test Ps.sunshine(weather, date) |> ismissing
+    @test Ps.humidity(weather, date) |> ismissing
+    @test Ps.meantemp(weather, date) == 1.0
+    @test Ps.maxtemp(weather, date) == 1.0
+    @test Ps.mintemp(weather, date) == 1.0
+    @test Ps.evapotranspiration(weather, date) == 1.0
+end
-- 
GitLab