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

Wrote simulation tests

There's still at least one bug with the RNG
parent dbff4414
Branches
Tags
No related merge requests found
......@@ -8,7 +8,7 @@
space = GridSpace((10,10), periodic=false)
model = AgentBasedModel(Animal, space, properties=properties, warn=false)
@test @param(core.configfile) == TESTPARAMETERS
@test @param(core.startdate) == Date(2022, 1, 1)
@test @param(core.startdate) == Date(2022, 2, 1)
@test @param(nature.targetspecies) == ["Wolpertinger", "Wyvern"]
@param(core.enddate) = Date(2022,1,3)
@test @param(core.enddate) == Date(2022,1,3)
......@@ -22,7 +22,7 @@ end
model = AgentBasedModel(Animal, space, properties=properties, warn=false)
# test that the output directory is created with all files
outdir = @param(core.outdir)
logstring = "Setting up output directory results_testsuite_$(Dates.today())_s1"
logstring = "Setting up output directory results_testsuite_$(Dates.today())_s1."
@test_logs (:debug, logstring) min_level=Logging.Debug Ps.setupdatadir(model)
@test isdir(outdir)
@test isfile(joinpath(outdir, @param(core.landcovermap)))
......
......@@ -61,11 +61,11 @@ end
@test model.landscape[1,1].events == [Ps.tillage, Ps.sowing]
@test model.landscape[2,1].events == [Ps.tillage]
@test model.landscape[2,2].events == [Ps.sowing]
@test_logs (:info, "Simulating day 2022-01-01.") match_mode=:any stepsimulation!(model)
@test_logs (:info, "Simulating day 2022-02-01.") match_mode=:any stepsimulation!(model)
@test model.landscape[1,1].events == [Ps.sowing]
@test model.landscape[2,1].events == []
@test model.landscape[2,2].events == [Ps.sowing]
@test_logs (:info, "Simulating day 2022-01-02.") match_mode=:any stepsimulation!(model)
@test_logs (:info, "Simulating day 2022-02-02.") match_mode=:any stepsimulation!(model)
@test model.landscape[1,1].events == []
@test model.landscape[2,1].events == []
@test model.landscape[2,2].events == []
......
......@@ -68,8 +68,8 @@ end
@testset "Species macros" begin
# create a model landscape and a test species
#TODO test @rand
model = smalltestlandscape(Union{Animal,Farmer,FarmPlot})
@species Mermaid begin
ageofmaturity = 2
pesticidemortality = 1.0
......@@ -85,7 +85,8 @@ end
end
end
@phase drought begin
@debug "$(Persephone.animalid(animal)) is trying to survive a drought."
n = sum(1 for a in @neighbours(0))
@debug "$(Persephone.animalid(animal)) is experiencing drought with $n neighbour(s)."
@respond Persephone.sowing @setphase(life)
end
end
......@@ -110,8 +111,8 @@ end
@test model[1].age == 1
@test model[2].traits["phase"] == "drought"
createevent!(model, [pond], Ps.sowing)
@test_logs((:debug, "Mermaid 1 is trying to survive a drought."),
(:debug, "Mermaid 2 is trying to survive a drought."),
@test_logs((:debug, "Mermaid 1 is experiencing drought with 1 neighbour(s)."),
(:debug, "Mermaid 2 is experiencing drought with 1 neighbour(s)."),
min_level=Logging.Debug, match_mode=:any,
stepsimulation!(model))
@test_logs((:debug, "Mermaid 1 is swimming happily in its pond."),
......
......@@ -3,4 +3,31 @@
### These are the tests for the core simulation functions.
###
#TODO
@testset "Model initialisation" begin
model = initialise(TESTPARAMETERS)
@test typeof(model.settings) == Dict{String, Dict{String, Any}}
@test model.date == Date(2022,2,1)
@test typeof(model.landscape) == Matrix{Pixel}
@test typeof(model.dataoutputs) == Vector{DataOutput}
@test length(model.dataoutputs) == 2
@test model.events == Vector{FarmEvent}()
@test nagents(model) == 2092+10+28
end
@testset "Model simulation" begin
Random.seed!(1)
@test isapprox(rand(), 0.07337, atol=0.0001)
model = simulate(TESTPARAMETERS, 218)
@test @param(core.seed) == 218
@test model.date == Date(2022,4,1)
nwol = sum((typeof(a)==Animal && a.traits["name"]=="Wolpertinger") for a in allagents(model))
nwyv = sum((typeof(a)==Animal && a.traits["name"]=="Wyvern") for a in allagents(model))
#FIXME these still fail - although it might not be that clever to rely on random model outcomes
@test nwol == 32
@test nwyv == 9
# To retain reproducibility, the model code must never use the global RNG.
# If this next test fails, that requirement has probably been violated somewhere.
#FIXME it does fail... Might it be called by some dependency?
@test isapprox(rand(), 0.34924, atol=0.0001)
end
......@@ -9,11 +9,11 @@ landcovermap = "landcover_jena.tif" # location of the landcover map
farmfieldsmap = "fields_jena.tif" # location of the field geometry map
outdir = "results_testsuite" # location and name of the output folder
overwrite = true # overwrite the output directory? (true/false/"ask")
loglevel = "debug" # verbosity level: "debug", "info", "quiet"
loglevel = "quiet" # verbosity level: "debug", "info", "quiet"
seed = 1 # seed value for the RNG (0 -> random value)
# dates to start and end the simulation
startdate = 2022-01-01
enddate = 2022-01-02
startdate = 2022-02-01
enddate = 2022-03-31
[farm]
farmmodel = "FieldManager" # which version of the farm model to use (not yet implemented)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment