From d4af17d59000e6cc80b0cdd89faa4a4736306c6c Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.fr>
Date: Mon, 11 Oct 2021 16:14:55 +0200
Subject: [PATCH] test(Extract): add test using function to extract InputsModel
 and OutputsModel Objects Refs #137

---
 tests/testthat/test-Extract.R | 37 +++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 tests/testthat/test-Extract.R

diff --git a/tests/testthat/test-Extract.R b/tests/testthat/test-Extract.R
new file mode 100644
index 00000000..f2231095
--- /dev/null
+++ b/tests/testthat/test-Extract.R
@@ -0,0 +1,37 @@
+context("Extract")
+
+## loading catchment data
+data(L0123002)
+
+## preparation of the InputsModel object
+InputsModel <- CreateInputsModel(FUN_MOD = RunModel_CemaNeigeGR4J, DatesR = BasinObs$DatesR,
+                                 Precip = BasinObs$P, PotEvap = BasinObs$E, TempMean = BasinObs$T,
+                                 ZInputs = median(BasinInfo$HypsoData),
+                                 HypsoData = BasinInfo$HypsoData, NLayers = 5)
+
+## run period selection
+Ind_Run <- seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d")=="1990-01-01"),
+               which(format(BasinObs$DatesR, format = "%Y-%m-%d")=="1999-12-31"))
+
+
+## preparation of the RunOptions object
+RunOptions <- CreateRunOptions(FUN_MOD = RunModel_CemaNeigeGR4J, InputsModel = InputsModel,
+                               IndPeriod_Run = Ind_Run)
+
+## simulation
+Param <- c(X1 = 408.774, X2 = 2.646, X3 = 131.264, X4 = 1.174,
+           CNX1 = 0.962, CNX2 = 2.249)
+OutputsModel <- RunModel_CemaNeigeGR4J(InputsModel = InputsModel,
+                                       RunOptions = RunOptions, Param = Param)
+
+## -----
+
+test_that("Names of InputsModel", {
+  expect_equal(names(InputsModel), names(InputsModel[1:5]))
+})
+
+
+test_that("Names of OutputsModel", {
+  expect_equal(names(OutputsModel), names(airGR:::.ExtractOutputsModel(OutputsModel, 1:5)))
+})
+
-- 
GitLab