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

Add cropcover, cropyield functions and add some tests

parent 9b1ea59d
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ export
Weather,
FarmEvent,
ModelAgent,
# FarmPlot,
FarmPlot,
Animal,
Farmer,
DataOutput,
......@@ -103,7 +103,9 @@ export
loadmodelobject,
croptype,
cropname,
cropheight
cropheight,
cropcover,
cropyield
## Import and define units and dimensions
import Unitful: cm, m, km, ha, mg, g, kg, Length, Area, Mass
......
......@@ -21,7 +21,9 @@ import Persefone:
stepagent!,
croptype,
cropname,
cropheight
cropheight,
cropcover,
cropyield
using Dates: Date, month, monthday
using CSV: CSV
......@@ -89,6 +91,8 @@ end
croptype(cs::CropState) = cs.croptype
cropname(cs::CropState) = cropname(croptype(cs))
cropheight(cs::CropState) = cs.height
cropcover(cs::CropState) = 0.0
cropyield(cs::CropState) = 0.0
"""
Base.tryparse(type, str)
......
......@@ -3,9 +3,6 @@
### This file contains code for the fields that farmers manage.
###
# abstract type AbstractFarmPlot <: ModelAgent end
# mutable struct FarmPlot{T <: AbstractCropState} <: AbstractFarmPlot
mutable struct FarmPlot{T} <: ModelAgent
const id::Int64
pixels::Vector{Tuple{Int64, Int64}}
......@@ -15,6 +12,8 @@ end
croptype(f::FarmPlot{T}) where {T} = croptype(f.crop_state)
cropname(f::FarmPlot{T}) where {T} = cropname(croptype(f))
cropheight(f::FarmPlot{T}) where {T} = cropheight(f.crop_state)
cropcover(f::FarmPlot{T}) where {T} = cropcover(f.crop_state)
cropyield(f::FarmPlot{T}) where {T} = cropyield(f.crop_state)
"""
initfields_fill_with!(make_farmplot_fn, model)
......
......@@ -10,7 +10,9 @@ import Persefone:
stepagent!,
croptype,
cropname,
cropheight
cropheight,
cropcover,
cropyield
struct CropType
name::String
......@@ -20,12 +22,15 @@ cropname(ct::CropType) = ct.name
mutable struct CropState
croptype::CropType
cropheight::Length{Float64}
height::Length{Float64}
end
croptype(cs::CropState) = cs.croptype
cropname(cs::CropState) = cropname(croptype(cs))
cropheight(cs::CropState) = cs.height
cropcover(cs::CropState) = 0.0
cropyield(cs::CropState) = 0.0
"""
stepagent!(farmplot, model)
......
......@@ -6,7 +6,6 @@
const TESTPARAM_ALMASS = joinpath(pkgdir(Persefone), "test", "test_parameters_almass.toml")
const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameters_simplecrop.toml")
#"Model initialisation" begin
@testset for paramfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP)
@testset "Model initialisation" begin
model = initialise(paramfile)
......@@ -19,3 +18,28 @@ const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameter
end
end
@testset "Submodule ALMaSS" begin
ct = Ps.ALMaSS.CropType("olive tree", missing, missing, missing, missing, missing,
missing, missing)
fp = FarmPlot(0, [(0,0)],
Ps.ALMaSS.CropState(ct, Ps.ALMaSS.janfirst, 0.0, 0.0m, 0.0, 0.0, Ps.EventType[]))
@test fp isa FarmPlot
@test fp isa FarmPlot{Ps.ALMaSS.CropState}
@test croptype(fp) isa Ps.ALMaSS.CropType
@test cropname(fp) isa String
@test cropheight(fp) isa Length{Float64}
@test cropcover(fp) isa Float64
@test cropyield(fp) isa Float64
end
@testset "Submodule SimpleCrop" begin
ct = Ps.SimpleCrop.CropType("olive tree")
fp = FarmPlot(0, [(0,0)], Ps.SimpleCrop.CropState(ct, 0.0m))
@test fp isa FarmPlot
@test fp isa FarmPlot{Ps.SimpleCrop.CropState}
@test croptype(fp) isa Ps.SimpleCrop.CropType
@test cropname(fp) isa String
@test cropheight(fp) isa Length{Float64}
@test cropcover(fp) isa Float64
@test cropyield(fp) isa Float64
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment