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
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,7 @@ ...@@ -4,11 +4,7 @@
### ###
@testset "Model configuration" begin @testset "Model configuration" begin
settings = Ps.getsettings(TESTPARAMETERS) model = inittestmodel()
properties = Dict{Symbol,Any}(:settings=>settings)
space = GridSpace((10,10), periodic=false)
model = SimulationModel(Animal, space, properties=properties, warn=false)
@test @param(core.configfile) == basename(TESTPARAMETERS) @test @param(core.configfile) == basename(TESTPARAMETERS)
@test @param(core.startdate) == Date(2022, 2, 1) @test @param(core.startdate) == Date(2022, 2, 1)
@test @param(core.loglevel) == "warn" @test @param(core.loglevel) == "warn"
...@@ -76,11 +72,11 @@ end ...@@ -76,11 +72,11 @@ end
model2 = loadmodelobject(joinpath(@param(core.outdir), "test.dat")) model2 = loadmodelobject(joinpath(@param(core.outdir), "test.dat"))
@test model.date == model2.date @test model.date == model2.date
@test model.settings == model2.settings @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(model))
simulate!(Ps.withtestlogger(model2)) simulate!(Ps.withtestlogger(model2))
@test model.date == model2.date @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) rm(@param(core.outdir), force=true, recursive=true)
@param(core.enddate) = originalenddate @param(core.enddate) = originalenddate
end end
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
@test Ps.landcover((1100,1100), model) == Ps.builtup @test Ps.landcover((1100,1100), model) == Ps.builtup
@test Ps.averagefieldsize(model) == 5.37 @test Ps.averagefieldsize(model) == 5.37
@test count(f -> ismissing(f.fieldid), model.landscape) == 1685573 @test count(f -> ismissing(f.fieldid), model.landscape) == 1685573
@test length(Ps.farmplot((800,800), model).pixels) == 4049 @test length(Ps.farmplot((800,800), model).pixels) == 4049
end end
@testset "Event system" begin @testset "Event system" begin
...@@ -42,6 +42,11 @@ end ...@@ -42,6 +42,11 @@ end
@testset "Landscape functions" begin @testset "Landscape functions" begin
model = inittestmodel() 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.agriculture) == 0
@test Ps.distanceto((2,3), model, Ps.forest) == 2 @test Ps.distanceto((2,3), model, Ps.forest) == 2
@test Ps.distanceto((2,3), model, Ps.grass) == 2 @test Ps.distanceto((2,3), model, Ps.grass) == 2
......
...@@ -39,20 +39,20 @@ function inittestmodel(smallmap=true) ...@@ -39,20 +39,20 @@ function inittestmodel(smallmap=true)
TESTSETTINGS["core.enddate"]) TESTSETTINGS["core.enddate"])
crops = Ps.readcropparameters(TESTSETTINGS["crop.cropfile"], crops = Ps.readcropparameters(TESTSETTINGS["crop.cropfile"],
TESTSETTINGS["crop.growthfile"]) TESTSETTINGS["crop.growthfile"])
model = SimulationModel(TESTSETTINGS, model = AgricultureModel(TESTSETTINGS,
StableRNG(TESTSETTINGS["core.seed"]), StableRNG(TESTSETTINGS["core.seed"]),
global_logger(), global_logger(),
Vector{DataOutput}(), Vector{DataOutput}(),
Dict{String, DataFrame}(), Dict{String, DataFrame}(),
TESTSETTINGS["core.startdate"], TESTSETTINGS["core.startdate"],
landscape, landscape,
weather, weather,
crops, crops,
Vector{Farmer}(), Vector{Farmer}(),
Vector{FarmPlot}(), Vector{FarmPlot}(),
Vector{Union{Animals,Nothing}}(), Vector{Union{Animal,Nothing}}(),
Vector{Pair{Animal, Date}}(), Vector{Pair{Animal, Date}}(),
Vector{FarmEvent}()) Vector{FarmEvent}())
model model
end end
...@@ -78,10 +78,10 @@ function smalltestlandscape() ...@@ -78,10 +78,10 @@ function smalltestlandscape()
(x in (1:2)) ? lc = Ps.forest : (x in (1:2)) ? lc = Ps.forest :
(y == 8) ? lc = Ps.builtup : (y == 8) ? lc = Ps.builtup :
lc = Ps.grass lc = Ps.grass
landscape[x,y] = Pixel(lc, missing, []) landscape[x,y] = Pixel(lc, missing, [], [])
end end
end end
landscape[6,4] = Pixel(Ps.water, 0, []) landscape[6,4] = Pixel(Ps.water, 0, [], [])
landscape landscape
end end
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
@test typeof(model.logger) == TeeLogger{Tuple{ConsoleLogger, ConsoleLogger}} @test typeof(model.logger) == TeeLogger{Tuple{ConsoleLogger, ConsoleLogger}}
@test length(model.dataoutputs) == 2 @test length(model.dataoutputs) == 2
@test model.events == Vector{FarmEvent}() @test model.events == Vector{FarmEvent}()
@test nagents(model) == 2092+10+28 @test Ps.nagents(model) == 2092+10+28 #FIXME 2412 == 2130
end end
@testset "Parameter scanning" begin @testset "Parameter scanning" begin
...@@ -48,8 +48,7 @@ end ...@@ -48,8 +48,7 @@ end
rand1 = rand() rand1 = rand()
Random.seed!(1) Random.seed!(1)
model = initialise(TESTPARAMETERS, 218) 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 rand() == rand1
@test_broken rand() == rand1
Random.seed!(1) Random.seed!(1)
@test @param(core.seed) == 218 @test @param(core.seed) == 218
@test_logs((:info, "Simulating day 2022-02-01."), @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