From a82800647a935dde151bbc8a128943552f5c3956 Mon Sep 17 00:00:00 2001 From: Marco Matthies <71844+marcom@users.noreply.github.com> Date: Mon, 19 Aug 2024 05:09:55 +0200 Subject: [PATCH] Fixes for SimpleCrop unit tests --- src/crop/cropmodels.jl | 3 ++- src/crop/simplecrop.jl | 14 +++++++++++--- test/crop_tests.jl | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/crop/cropmodels.jl b/src/crop/cropmodels.jl index 22d6b14..8653a14 100644 --- a/src/crop/cropmodels.jl +++ b/src/crop/cropmodels.jl @@ -18,7 +18,8 @@ function initcropmodel(cropmodel::AbstractString, cropfile::AbstractString, grow Tcroptype = SimpleCrop.CropType Tcropstate = SimpleCrop.CropState crops_almass = ALMaSS.readcropparameters(cropfile, growthfile) - crops = Dict(name => SimpleCrop.CropType(ct.name) for (name, ct) in crops_almass) + crops = Dict(name => SimpleCrop.CropType(ct.name, ct.group, ct.minsowdate, ct.maxsowdate) + for (name, ct) in crops_almass) else error("initcropmodel: no implementation for crop model '$cropmodel'") end diff --git a/src/crop/simplecrop.jl b/src/crop/simplecrop.jl index 308434d..348d944 100644 --- a/src/crop/simplecrop.jl +++ b/src/crop/simplecrop.jl @@ -1,6 +1,7 @@ module SimpleCrop using Persefone: + AnnualDate, FarmPlot, Length, cm, @@ -14,10 +15,17 @@ import Persefone: cropcover, cropyield, sow!, - harvest! + harvest!, + isharvestable +using Unitful: @u_str + +# TODO: alternatively just use ALMaSS.CropType ? struct CropType name::String + group::String + minsowdate::Union{Missing,AnnualDate} + maxsowdate::Union{Missing,AnnualDate} end cropname(ct::CropType) = ct.name @@ -64,8 +72,8 @@ function harvest!(cs::CropState, model::SimulationModel) # TODO: set cs.croptype ? # TODO: this 1.0g/cm/m^2 height_to_yield factor should be a param # for every crop type - yield = cs.height * 1.0g/cm/m^2 - cs.height = 0cm + yield = cs.height * 1.0u"g/cm/m^2" + cs.height = 5.0cm return yield end diff --git a/test/crop_tests.jl b/test/crop_tests.jl index 93e233c..9632b1d 100644 --- a/test/crop_tests.jl +++ b/test/crop_tests.jl @@ -38,7 +38,7 @@ end end @testset "Submodule SimpleCrop" begin - ct = Ps.SimpleCrop.CropType("olive tree") + ct = Ps.SimpleCrop.CropType("olive tree", "no_crop_group", AnnualDate(4, 1), AnnualDate(5, 1)) id = 0 pixels = [(0, 0)] farmer = 0 -- GitLab