From 77f67aa2d99a5fb99143be50cf38af04a351121c Mon Sep 17 00:00:00 2001
From: Marco Matthies <71844+marcom@users.noreply.github.com>
Date: Wed, 17 Jul 2024 21:35:48 +0200
Subject: [PATCH] Add tests for model initialisation with different crop models
 (ALMaSS, SimpleCrop)

---
 src/core/simulation.jl               |  1 -
 test/crop_tests.jl                   | 12 ++++++--
 test/test_parameters_almass.toml     | 44 ++++++++++++++++++++++++++++
 test/test_parameters_simplecrop.toml | 43 +++++++++++++++++++++++++++
 4 files changed, 97 insertions(+), 3 deletions(-)
 create mode 100644 test/test_parameters_almass.toml
 create mode 100644 test/test_parameters_simplecrop.toml

diff --git a/src/core/simulation.jl b/src/core/simulation.jl
index 7c2e8f2..ed8b2da 100644
--- a/src/core/simulation.jl
+++ b/src/core/simulation.jl
@@ -23,7 +23,6 @@ mutable struct AgricultureModel <: SimulationModel
     weather::Dict{Date,Weather}
     crops::Dict{String,ALMaSS.CropType}
     farmers::Vector{Farmer}
-    #farmplots::Vector{ALMaSS.FarmPlot}
     farmplots::Vector{AbstractFarmPlot}
     animals::Vector{Union{Animal,Nothing}}
     migrants::Vector{Pair{Animal,Date}}
diff --git a/test/crop_tests.jl b/test/crop_tests.jl
index 2ab0aff..53ee874 100644
--- a/test/crop_tests.jl
+++ b/test/crop_tests.jl
@@ -1,6 +1,14 @@
 ### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
 ###
-### These are the tests for the crop growth model.
+### These are the tests for the crop growth models.
 ###
 
-#TODO
+const TESTPARAM_ALMASS = joinpath(pkgdir(Persefone), "test", "test_parameters_almass.toml")
+const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameters_simplecrop.toml")
+
+@testset "Model initialisation" begin
+    for paramfile in (TESTPARAM_ALMASS, TESTPARAM_SIMPLECROP)
+        model = initialise(paramfile)
+        @test model isa AgricultureModel
+    end
+end
diff --git a/test/test_parameters_almass.toml b/test/test_parameters_almass.toml
new file mode 100644
index 0000000..94d6a9a
--- /dev/null
+++ b/test/test_parameters_almass.toml
@@ -0,0 +1,44 @@
+### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
+###
+### This configuration file is used for the test suite.
+###
+
+#XXX remember that changes here may break tests!
+	
+[core]
+configfile = "test_parameters.toml" # location of the configuration file
+outdir = "results_testsuite" # location and name of the output folder
+logoutput = "both"
+overwrite = true # overwrite the output directory? (true/false/"ask")
+csvoutput = true # save collected data in CSV files
+visualise = true # generate result graphs
+storedata = true # keep collected data in memory
+loglevel = "warn" # verbosity level: "debug", "info", "warn"
+processors = 6 # number of processors to use on parallel runs
+seed = 1 # seed value for the RNG (0 -> random value)
+# dates to start and end the simulation
+startdate = 2022-02-01
+enddate = 2022-03-31
+
+[world]
+mapdirectory = "." # the directory in which all geographic data are stored
+mapresolution = 10 # map resolution in meters
+landcovermap = "landcover_jena.tif" # location of the landcover map
+farmfieldsmap = "fields_jena.tif" # location of the field geometry map
+weatherfile = "weather_jena.csv" # location of the weather data file
+
+[farm]
+farmmodel = "FieldManager" # which version of the farm model to use (not yet implemented)
+
+[nature]
+targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate - example species
+#targetspecies = ["Skylark"] # list of target species to simulate
+popoutfreq = "daily" # output frequency population-level data, daily/monthly/yearly/end/never
+indoutfreq = "daily" # output frequency individual-level data, daily/monthly/yearly/end/never
+insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect growth ("weather" is not yet implemented)
+	
+[crop]
+cropmodel = "almass" # crop growth model to use, "almass", "aquacrop", or "simple"
+cropfile = "crop_data_general.csv" # file with general crop parameters
+growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters
+
diff --git a/test/test_parameters_simplecrop.toml b/test/test_parameters_simplecrop.toml
new file mode 100644
index 0000000..c0fe15c
--- /dev/null
+++ b/test/test_parameters_simplecrop.toml
@@ -0,0 +1,43 @@
+### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
+###
+### This configuration file is used for the test suite.
+###
+
+#XXX remember that changes here may break tests!
+	
+[core]
+configfile = "test_parameters.toml" # location of the configuration file
+outdir = "results_testsuite" # location and name of the output folder
+logoutput = "both"
+overwrite = true # overwrite the output directory? (true/false/"ask")
+csvoutput = true # save collected data in CSV files
+visualise = true # generate result graphs
+storedata = true # keep collected data in memory
+loglevel = "warn" # verbosity level: "debug", "info", "warn"
+processors = 6 # number of processors to use on parallel runs
+seed = 1 # seed value for the RNG (0 -> random value)
+# dates to start and end the simulation
+startdate = 2022-02-01
+enddate = 2022-03-31
+
+[world]
+mapdirectory = "." # the directory in which all geographic data are stored
+mapresolution = 10 # map resolution in meters
+landcovermap = "landcover_jena.tif" # location of the landcover map
+farmfieldsmap = "fields_jena.tif" # location of the field geometry map
+weatherfile = "weather_jena.csv" # location of the weather data file
+
+[farm]
+farmmodel = "FieldManager" # which version of the farm model to use (not yet implemented)
+
+[nature]
+targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate - example species
+#targetspecies = ["Skylark"] # list of target species to simulate
+popoutfreq = "daily" # output frequency population-level data, daily/monthly/yearly/end/never
+indoutfreq = "daily" # output frequency individual-level data, daily/monthly/yearly/end/never
+insectmodel = ["season", "habitat", "pesticides"] # which factors affect insect growth ("weather" is not yet implemented)
+	
+[crop]
+cropmodel = "simple" # crop growth model to use, "almass", "aquacrop", or "simple"
+cropfile = "crop_data_general.csv" # file with general crop parameters
+growthfile = "almass_crop_growth_curves.csv" # file with crop growth parameters
-- 
GitLab