From db303278c91514aa4f7d810a77b23462147a5e2e Mon Sep 17 00:00:00 2001
From: Dorchies David <david.dorchies@inrae.fr>
Date: Fri, 28 May 2021 11:57:32 +0200
Subject: [PATCH] test(calibration): add tests for Hysteresis version of
 Cemaneige

Refs #120
---
 tests/testthat/test-Calibration.R | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/tests/testthat/test-Calibration.R b/tests/testthat/test-Calibration.R
index 504ecefd..b3b2821a 100644
--- a/tests/testthat/test-Calibration.R
+++ b/tests/testthat/test-Calibration.R
@@ -1,15 +1,18 @@
 context("Calibration")
 
 sModels <- c(
-  "name          data     aggreg ParamFinalR",
-  "GR1A          L0123001 %Y     0.91125",
-  "GR2M          L0123001 %Y%m   259.8228;0.9975",
-  "GR4J          L0123001 NA     223.6315877;0.5781516;97.5143942;2.2177177",
-  "GR5J          L0123001 NA     220.3863609;0.8944531;93.5640705;1.7628720;0.4846427",
-  "GR6J          L0123001 NA     192.8761657;0.6933087;49.1783293;2.2145422;0.5088240;6.8146261",
-  "CemaNeigeGR4J L0123001 NA     2.043839e+02;5.781516e-01;1.025141e+02;2.217718e+00;1.501502e-03;1.432036e+01",
-  "CemaNeigeGR5J L0123001 NA     1.983434e+02;8.747758e-01;9.849443e+01;1.768769e+00;4.829830e-01;1.501502e-03;1.432036e+01",
-  "CemaNeigeGR6J L0123001 NA     184.9341841;0.5551637;59.7398917;2.2177177;0.4760000;6.0496475;0.0000000;14.4642868"
+  "name          IsHyst data     aggreg ParamFinalR",
+  "GR1A          FALSE  L0123001 %Y     0.91125",
+  "GR2M          FALSE  L0123001 %Y%m   259.8228;0.9975",
+  "GR4J          FALSE  L0123001 NA     223.6315877;0.5781516;97.5143942;2.2177177",
+  "GR5J          FALSE  L0123001 NA     220.3863609;0.8944531;93.5640705;1.7628720;0.4846427",
+  "GR6J          FALSE  L0123001 NA     192.8761657;0.6933087;49.1783293;2.2145422;0.5088240;6.8146261",
+  "CemaNeigeGR4J FALSE  L0123001 NA     2.043839e+02;5.781516e-01;1.025141e+02;2.217718e+00;1.501502e-03;1.432036e+01",
+  "CemaNeigeGR5J FALSE  L0123001 NA     1.983434e+02;8.747758e-01;9.849443e+01;1.768769e+00;4.829830e-01;1.501502e-03;1.432036e+01",
+  "CemaNeigeGR6J FALSE  L0123001 NA     184.9341841;0.5551637;59.7398917;2.2177177;0.4760000;6.0496475;0.0000000;14.4642868",
+  "CemaNeigeGR4J TRUE   L0123001 NA     208.5127103;0.5781516;102.5140641;2.2274775;0.0000000;6.7644613;8.0000000;1.0000000",
+  "CemaNeigeGR5J TRUE   L0123001 NA     202.350228;0.901525;98.494430;1.788288;0.483984;0.000000;7.401500;6.100000;1.000000",
+  "CemaNeigeGR6J TRUE   L0123001 NA     188.67010241;0.56662930;60.34028760;2.22747748;0.47600000;5.98945247;0.03203203;7.93816892;10.80000000;1.00000000"
 )
 dfModels <- read.table(text = paste(sModels, collapse = "\n"), header = TRUE)
 
@@ -74,7 +77,8 @@ TestModelCalibration <- function(model) {
         FUN_MOD = sModel,
         InputsModel = InputsModel,
         IndPeriod_Run = Ind_Run,
-        IndPeriod_WarmUp = Ind_WarmUp
+        IndPeriod_WarmUp = Ind_WarmUp,
+        IsHyst = as.logical(model$IsHyst)
       )
     )
 
@@ -82,7 +86,7 @@ TestModelCalibration <- function(model) {
     InputsCrit <- CreateInputsCrit(FUN_CRIT = ErrorCrit_NSE, InputsModel = InputsModel,
                                    RunOptions = RunOptions, Obs = Obs[Ind_Run])
     # preparation of CalibOptions object
-    CalibOptions <- CreateCalibOptions(sModel)
+    CalibOptions <- CreateCalibOptions(sModel, IsHyst = as.logical(model$IsHyst))
 
     # calibration
     OutputsCalib <- Calibration(InputsModel = InputsModel, RunOptions = RunOptions,
@@ -92,6 +96,7 @@ TestModelCalibration <- function(model) {
                  as.numeric(strsplit(model$ParamFinalR, ";")[[1]]),
                  tolerance = 1E-6)
   })
+  # OutputsCalib$ParamFinalR
 }
 
 apply(dfModels, 1, TestModelCalibration)
-- 
GitLab