From 4c5b17c2981b7874d3dfd255dbc40489f2ed833f Mon Sep 17 00:00:00 2001
From: Marco Matthies <71844+marcom@users.noreply.github.com>
Date: Tue, 3 Sep 2024 20:17:08 +0200
Subject: [PATCH] Better unit test for AquaCrop cropyield()

---
 src/crop/aquacrop.jl |  2 +-
 test/crop_tests.jl   | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/crop/aquacrop.jl b/src/crop/aquacrop.jl
index 9452ce1..cea2b2f 100644
--- a/src/crop/aquacrop.jl
+++ b/src/crop/aquacrop.jl
@@ -17,7 +17,7 @@ mutable struct AquaCropState
     function AquaCropState(croptype::AquaCropType, height::Length{Float64}=0.0cm)
         ac_parentdir = AquaCrop.test_toml_dir  # TODO: hardcoded croptype
         ac_runtype = :Julia
-        cropstate, allok = AquaCrop.initialize_cropfield(ac_parentdir, ac_runtype)
+        cropstate, allok = AquaCrop.initialize_cropfield(; parentdir=ac_parentdir, runtype=ac_runtype)
         if ! allok.logi
             error("AquaCrop.initialize_cropfield() failed, status = $allok")
         end
diff --git a/test/crop_tests.jl b/test/crop_tests.jl
index aaf8f71..dabcf84 100644
--- a/test/crop_tests.jl
+++ b/test/crop_tests.jl
@@ -3,17 +3,20 @@
 ### These are the tests for the crop growth models.
 ###
 
-const TESTPARAM_ALMASS = joinpath(pkgdir(Persefone), "test", "test_parameters_almass.toml")
-const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameters_simplecrop.toml")
-const TESTPARAM_AQUACROP = joinpath(pkgdir(Persefone), "test", "test_parameters_aquacrop.toml")
+import Unitful
 
-@testset for paramfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP, TESTPARAM_AQUACROP)
+@testset for paramfile in [
+    "test_parameters_almass.toml",
+    "test_parameters_simplecrop.toml",
+    "test_parameters_aquacrop.toml",
+]
+    parampath = joinpath(pkgdir(Persefone), "test", paramfile)
     @testset "Model initialisation" begin
-        model = initialise(paramfile)
+        model = initialise(parampath)
         @test model isa AgricultureModel
     end
     @testset "Time step" begin
-        model = initialise(paramfile)
+        model = initialise(parampath)
         stepsimulation!(model)
         @test model isa AgricultureModel
     end
@@ -65,6 +68,6 @@ end
     @test cropname(fp) isa String
     @test cropheight(fp) isa Length{Float64}
     @test cropcover(fp) isa Float64
-    @test cropyield(fp) isa type(1.0u"kg/ha")
+    @test Unitful.dimension(cropyield(fp)) == Unitful.𝐌 * Unitful.𝐋^-2
     # TODO: test stepagent!(), sow!(), harvest!()
 end
-- 
GitLab