Skip to content
Snippets Groups Projects
  • xo30xoqa's avatar
    e82aa559
    Rewrote insect submodel · e82aa559
    xo30xoqa authored
    It is now contained within a single function that can be called at
    need, rather than being calculated every day for every pixel.
    e82aa559
    History
    Rewrote insect submodel
    xo30xoqa authored
    It is now contained within a single function that can be called at
    need, rather than being calculated every day for every pixel.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
runtests.jl 2.33 KiB
### Persefone - a socio-economic-ecological model of European agricultural landscapes.
###
### This is the top-level file of the Persefone test suite. Execute this to run all tests.
###

using Pkg
Pkg.activate("..")

using Agents
using Dates
using Logging
using LoggingExtras
using Persefone
using Random
using StableRNGs
using Test

const Ps = Persefone

const TESTPARAMETERS = joinpath(pkgdir(Persefone), "test/test_parameters.toml")
const TESTSETTINGS = Ps.getsettings(TESTPARAMETERS)

"""
    smalltestlandscape()

Create a 6x6 landscape with three land cover types for testing:

    F F F F F F
    F F F F F F
    F F F F F F
    F F F F F W
    F F G G G G
    F F G G G G
"""
function smalltestlandscape()
    landscape = Matrix{Pixel}(undef, 6, 6)
    for x in 1:6
        for y in 1:6
            (x in (1:2) || y in (1:4)) ? lc = Ps.forest : lc = Ps.grass
            landscape[x,y] = Pixel(lc, missing, [])
        end
    end
    landscape[6,4] = Pixel(Ps.water, 0, [])
    space = GridSpace(size(landscape), periodic=false)
    properties = Dict{Symbol,Any}(:date=>TESTSETTINGS["core.startdate"],
                                  :landscape=>landscape,
                                  :events=>Vector{FarmEvent}(),
                                  :logger=>global_logger(),
                                  :dataoutputs=>Vector{DataOutput}(),
                                  :settings=>TESTSETTINGS)
    return AgentBasedModel(Union{Farmer,Animal,FarmPlot}, space, properties=properties,
                           rng=StableRNG(TESTSETTINGS["core.seed"]), warn=false)
end

@testset "Persefone Tests" begin
    @testset "Core model" begin
        include("io_tests.jl")
        include("landscape_tests.jl")
        include("simulation_tests.jl")
    end
    @testset "Nature model" begin
        include("nature_tests.jl")
    end
    @testset "Crop growth model" begin
        include("crop_tests.jl")
    end
    @testset "Farm model" begin
        include("farm_tests.jl")
    end
    rm(TESTSETTINGS["core.outdir"], force=true, recursive=true)
end

# NOTE: Due to an issue with Julia (https://github.com/JuliaLang/julia/issues/48456),
# whenever we are using `@test_logs` with a function that takes a model object, we have
# to wrap that model object in `Ps.withtestlogger()`. (For an example, see the "Model
# simulation" testset in simulation_tests.jl.)