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

Added landscape tests

parent 272e76a2
Branches
Tags
No related merge requests found
File moved
...@@ -23,6 +23,7 @@ using ...@@ -23,6 +23,7 @@ using
TOML TOML
## define exported functions and variables ## define exported functions and variables
#XXX export all types?
export export
param, param,
simulate, simulate,
......
...@@ -22,7 +22,7 @@ function initialise(config::String=PARAMFILE) ...@@ -22,7 +22,7 @@ function initialise(config::String=PARAMFILE)
properties = Dict{Symbol,Any}(:date=>param("core.startdate"), properties = Dict{Symbol,Any}(:date=>param("core.startdate"),
:landscape=>landscape, :landscape=>landscape,
:events=>events) :events=>events)
@debug "Setting up model now" @debug "Setting up model."
model = AgentBasedModel(Union{Farmer,Animal,FarmPlot}, space, properties=properties, model = AgentBasedModel(Union{Farmer,Animal,FarmPlot}, space, properties=properties,
rng=Random.Xoshiro(param("core.seed")), warn=false) rng=Random.Xoshiro(param("core.seed")), warn=false)
# initialise submodels # initialise submodels
......
...@@ -59,7 +59,7 @@ function initfields!(model::AgentBasedModel) ...@@ -59,7 +59,7 @@ function initfields!(model::AgentBasedModel)
@debug "Initialised $n farm plots." @debug "Initialised $n farm plots."
end end
#XXX only needed during development, can be deleted again #XXX only needed during development, can be deleted again?
function countfields(model::AgentBasedModel) function countfields(model::AgentBasedModel)
ids::Vector{Int64} = [] ids::Vector{Int64} = []
width, height = size(model.landscape) width, height = size(model.landscape)
......
### Persephone - a socio-economic-ecological model of European agricultural landscapes.
###
### This tests the core input and output functions.
###
#TODO
...@@ -3,4 +3,50 @@ ...@@ -3,4 +3,50 @@
### These are the tests for the core landscape functions. ### These are the tests for the core landscape functions.
### ###
#TODO @testset "Landscape initialisation" begin
# initialise the landscape part of the model
landscape = Persephone.initlandscape()
space = GridSpace(size(landscape), periodic=false)
properties = Dict{Symbol,Any}(:landscape=>landscape)
model = AgentBasedModel(Persephone.FarmPlot, space, properties=properties,
rng=Random.Xoshiro(param("core.seed")), warn=false)
Persephone.initfields!(model)
# these tests are specific to the Jena maps
@test size(model.landscape) == (1754, 1602)
@test Persephone.landcover(model, (100,100)) == Persephone.forest
@test Persephone.landcover(model, (300,1)) == Persephone.soil
@test Persephone.landcover(model, (500,1)) == Persephone.nodata
@test Persephone.landcover(model, (400,400)) == Persephone.grass
@test Persephone.landcover(model, (800,800)) == Persephone.agriculture
@test Persephone.landcover(model, (1100,1100)) == Persephone.builtup
@test Persephone.countfields(model) == 2092
@test Persephone.averagefieldsize(model) == 5.37
@test count(f -> ismissing(f.fieldid), model.landscape) == 1685573
@test length(Persephone.farmplot(model, (800,800)).pixels) == 4049
end
@testset "Event system" begin
# initialise a basic model landscape
landscape = Persephone.initlandscape()
space = GridSpace(size(landscape), periodic=false)
properties = Dict{Symbol,Any}(:date=>param("core.startdate"),
:landscape=>landscape,
:events=>Vector{Persephone.FarmEvent}())
model = AgentBasedModel(Union{Persephone.Farmer,Persephone.Animal,Persephone.FarmPlot},
space, properties=properties,
rng=Random.Xoshiro(param("core.seed")), warn=false)
# create some events and see whether they show up on the map and disappear as they should
Persephone.createevent!(model, [(1,1), (1,2), (1,3), (2,1), (2,3)], Persephone.tillage)
Persephone.createevent!(model, [(1,1), (1,2), (1,3), (2,2)], Persephone.sowing, 2)
@test model.landscape[1,1].events == [Persephone.tillage, Persephone.sowing]
@test model.landscape[2,1].events == [Persephone.tillage]
@test model.landscape[2,2].events == [Persephone.sowing]
stepsimulation!(model)
@test model.landscape[1,1].events == [Persephone.sowing]
@test model.landscape[2,1].events == []
@test model.landscape[2,2].events == [Persephone.sowing]
stepsimulation!(model)
@test model.landscape[1,1].events == []
@test model.landscape[2,1].events == []
@test model.landscape[2,2].events == []
end
...@@ -8,9 +8,13 @@ Pkg.activate("..") ...@@ -8,9 +8,13 @@ Pkg.activate("..")
using Persephone using Persephone
using Test using Test
using Random
using Agents
@testset "Persephone Tests" begin @testset "Persephone Tests" begin
Persephone.initsettings("test_parameters.toml")
@testset "Core model" begin @testset "Core model" begin
include("io_tests.jl")
include("landscape_tests.jl") include("landscape_tests.jl")
include("simulation_tests.jl") include("simulation_tests.jl")
end end
...@@ -23,4 +27,5 @@ using Test ...@@ -23,4 +27,5 @@ using Test
@testset "Farm model" begin @testset "Farm model" begin
include("farm_tests.jl") include("farm_tests.jl")
end end
rm(param("core.outdir"), force=true, recursive=true)
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment