From d141b3d324579617b60f2b58b1470046565289a8 Mon Sep 17 00:00:00 2001
From: Marco Matthies <71844+marcom@users.noreply.github.com>
Date: Mon, 19 Aug 2024 03:00:10 +0200
Subject: [PATCH] Fix some of the failures in the unit tests

- fix calls to `ALMaSS.CropType()`

- fix calls to `FarmPlot()`

- temporarily deal with `group` column not present in ALMaSS growth
  curves csv file

- fix farm model settings in parameter toml files under `test/`
---
 src/crop/almass.jl                   | 5 ++++-
 test/crop_tests.jl                   | 8 +++++---
 test/test_parameters.toml            | 4 +++-
 test/test_parameters_almass.toml     | 4 +++-
 test/test_parameters_simplecrop.toml | 4 +++-
 5 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/crop/almass.jl b/src/crop/almass.jl
index 891cbcf..eb7db59 100644
--- a/src/crop/almass.jl
+++ b/src/crop/almass.jl
@@ -172,7 +172,10 @@ function readcropparameters(generalcropfile::String, growthfile::String)
                                     filter(x -> x.nutrient_status=="high"))
         lownuts = buildgrowthcurve(cropgrowthdata |>
                                    filter(x -> x.nutrient_status=="low"))
-        croptypes[crop.name] = CropType(crop.name, crop.group, crop.minsowdate, crop.maxsowdate,
+        # TODO: set crop group temporarily until there is a column in
+        # the csv file
+        crop_group = "CROP_GROUP_NOT_SET"
+        croptypes[crop.name] = CropType(crop.name, crop_group, crop.minsowdate, crop.maxsowdate,
                                         crop.minharvestdate, crop.maxharvestdate,
                                         crop.mingrowthtemp, highnuts, lownuts)
     end
diff --git a/test/crop_tests.jl b/test/crop_tests.jl
index eb6b3e6..93e233c 100644
--- a/test/crop_tests.jl
+++ b/test/crop_tests.jl
@@ -19,13 +19,15 @@ const TESTPARAM_SIMPLECROP = joinpath(pkgdir(Persefone), "test", "test_parameter
 end
 
 @testset "Submodule ALMaSS" begin
-    ct = Ps.ALMaSS.CropType("olive tree", missing, missing, missing, missing, missing,
-                            missing, missing)
+    ct = Ps.ALMaSS.CropType("olive tree", "no_crop_group",
+                            missing, missing, missing, missing, missing, missing, missing)
     id = 0
     pixels = [(0, 0)]
     farmer = 0
+    mature = false
+    events = Ps.Management[]
     fp = FarmPlot(id, pixels, farmer,
-                  Ps.ALMaSS.CropState(ct, Ps.ALMaSS.janfirst, 0.0, 0.0m, 0.0, 0.0, Ps.Management[]))
+                  Ps.ALMaSS.CropState(ct, Ps.ALMaSS.janfirst, 0.0, 0.0m, 0.0, 0.0, mature, events))
     @test fp isa FarmPlot
     @test fp isa FarmPlot{Ps.ALMaSS.CropState}
     @test croptype(fp) isa Ps.ALMaSS.CropType
diff --git a/test/test_parameters.toml b/test/test_parameters.toml
index 0a8e405..089712e 100644
--- a/test/test_parameters.toml
+++ b/test/test_parameters.toml
@@ -28,7 +28,9 @@ 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)
+farmmodel = "BasicFarmer" # which version of the farm model to use
+setaside = 0.04 # proportion of farm area set aside as fallow
+fieldoutfreq = "daily" # output frequency for crop/field data, daily/monthly/yearly/end/never
 
 [nature]
 targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate - example species
diff --git a/test/test_parameters_almass.toml b/test/test_parameters_almass.toml
index 1308029..159e59d 100644
--- a/test/test_parameters_almass.toml
+++ b/test/test_parameters_almass.toml
@@ -28,7 +28,9 @@ 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)
+farmmodel = "BasicFarmer" # which version of the farm model to use
+setaside = 0.04 # proportion of farm area set aside as fallow
+fieldoutfreq = "daily" # output frequency for crop/field data, daily/monthly/yearly/end/never
 
 [nature]
 targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate - example species
diff --git a/test/test_parameters_simplecrop.toml b/test/test_parameters_simplecrop.toml
index fc199a8..b7c08f1 100644
--- a/test/test_parameters_simplecrop.toml
+++ b/test/test_parameters_simplecrop.toml
@@ -28,7 +28,9 @@ 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)
+farmmodel = "BasicFarmer" # which version of the farm model to use
+setaside = 0.04 # proportion of farm area set aside as fallow
+fieldoutfreq = "daily" # output frequency for crop/field data, daily/monthly/yearly/end/never
 
 [nature]
 targetspecies = ["Wolpertinger", "Wyvern"] # list of target species to simulate - example species
-- 
GitLab