Skip to content
Snippets Groups Projects
Commit c42af384 authored by xo30xoqa's avatar xo30xoqa
Browse files

Started fixing tests

parent 98d092f2
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,7 @@ export ...@@ -60,7 +60,7 @@ export
@habitat, @habitat,
@landcover, @landcover,
@cropheight, @cropheight,
@croptype, @cropname,
@distanceto, @distanceto,
@distancetoedge, @distancetoedge,
@countanimals, @countanimals,
......
...@@ -176,6 +176,17 @@ function croptype(pos::Tuple{Int64,Int64}, model::AgentBasedModel) ...@@ -176,6 +176,17 @@ function croptype(pos::Tuple{Int64,Int64}, model::AgentBasedModel)
model[model.landscape[pos...].fieldid].croptype model[model.landscape[pos...].fieldid].croptype
end end
"""
cropname(model, position)
Return the name of the crop at this position, or nothing if there is no crop here
(utility wrapper).
"""
function cropname(pos::Tuple{Int64,Int64}, model::AgentBasedModel)
ismissing(model.landscape[pos...].fieldid) ? nothing :
model[model.landscape[pos...].fieldid].croptype.name
end
""" """
cropheight(model, position) cropheight(model, position)
......
...@@ -287,7 +287,7 @@ and a position, and returns `true` or `false` depending on the conditions ...@@ -287,7 +287,7 @@ and a position, and returns `true` or `false` depending on the conditions
specified in the macro body. specified in the macro body.
Several utility macros can be used within the body of `@habitat` as a short-hand for Several utility macros can be used within the body of `@habitat` as a short-hand for
common expressions: [`@landcover`](@ref), [`@croptype`](@ref), [`@cropheight`](@ref), common expressions: [`@landcover`](@ref), [`@cropname`](@ref), [`@cropheight`](@ref),
[`@distanceto`](@ref), [`@distancetoedge`](@ref), [`@countanimals`](@ref). [`@distanceto`](@ref), [`@distancetoedge`](@ref), [`@countanimals`](@ref).
The variables `model` and `pos` can be used for checks that don't have a macro available. The variables `model` and `pos` can be used for checks that don't have a macro available.
...@@ -297,7 +297,7 @@ Two example uses of `@habitat` might look like this: ...@@ -297,7 +297,7 @@ Two example uses of `@habitat` might look like this:
movementhabitat = @habitat(@landcover() in (grass agriculture soil)) movementhabitat = @habitat(@landcover() in (grass agriculture soil))
nestinghabitat = @habitat((@landcover() == grass || nestinghabitat = @habitat((@landcover() == grass ||
(@landcover() == agriculture && @croptype() != maize && (@landcover() == agriculture && @cropname() != "maize" &&
@cropheight() < 10)) && @cropheight() < 10)) &&
@distanceto(forest) > 20) @distanceto(forest) > 20)
``` ```
...@@ -333,14 +333,14 @@ macro landcover() ...@@ -333,14 +333,14 @@ macro landcover()
end end
""" """
@croptype @cropname
Return the local croptype, or nothing if there is no crop here. Return the name of the local croptype, or nothing if there is no crop here.
This is a utility wrapper that can only be used nested within [`@phase`](@ref) This is a utility wrapper that can only be used nested within [`@phase`](@ref)
or [`@habitat`](@ref). or [`@habitat`](@ref).
""" """
macro croptype() macro cropname()
:(croptype($(esc(:pos)), $(esc(:model)))) :(cropname($(esc(:pos)), $(esc(:model))))
end end
""" """
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
landscape = Ps.initlandscape(TESTSETTINGS["world.landcovermap"], landscape = Ps.initlandscape(TESTSETTINGS["world.landcovermap"],
TESTSETTINGS["world.farmfieldsmap"]) TESTSETTINGS["world.farmfieldsmap"])
space = GridSpace(size(landscape), periodic=false) space = GridSpace(size(landscape), periodic=false)
properties = Dict{Symbol,Any}(:landscape=>landscape, :settings=>TESTSETTINGS) properties = Dict{Symbol,Any}(:landscape=>landscape, :settings=>TESTSETTINGS,
:date=>TESTSETTINGS["core.startdate"])
model = AgentBasedModel(FarmPlot, space, properties=properties, warn=false) model = AgentBasedModel(FarmPlot, space, properties=properties, warn=false)
# these tests are specific to the Jena maps # these tests are specific to the Jena maps
@test_logs (:info, "Initialised 2092 farm plots.") match_mode=:any Ps.initfields!(model) @test_logs (:info, "Initialised 2092 farm plots.") match_mode=:any Ps.initfields!(model)
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
model = smalltestlandscape() model = smalltestlandscape()
model.landscape[6,6] = Pixel(Ps.agriculture, 1, []) model.landscape[6,6] = Pixel(Ps.agriculture, 1, [])
species::Dict{String,Any} = Dict("name"=>"test_animal") species::Dict{String,Any} = Dict("name"=>"test_animal")
add_agent!((6,6), FarmPlot, model, [(6,6)], Ps.wheat, 1.2, 3.4) add_agent!((6,6), FarmPlot, model, [(6,6)], Ps.wheat, 1.2, 3.4) #FIXME
add_agent!((3,3), Animal, model, species, Ps.male, 1) add_agent!((3,3), Animal, model, species, Ps.male, 1)
add_agent!((4,4), Animal, model, species, Ps.female, 1) add_agent!((4,4), Animal, model, species, Ps.female, 1)
# create a set of habitat descriptors # create a set of habitat descriptors
h1 = @habitat(@landcover() == Ps.water) h1 = @habitat(@landcover() == Ps.water)
h2 = @habitat(@croptype() == Ps.wheat && h2 = @habitat(@cropname() == "wheat" &&
@cropheight() < 2) @cropheight() < 2)
h3 = @habitat(@distanceto(Ps.water) > 2 && h3 = @habitat(@distanceto(Ps.water) > 2 &&
@distancetoedge() <= 2) @distancetoedge() <= 2)
...@@ -77,7 +77,7 @@ end ...@@ -77,7 +77,7 @@ end
@phase life begin @phase life begin
@debug "$(Persefone.animalid(animal)) is swimming happily in its pond." @debug "$(Persefone.animalid(animal)) is swimming happily in its pond."
@respond Persefone.pesticide @kill(@trait(pesticidemortality), "poisoning") @respond Persefone.pesticide @kill(@trait(pesticidemortality), "poisoning")
@respond Persefone.harvest @setphase(drought) @respond Persefone.harvesting @setphase(drought)
@debug "Animal: $animal" @debug "Animal: $animal"
if @trait(sex) == Persefone.female && @countanimals() < 3 && if @trait(sex) == Persefone.female && @countanimals() < 3 &&
@trait(age) >= @trait(ageofmaturity) && @landcover() == Persefone.water @trait(age) >= @trait(ageofmaturity) && @landcover() == Persefone.water
...@@ -103,7 +103,7 @@ end ...@@ -103,7 +103,7 @@ end
@test Ps.countanimals((1,1), model, radius=4) == 0 @test Ps.countanimals((1,1), model, radius=4) == 0
@test Ps.countanimals(pond, model) == 2 @test Ps.countanimals(pond, model) == 2
@test model[1].age == 0 @test model[1].age == 0
createevent!(model, [pond], Ps.harvest) createevent!(model, [pond], Ps.harvesting)
@test_logs((:debug, "Mermaid 1 is swimming happily in its pond."), @test_logs((:debug, "Mermaid 1 is swimming happily in its pond."),
(:debug, "Mermaid 2 is swimming happily in its pond."), (:debug, "Mermaid 2 is swimming happily in its pond."),
min_level=Logging.Debug, match_mode=:any, min_level=Logging.Debug, match_mode=:any,
......
...@@ -45,9 +45,12 @@ function smalltestlandscape() ...@@ -45,9 +45,12 @@ function smalltestlandscape()
weather = Ps.initweather(TESTSETTINGS["world.weatherfile"], weather = Ps.initweather(TESTSETTINGS["world.weatherfile"],
TESTSETTINGS["core.startdate"], TESTSETTINGS["core.startdate"],
TESTSETTINGS["core.enddate"]) TESTSETTINGS["core.enddate"])
crops = Ps.readcropparameters(TESTSETTINGS["crop.cropfile"],
TESTSETTINGS["crop.growthfile"])
properties = Dict{Symbol,Any}(:date=>TESTSETTINGS["core.startdate"], properties = Dict{Symbol,Any}(:date=>TESTSETTINGS["core.startdate"],
:landscape=>landscape, :landscape=>landscape,
:weather=>weather, :weather=>weather,
:crops=>crops,
:events=>Vector{FarmEvent}(), :events=>Vector{FarmEvent}(),
:logger=>global_logger(), :logger=>global_logger(),
:dataoutputs=>Vector{DataOutput}(), :dataoutputs=>Vector{DataOutput}(),
......
...@@ -32,6 +32,6 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect ...@@ -32,6 +32,6 @@ insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect
[crop] [crop]
cropmodel = "almass" # crop growth model to use, "almass" or "aquacrop" cropmodel = "almass" # crop growth model to use, "almass" or "aquacrop"
cropfile = "data/crop_data_general.csv" # file with general crop parameters cropfile = "crop_data_general.csv" # file with general crop parameters
growthfile = "data/almass_crop_growth_curves.csv" # file with crop growth parameters growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment