Skip to content
Snippets Groups Projects
Commit a8280064 authored by Marco Matthies's avatar Marco Matthies
Browse files

Fixes for SimpleCrop unit tests

parent 79d17c15
Branches
Tags
No related merge requests found
......@@ -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
......
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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment