Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
crop_tests.jl 1.76 KiB
### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
###
### These are the tests for the crop growth models.
###

const TESTPARAM_ALMASS = joinpath(pkgdir(Persefone), "test", "test_parameters_almass.toml")
const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameters_simplecrop.toml")

@testset for paramfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP)
    @testset "Model initialisation" begin
        model = initialise(paramfile)
        @test model isa AgricultureModel
    end
    @testset "Time step" begin
        model = initialise(paramfile)
        stepsimulation!(model)
        @test model isa AgricultureModel
    end
end

@testset "Submodule ALMaSS" begin
    ct = Ps.ALMaSS.CropType("olive tree", missing, missing, missing, missing, missing,
                            missing, missing)
    id = 0
    pixels = [(0, 0)]
    farmer = 0
    fp = FarmPlot(id, pixels, farmer,
                  Ps.ALMaSS.CropState(ct, Ps.ALMaSS.janfirst, 0.0, 0.0m, 0.0, 0.0, Ps.Management[]))
    @test fp isa FarmPlot
    @test fp isa FarmPlot{Ps.ALMaSS.CropState}
    @test croptype(fp) isa Ps.ALMaSS.CropType
    @test cropname(fp) isa String
    @test cropheight(fp) isa Length{Float64}
    @test cropcover(fp) isa Float64
    @test cropyield(fp) isa Float64
end

@testset "Submodule SimpleCrop" begin
    ct = Ps.SimpleCrop.CropType("olive tree")
    id = 0
    pixels = [(0, 0)]
    farmer = 0
    fp = FarmPlot(id, pixels, farmer, Ps.SimpleCrop.CropState(ct, 0.0cm))
    @test fp isa FarmPlot
    @test fp isa FarmPlot{Ps.SimpleCrop.CropState}
    @test croptype(fp) isa Ps.SimpleCrop.CropType
    @test cropname(fp) isa String
    @test cropheight(fp) isa Length{Float64}
    @test cropcover(fp) isa Float64
    @test cropyield(fp) isa Float64
end