diff --git a/test/io_tests.jl b/test/io_tests.jl index 475c1daaa031e476a889651bab292e82db73b10a..a9dd780e24fc9bff05ea7c3c26d3a76a9a37af27 100644 --- a/test/io_tests.jl +++ b/test/io_tests.jl @@ -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))) diff --git a/test/landscape_tests.jl b/test/landscape_tests.jl index 24f0481228372a83ed798f841468b73cf12c34c0..b02ee20006d10a7ece354da82b9f35579ba8d424 100644 --- a/test/landscape_tests.jl +++ b/test/landscape_tests.jl @@ -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 == [] diff --git a/test/nature_tests.jl b/test/nature_tests.jl index b8d4937bee3af19dbf633bb0c5645b8b1934d82d..661ea5791a8ba54834579013127637b1113d90a3 100644 --- a/test/nature_tests.jl +++ b/test/nature_tests.jl @@ -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."), diff --git a/test/simulation_tests.jl b/test/simulation_tests.jl index 4ef393c89b6126fefc9b30a49e2cbe1933980c80..d4a2d0b50aad367e757617cce7ad8a86057ac968 100644 --- a/test/simulation_tests.jl +++ b/test/simulation_tests.jl @@ -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 + diff --git a/test/test_parameters.toml b/test/test_parameters.toml index 0e3e021262d79cac888fc2961751792f301c8c69..3e5e0462a679d463a11cd1a5403dcc0f10631340 100644 --- a/test/test_parameters.toml +++ b/test/test_parameters.toml @@ -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)