diff --git a/test/io_tests.jl b/test/io_tests.jl index de75781afc8f997b64f75fec715c6d677ae26ce2..214e54921881f4be1d00cd51a2266c9a6aa3daa1 100644 --- a/test/io_tests.jl +++ b/test/io_tests.jl @@ -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 diff --git a/test/landscape_tests.jl b/test/landscape_tests.jl index 3a29f872a27dea2af4b5c60b662692dbd1caeae3..10bd212907286e3ffd36330eaf4b77595ce5dbcc 100644 --- a/test/landscape_tests.jl +++ b/test/landscape_tests.jl @@ -16,7 +16,7 @@ @test Ps.landcover((1100,1100), model) == Ps.builtup @test Ps.averagefieldsize(model) == 5.37 @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 @testset "Event system" begin @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index c761eeb1b3f79f7424d5f4c9ca8fc9dbcd6a8f1e..db4870c5988f9975de6266b066315f23c82bf33a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,20 +39,20 @@ function inittestmodel(smallmap=true) TESTSETTINGS["core.enddate"]) crops = Ps.readcropparameters(TESTSETTINGS["crop.cropfile"], TESTSETTINGS["crop.growthfile"]) - model = SimulationModel(TESTSETTINGS, - StableRNG(TESTSETTINGS["core.seed"]), - global_logger(), - Vector{DataOutput}(), - Dict{String, DataFrame}(), - TESTSETTINGS["core.startdate"], - landscape, - weather, - crops, - Vector{Farmer}(), - Vector{FarmPlot}(), - Vector{Union{Animals,Nothing}}(), - Vector{Pair{Animal, Date}}(), - Vector{FarmEvent}()) + model = AgricultureModel(TESTSETTINGS, + StableRNG(TESTSETTINGS["core.seed"]), + global_logger(), + Vector{DataOutput}(), + Dict{String, DataFrame}(), + TESTSETTINGS["core.startdate"], + landscape, + weather, + crops, + Vector{Farmer}(), + Vector{FarmPlot}(), + Vector{Union{Animal,Nothing}}(), + Vector{Pair{Animal, Date}}(), + Vector{FarmEvent}()) model end @@ -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 diff --git a/test/simulation_tests.jl b/test/simulation_tests.jl index 51de43adf8f8d5a05e7486c2b85e4a6693c84bb0..5b4b42e1ae0b56ab53b7909445fa9cd373a5e301 100644 --- a/test/simulation_tests.jl +++ b/test/simulation_tests.jl @@ -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."),