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

Upgraded tests to new code structure (except nature tests)

parent 8a958fd9
Branches
No related tags found
No related merge requests found
......@@ -4,11 +4,7 @@
###
@testset "Model configuration" begin
settings = Ps.getsettings(TESTPARAMETERS)
properties = Dict{Symbol,Any}(:settings=>settings)
space = GridSpace((10,10), periodic=false)
model = SimulationModel(Animal, space, properties=properties, warn=false)
model = inittestmodel()
@test @param(core.configfile) == basename(TESTPARAMETERS)
@test @param(core.startdate) == Date(2022, 2, 1)
@test @param(core.loglevel) == "warn"
......@@ -76,11 +72,11 @@ end
model2 = loadmodelobject(joinpath(@param(core.outdir), "test.dat"))
@test model.date == model2.date
@test model.settings == model2.settings
@test length(model.agents) == length(model2.agents)
@test Ps.nagents(model) == Ps.nagents(model2)
simulate!(Ps.withtestlogger(model))
simulate!(Ps.withtestlogger(model2))
@test model.date == model2.date
@test length(model.agents) == length(model2.agents)
@test Ps.nagents(model) == Ps.nagents(model2)
rm(@param(core.outdir), force=true, recursive=true)
@param(core.enddate) = originalenddate
end
......
......@@ -42,6 +42,11 @@ end
@testset "Landscape functions" begin
model = inittestmodel()
@test Ps.directionto((2,3), model, Ps.agriculture) == (0,0)
@test Ps.directionto((2,3), model, Ps.forest) == (-1,2)
@test Ps.directionto((2,3), model, Ps.grass) == (1,2)
@test Ps.directionto((2,3), model, Ps.water) == (4,1)
@test Ps.directionto((2,3), model, Ps.soil) == nothing
@test Ps.distanceto((2,3), model, Ps.agriculture) == 0
@test Ps.distanceto((2,3), model, Ps.forest) == 2
@test Ps.distanceto((2,3), model, Ps.grass) == 2
......
......@@ -39,7 +39,7 @@ function inittestmodel(smallmap=true)
TESTSETTINGS["core.enddate"])
crops = Ps.readcropparameters(TESTSETTINGS["crop.cropfile"],
TESTSETTINGS["crop.growthfile"])
model = SimulationModel(TESTSETTINGS,
model = AgricultureModel(TESTSETTINGS,
StableRNG(TESTSETTINGS["core.seed"]),
global_logger(),
Vector{DataOutput}(),
......@@ -50,7 +50,7 @@ function inittestmodel(smallmap=true)
crops,
Vector{Farmer}(),
Vector{FarmPlot}(),
Vector{Union{Animals,Nothing}}(),
Vector{Union{Animal,Nothing}}(),
Vector{Pair{Animal, Date}}(),
Vector{FarmEvent}())
model
......@@ -78,10 +78,10 @@ function smalltestlandscape()
(x in (1:2)) ? lc = Ps.forest :
(y == 8) ? lc = Ps.builtup :
lc = Ps.grass
landscape[x,y] = Pixel(lc, missing, [])
landscape[x,y] = Pixel(lc, missing, [], [])
end
end
landscape[6,4] = Pixel(Ps.water, 0, [])
landscape[6,4] = Pixel(Ps.water, 0, [], [])
landscape
end
......
......@@ -12,7 +12,7 @@
@test typeof(model.logger) == TeeLogger{Tuple{ConsoleLogger, ConsoleLogger}}
@test length(model.dataoutputs) == 2
@test model.events == Vector{FarmEvent}()
@test nagents(model) == 2092+10+28
@test Ps.nagents(model) == 2092+10+28 #FIXME 2412 == 2130
end
@testset "Parameter scanning" begin
......@@ -48,8 +48,7 @@ end
rand1 = rand()
Random.seed!(1)
model = initialise(TESTPARAMETERS, 218)
#XXX upstream problem with ArgParse (https://github.com/carlobaldassi/ArgParse.jl/issues/121) - should work again with Julia 1.10
@test_broken rand() == rand1
@test rand() == rand1
Random.seed!(1)
@test @param(core.seed) == 218
@test_logs((:info, "Simulating day 2022-02-01."),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment