Commit 32a34205 authored by Dorchies David's avatar Dorchies David

test: Add first expectation and fix issues in implementation of vignette tests (still failed)

- Fix issue with chunk 3 of V02.2_param_mcmc
- skip temporarily V02.1_param_optim due to bug in package hydroPSO
- add skip_on_cran() to vignette tests
- reset local variables before each vignette execution
Refs #52
parent 74be387b
......@@ -5,7 +5,7 @@
#' @param force.eval Force execution of chunks with parameter eval=FALSE
RunRmdChunks <- function(fileRmd,
tmpFolder = "../tmp",
force.eval = FALSE) {
force.eval = TRUE) {
dir.create(tmpFolder, showWarnings = FALSE)
output = file.path(tmpFolder,
gsub("\\.Rmd", "\\.R", basename(fileRmd), ignore.case = TRUE))
......@@ -34,7 +34,7 @@ RunRmdChunks <- function(fileRmd,
x = sTxt[chunksEvalStart[i]:chunksEvalEnd[i]])
}
}
}
# Remove line of code displaying data
removeFromGrep <- function(pattern, x) {
......@@ -52,7 +52,7 @@ RunRmdChunks <- function(fileRmd,
exLines = grep("^example\\(.*\\)", sTxt)
sTxt[exLines] = paste0(substr(sTxt[exLines], 1, nchar(sTxt[exLines]) - 1), ", local = TRUE, echo = FALSE, verbose = FALSE, ask = FALSE)")
# Remove question "Hit <Return> to see next plot"
sTxt = c("par(ask=F)", sTxt)
sTxt = c("par(ask=F)", sTxt)
# Write the transformed script
writeLines(sTxt, output)
# Silently run the chunks
......
context("Test vignette chunks")
test_that("V01_get_started works", {
skip_on_cran()
rm(list=ls())
RunRmdChunks("../../vignettes/V01_get_started.Rmd")
# Test Qmm -> Qls conversion in input
notNA = which(!is.na(BasinObs$Qmm))
expect(
all(abs(BasinObs$Qmm[notNA] * BasinInfo$BasinArea / 86400 * 1E6 - BasinObs$Qls[notNA]) < 1E-7),
"Error in conversion Qmm -> Qls"
)
})
test_that("V02.1_param_optim works", {
RunRmdChunks("../../vignettes/V02.1_param_optim.Rmd", force.eval = TRUE)
skip_on_cran()
skip("hydroPSO not working presently")
rm(list=ls())
RunRmdChunks("../../vignettes/V02.1_param_optim.Rmd")
})
test_that("V02.2_param_mcmc works", {
RunRmdChunks("../../vignettes/V02.2_param_mcmc.Rmd", force.eval = TRUE)
skip_on_cran()
rm(list=ls())
RunRmdChunks("../../vignettes/V02.2_param_mcmc.Rmd")
})
test_that("V03_param_sets_GR4J works", {
RunRmdChunks("../../vignettes/V03_param_sets_GR4J.Rmd", force.eval = TRUE)
skip_on_cran()
rm(list=ls())
RunRmdChunks("../../vignettes/V03_param_sets_GR4J.Rmd")
})
test_that("V04_cemaneige_hysteresis works", {
RunRmdChunks("../../vignettes/V04_cemaneige_hysteresis.Rmd", force.eval = TRUE)
skip_on_cran()
rm(list=ls())
RunRmdChunks("../../vignettes/V04_cemaneige_hysteresis.Rmd")
})
......@@ -48,8 +48,8 @@ Please note that this vignette is only for illustration purposes and does not pr
We show how to use the DRAM algorithm for SLS Bayesian inference, with the `modMCMC()` function of the [FME](https://cran.r-project.org/package=FME) package.
First, we need to define a function that returns twice the opposite of the log-likelihood for a given parameter set.
Nota: in the `LogLikeGR4J()` function, the computation of the log-likelihood is simplified in order to ensure a good computing performance. It corresponds to a translation of the two following lines.
```{r, echo=TRUE, eval=FALSE}
Nota: in the `LogLikeGR4J()` function, the computation of the log-likelihood is simplified in order to ensure a good computing performance. It corresponds to a translation of the two following lines.
```{r, echo=TRUE, eval=FALSE, purl=FALSE}
Likelihood <- sum((ObsY - ModY)^2, na.rm = TRUE)^(-sum(!is.na(ObsY)) / 2)
LogLike <- -2 * log(Likelihood)
```
......@@ -79,7 +79,7 @@ LogLikeGR4J <- function(ParamOptim) {
## Estimation of the best-fit parameters as a starting point
We start by using the PORT optimization routine to estimate the best-fit parameters.
```{r, results='hide', eval=FALSE}
optPORT <- stats::nlminb(start = c(4.1, 3.9, -0.9, -8.7),
optPORT <- stats::nlminb(start = c(4.1, 3.9, -0.9, -8.7),
objective = LogLikeGR4J,
lower = rep(-9.9, times = 4), upper = rep(9.9, times = 4),
control = list(trace = 1))
......
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