Commit de0e5f5a authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

test(style): indent code and review some minor typo in many test files

parent 12072dba
Pipeline #19716 passed with stages
in 11 minutes and 50 seconds
...@@ -70,12 +70,12 @@ RunRmdChunks <- function(fileRmd, ...@@ -70,12 +70,12 @@ RunRmdChunks <- function(fileRmd,
RunVignetteChunks <- function(vignette, RunVignetteChunks <- function(vignette,
tmpFolder = "../tmp", tmpFolder = "../tmp",
force.eval = TRUE) { force.eval = TRUE) {
if(file.exists(file.path("../../vignettes/", paste0(vignette, ".Rmd")))) { if(file.exists(sprintf("../../vignettes/%s.Rmd", vignette))) {
# testthat context in development environnement # testthat context in development environnement
RunRmdChunks(file.path("../../vignettes/", paste0(vignette, ".Rmd")), tmpFolder, force.eval) RunRmdChunks(sprintf("../../vignettes/%s.Rmd", vignette), tmpFolder, force.eval)
} else { } else {
# R CMD check context in package environnement # R CMD check context in package environnement
RunRmdChunks(system.file(file.path("doc/", paste0(vignette, ".Rmd")), package = "airGR"), tmpFolder, force.eval) RunRmdChunks(system.file(sprintf("doc/%s.Rmd", vignette), package = "airGR"), tmpFolder, force.eval)
} }
return(TRUE) return(TRUE)
} }
......
...@@ -35,7 +35,7 @@ if (dir.exists(file.path(tmp_path, "stable")) & dir.exists(file.path(tmp_path, " ...@@ -35,7 +35,7 @@ if (dir.exists(file.path(tmp_path, "stable")) & dir.exists(file.path(tmp_path, "
message("File ", file.path(getwd(), regIgnoreFile), " not found") message("File ", file.path(getwd(), regIgnoreFile), " not found")
regIgnore <- NULL regIgnore <- NULL
} }
lapply(X = refVarFiles, CompareWithStable, testDir = file.path(tmp_path, "dev"), regIgnore = regIgnore) lapply(refVarFiles, FUN = CompareWithStable, testDir = file.path(tmp_path, "dev"), regIgnore = regIgnore)
} else { } else {
stop("Regression tests compared to released version needs that you run the following instructions first:\n", stop("Regression tests compared to released version needs that you run the following instructions first:\n",
"Rscript tests/testthat/regression_tests.R stable\n", "Rscript tests/testthat/regression_tests.R stable\n",
......
...@@ -3,7 +3,7 @@ Args <- commandArgs(trailingOnly = TRUE) ...@@ -3,7 +3,7 @@ Args <- commandArgs(trailingOnly = TRUE)
source("tests/testthat/helper_regression.R") source("tests/testthat/helper_regression.R")
lActions = list( lActions <- list(
stable = StoreStableExampleResults, stable = StoreStableExampleResults,
dev = StoreDevExampleResults, dev = StoreDevExampleResults,
compare = CompareStableDev compare = CompareStableDev
......
...@@ -11,17 +11,20 @@ test_that("Warm start of GR4J should give same result as warmed model", { ...@@ -11,17 +11,20 @@ test_that("Warm start of GR4J should give same result as warmed model", {
which(format(BasinObs$DatesR, format = "%Y-%m-%d")=="1991-12-31")) which(format(BasinObs$DatesR, format = "%Y-%m-%d")=="1991-12-31"))
# 1990-1991 # 1990-1991
RunOptions <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J, RunOptions <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J,
InputsModel = InputsModel, IndPeriod_Run = c(Ind_Run1, Ind_Run2))) InputsModel = InputsModel,
IndPeriod_Run = c(Ind_Run1, Ind_Run2)))
OutputsModel <- RunModel_GR4J(InputsModel = InputsModel, OutputsModel <- RunModel_GR4J(InputsModel = InputsModel,
RunOptions = RunOptions, Param = Param) RunOptions = RunOptions, Param = Param)
# 1990 # 1990
RunOptions1 <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J, RunOptions1 <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J,
InputsModel = InputsModel, IndPeriod_Run = Ind_Run1)) InputsModel = InputsModel,
IndPeriod_Run = Ind_Run1))
OutputsModel1 <- RunModel_GR4J(InputsModel = InputsModel, OutputsModel1 <- RunModel_GR4J(InputsModel = InputsModel,
RunOptions = RunOptions1, Param = Param) RunOptions = RunOptions1, Param = Param)
# Warm start 1991 # Warm start 1991
RunOptions2 <- CreateRunOptions(FUN_MOD = RunModel_GR4J, RunOptions2 <- CreateRunOptions(FUN_MOD = RunModel_GR4J,
InputsModel = InputsModel, IndPeriod_Run = Ind_Run2, InputsModel = InputsModel,
IndPeriod_Run = Ind_Run2,
IndPeriod_WarmUp = 0L, IndPeriod_WarmUp = 0L,
IniStates = OutputsModel1$StateEnd) IniStates = OutputsModel1$StateEnd)
OutputsModel2 <- RunModel_GR4J(InputsModel = InputsModel, OutputsModel2 <- RunModel_GR4J(InputsModel = InputsModel,
......
...@@ -140,10 +140,8 @@ test_that("Params from calibration with simulated data should be similar to init ...@@ -140,10 +140,8 @@ test_that("Params from calibration with simulated data should be similar to init
InputsModel = InputsModel, InputsModel = InputsModel,
RunOptions = RunOptions, RunOptions = RunOptions,
VarObs = "Q", VarObs = "Q",
Obs = ( Obs = (c(0, Qupstream[Ind_Run[1:(length(Ind_Run) - 1)]]) * BasinAreas[1L] +
c(0, Qupstream[Ind_Run[1:(length(Ind_Run) - 1)]]) * BasinAreas[1L] + BasinObs$Qmm[Ind_Run] * BasinAreas[2L]) / sum(BasinAreas)
BasinObs$Qmm[Ind_Run] * BasinAreas[2L]
) / sum(BasinAreas)
) )
CalibOptions <- CreateCalibOptions( CalibOptions <- CreateCalibOptions(
FUN_MOD = RunModel_GR4J, FUN_MOD = RunModel_GR4J,
...@@ -193,14 +191,19 @@ Ind_Run2 <- seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d")=="1991-01-01" ...@@ -193,14 +191,19 @@ Ind_Run2 <- seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d")=="1991-01-01"
# 1990 # 1990
RunOptions1 <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J, RunOptions1 <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J,
InputsModel = IM, IndPeriod_Run = Ind_Run1)) InputsModel = IM,
IndPeriod_Run = Ind_Run1))
OutputsModel1 <- RunModel(InputsModel = IM, OutputsModel1 <- RunModel(InputsModel = IM,
RunOptions = RunOptions1, Param = PSDini, FUN_MOD = RunModel_GR4J) RunOptions = RunOptions1, Param = PSDini,
FUN_MOD = RunModel_GR4J)
# 1990-1991 # 1990-1991
RunOptions <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J, RunOptions <- suppressWarnings(CreateRunOptions(FUN_MOD = RunModel_GR4J,
InputsModel = IM, IndPeriod_Run = c(Ind_Run1, Ind_Run2))) InputsModel = IM,
IndPeriod_Run = c(Ind_Run1, Ind_Run2)))
OutputsModel <- RunModel(InputsModel = IM, OutputsModel <- RunModel(InputsModel = IM,
RunOptions = RunOptions, Param = PSDini, FUN_MOD = RunModel_GR4J) RunOptions = RunOptions,
Param = PSDini,
FUN_MOD = RunModel_GR4J)
test_that("Warm start should give same result as warmed model", { test_that("Warm start should give same result as warmed model", {
# Warm start 1991 # Warm start 1991
...@@ -209,7 +212,9 @@ test_that("Warm start should give same result as warmed model", { ...@@ -209,7 +212,9 @@ test_that("Warm start should give same result as warmed model", {
IndPeriod_WarmUp = 0L, IndPeriod_WarmUp = 0L,
IniStates = OutputsModel1$StateEnd) IniStates = OutputsModel1$StateEnd)
OutputsModel2 <- RunModel(InputsModel = IM, OutputsModel2 <- RunModel(InputsModel = IM,
RunOptions = RunOptions2, Param = PSDini, FUN_MOD = RunModel_GR4J) RunOptions = RunOptions2,
Param = PSDini,
FUN_MOD = RunModel_GR4J)
# Compare 1991 Qsim from warm started and from 1990-1991 # Compare 1991 Qsim from warm started and from 1990-1991
names(OutputsModel2$Qsim) <- NULL names(OutputsModel2$Qsim) <- NULL
expect_equal(OutputsModel2$Qsim, OutputsModel$Qsim[366:730]) expect_equal(OutputsModel2$Qsim, OutputsModel$Qsim[366:730])
......
...@@ -58,5 +58,4 @@ test_that("PE_Oudin works", { ...@@ -58,5 +58,4 @@ test_that("PE_Oudin works", {
RunFortran = TRUE) RunFortran = TRUE)
expect_equal(PotEvapFor, c(PotEvapFor1, PotEvapFor2)) expect_equal(PotEvapFor, c(PotEvapFor1, PotEvapFor2))
}) })
...@@ -14,8 +14,8 @@ test_that("V02.1_param_optim works", { ...@@ -14,8 +14,8 @@ test_that("V02.1_param_optim works", {
rda_resGLOB <- resGLOB rda_resGLOB <- resGLOB
rda_resPORT <- resPORT rda_resPORT <- resPORT
expect_true(RunVignetteChunks("V02.1_param_optim")) expect_true(RunVignetteChunks("V02.1_param_optim"))
expect_equal(summary(resGLOB), summary(rda_resGLOB), tolerance = 1E-7) expect_equal(summary(resGLOB), summary(rda_resGLOB), tolerance = 1e-7)
expect_equal(resGLOB[,-1], rda_resGLOB[,-1], tolerance = 1E-2) # High tolerance due to randomisation in optimisations expect_equal(resGLOB[, -1], rda_resGLOB[, -1], tolerance = 1e-2) # High tolerance due to randomisation in optimisations
}) })
test_that("V02.2_param_mcmc works", { test_that("V02.2_param_mcmc works", {
...@@ -25,8 +25,8 @@ test_that("V02.2_param_mcmc works", { ...@@ -25,8 +25,8 @@ test_that("V02.2_param_mcmc works", {
rda_gelRub <- gelRub rda_gelRub <- gelRub
rda_multDRAM <- multDRAM rda_multDRAM <- multDRAM
expect_true(RunVignetteChunks("V02.2_param_mcmc")) expect_true(RunVignetteChunks("V02.2_param_mcmc"))
expect_equal(gelRub, rda_gelRub, tolerance = 1E-7) expect_equal(gelRub, rda_gelRub, tolerance = 1e-7)
expect_equal(multDRAM, rda_multDRAM, tolerance = 1E-7) expect_equal(multDRAM, rda_multDRAM, tolerance = 1e-7)
}) })
test_that("V03_param_sets_GR4J works", { test_that("V03_param_sets_GR4J works", {
...@@ -45,8 +45,8 @@ test_that("V04_cemaneige_hysteresis works", { ...@@ -45,8 +45,8 @@ test_that("V04_cemaneige_hysteresis works", {
rda_OutputsCrit_Val_NoHyst <- OutputsCrit_Val_NoHyst rda_OutputsCrit_Val_NoHyst <- OutputsCrit_Val_NoHyst
expect_true(RunVignetteChunks("V04_cemaneige_hysteresis")) expect_true(RunVignetteChunks("V04_cemaneige_hysteresis"))
TestQmmQlsConversion(BasinObs, BasinInfo$BasinArea) TestQmmQlsConversion(BasinObs, BasinInfo$BasinArea)
expect_equal(OutputsCrit_Cal, rda_OutputsCrit_Cal, tolerance = 1E-7) expect_equal(OutputsCrit_Cal, rda_OutputsCrit_Cal, tolerance = 1e-7)
expect_equal(OutputsCrit_Cal_NoHyst, rda_OutputsCrit_Cal_NoHyst, tolerance = 1E-7) expect_equal(OutputsCrit_Cal_NoHyst, rda_OutputsCrit_Cal_NoHyst, tolerance = 1e-7)
expect_equal(OutputsCrit_Val, rda_OutputsCrit_Val, tolerance = 1E-7) expect_equal(OutputsCrit_Val, rda_OutputsCrit_Val, tolerance = 1e-7)
expect_equal(OutputsCrit_Val_NoHyst, rda_OutputsCrit_Val_NoHyst, tolerance = 1E-7) expect_equal(OutputsCrit_Val_NoHyst, rda_OutputsCrit_Val_NoHyst, tolerance = 1e-7)
}) })
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment