Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
HYCAR-Hydro
airGR
Commits
de0e5f5a
Commit
de0e5f5a
authored
Jan 28, 2021
by
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
Changes
8
Pipelines
1
Show whitespace changes
Inline
Side-by-side
tests/testthat/helper_vignettes.R
View file @
de0e5f5a
...
...
@@ -70,12 +70,12 @@ RunRmdChunks <- function(fileRmd,
RunVignetteChunks
<-
function
(
vignette
,
tmpFolder
=
"../tmp"
,
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
RunRmdChunks
(
file.path
(
"../../vignettes/
"
,
paste0
(
vignette
,
".Rmd"
)
),
tmpFolder
,
force.eval
)
RunRmdChunks
(
sprintf
(
"../../vignettes/
%s.Rmd"
,
vignette
),
tmpFolder
,
force.eval
)
}
else
{
# 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
)
}
...
...
tests/testthat/regression.R
View file @
de0e5f5a
...
...
@@ -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"
)
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
{
stop
(
"Regression tests compared to released version needs that you run the following instructions first:\n"
,
"Rscript tests/testthat/regression_tests.R stable\n"
,
...
...
tests/testthat/regression_tests.R
View file @
de0e5f5a
...
...
@@ -3,7 +3,7 @@ Args <- commandArgs(trailingOnly = TRUE)
source
(
"tests/testthat/helper_regression.R"
)
lActions
=
list
(
lActions
<-
list
(
stable
=
StoreStableExampleResults
,
dev
=
StoreDevExampleResults
,
compare
=
CompareStableDev
...
...
tests/testthat/test-CreateRunOptions.R
View file @
de0e5f5a
...
...
@@ -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"
))
# 1990-1991
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
,
RunOptions
=
RunOptions
,
Param
=
Param
)
# 1990
RunOptions1
<-
suppressWarnings
(
CreateRunOptions
(
FUN_MOD
=
RunModel_GR4J
,
InputsModel
=
InputsModel
,
IndPeriod_Run
=
Ind_Run1
))
InputsModel
=
InputsModel
,
IndPeriod_Run
=
Ind_Run1
))
OutputsModel1
<-
RunModel_GR4J
(
InputsModel
=
InputsModel
,
RunOptions
=
RunOptions1
,
Param
=
Param
)
# Warm start 1991
RunOptions2
<-
CreateRunOptions
(
FUN_MOD
=
RunModel_GR4J
,
InputsModel
=
InputsModel
,
IndPeriod_Run
=
Ind_Run2
,
InputsModel
=
InputsModel
,
IndPeriod_Run
=
Ind_Run2
,
IndPeriod_WarmUp
=
0L
,
IniStates
=
OutputsModel1
$
StateEnd
)
OutputsModel2
<-
RunModel_GR4J
(
InputsModel
=
InputsModel
,
...
...
tests/testthat/test-RunModel_LAG.R
View file @
de0e5f5a
...
...
@@ -140,10 +140,8 @@ test_that("Params from calibration with simulated data should be similar to init
InputsModel
=
InputsModel
,
RunOptions
=
RunOptions
,
VarObs
=
"Q"
,
Obs
=
(
c
(
0
,
Qupstream
[
Ind_Run
[
1
:
(
length
(
Ind_Run
)
-
1
)]])
*
BasinAreas
[
1L
]
+
BasinObs
$
Qmm
[
Ind_Run
]
*
BasinAreas
[
2L
]
)
/
sum
(
BasinAreas
)
Obs
=
(
c
(
0
,
Qupstream
[
Ind_Run
[
1
:
(
length
(
Ind_Run
)
-
1
)]])
*
BasinAreas
[
1L
]
+
BasinObs
$
Qmm
[
Ind_Run
]
*
BasinAreas
[
2L
])
/
sum
(
BasinAreas
)
)
CalibOptions
<-
CreateCalibOptions
(
FUN_MOD
=
RunModel_GR4J
,
...
...
@@ -193,14 +191,19 @@ Ind_Run2 <- seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d")=="1991-01-01"
# 1990
RunOptions1
<-
suppressWarnings
(
CreateRunOptions
(
FUN_MOD
=
RunModel_GR4J
,
InputsModel
=
IM
,
IndPeriod_Run
=
Ind_Run1
))
InputsModel
=
IM
,
IndPeriod_Run
=
Ind_Run1
))
OutputsModel1
<-
RunModel
(
InputsModel
=
IM
,
RunOptions
=
RunOptions1
,
Param
=
PSDini
,
FUN_MOD
=
RunModel_GR4J
)
RunOptions
=
RunOptions1
,
Param
=
PSDini
,
FUN_MOD
=
RunModel_GR4J
)
# 1990-1991
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
,
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"
,
{
# Warm start 1991
...
...
@@ -209,7 +212,9 @@ test_that("Warm start should give same result as warmed model", {
IndPeriod_WarmUp
=
0L
,
IniStates
=
OutputsModel1
$
StateEnd
)
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
names
(
OutputsModel2
$
Qsim
)
<-
NULL
expect_equal
(
OutputsModel2
$
Qsim
,
OutputsModel
$
Qsim
[
366
:
730
])
...
...
tests/testthat/test-SeriesAggreg.R
View file @
de0e5f5a
tests/testthat/test-evap.R
View file @
de0e5f5a
...
...
@@ -58,5 +58,4 @@ test_that("PE_Oudin works", {
RunFortran
=
TRUE
)
expect_equal
(
PotEvapFor
,
c
(
PotEvapFor1
,
PotEvapFor2
))
})
tests/testthat/test-vignettes.R
View file @
de0e5f5a
...
...
@@ -14,8 +14,8 @@ test_that("V02.1_param_optim works", {
rda_resGLOB
<-
resGLOB
rda_resPORT
<-
resPORT
expect_true
(
RunVignetteChunks
(
"V02.1_param_optim"
))
expect_equal
(
summary
(
resGLOB
),
summary
(
rda_resGLOB
),
tolerance
=
1
E
-7
)
expect_equal
(
resGLOB
[,
-1
],
rda_resGLOB
[,
-1
],
tolerance
=
1
E
-2
)
# High tolerance due to randomisation in optimisations
expect_equal
(
summary
(
resGLOB
),
summary
(
rda_resGLOB
),
tolerance
=
1
e
-7
)
expect_equal
(
resGLOB
[,
-1
],
rda_resGLOB
[,
-1
],
tolerance
=
1
e
-2
)
# High tolerance due to randomisation in optimisations
})
test_that
(
"V02.2_param_mcmc works"
,
{
...
...
@@ -25,8 +25,8 @@ test_that("V02.2_param_mcmc works", {
rda_gelRub
<-
gelRub
rda_multDRAM
<-
multDRAM
expect_true
(
RunVignetteChunks
(
"V02.2_param_mcmc"
))
expect_equal
(
gelRub
,
rda_gelRub
,
tolerance
=
1
E
-7
)
expect_equal
(
multDRAM
,
rda_multDRAM
,
tolerance
=
1
E
-7
)
expect_equal
(
gelRub
,
rda_gelRub
,
tolerance
=
1
e
-7
)
expect_equal
(
multDRAM
,
rda_multDRAM
,
tolerance
=
1
e
-7
)
})
test_that
(
"V03_param_sets_GR4J works"
,
{
...
...
@@ -45,8 +45,8 @@ test_that("V04_cemaneige_hysteresis works", {
rda_OutputsCrit_Val_NoHyst
<-
OutputsCrit_Val_NoHyst
expect_true
(
RunVignetteChunks
(
"V04_cemaneige_hysteresis"
))
TestQmmQlsConversion
(
BasinObs
,
BasinInfo
$
BasinArea
)
expect_equal
(
OutputsCrit_Cal
,
rda_OutputsCrit_Cal
,
tolerance
=
1
E
-7
)
expect_equal
(
OutputsCrit_Cal_NoHyst
,
rda_OutputsCrit_Cal_NoHyst
,
tolerance
=
1
E
-7
)
expect_equal
(
OutputsCrit_Val
,
rda_OutputsCrit_Val
,
tolerance
=
1
E
-7
)
expect_equal
(
OutputsCrit_Val_NoHyst
,
rda_OutputsCrit_Val_NoHyst
,
tolerance
=
1
E
-7
)
expect_equal
(
OutputsCrit_Cal
,
rda_OutputsCrit_Cal
,
tolerance
=
1
e
-7
)
expect_equal
(
OutputsCrit_Cal_NoHyst
,
rda_OutputsCrit_Cal_NoHyst
,
tolerance
=
1
e
-7
)
expect_equal
(
OutputsCrit_Val
,
rda_OutputsCrit_Val
,
tolerance
=
1
e
-7
)
expect_equal
(
OutputsCrit_Val_NoHyst
,
rda_OutputsCrit_Val_NoHyst
,
tolerance
=
1
e
-7
)
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment