Commit 2da26982 authored by Dorchies David's avatar Dorchies David
Browse files

fix(CreateInputsCrit): fix wrong check on sub-catchment sorting for parameter regularisation

Refs #54
parent 0a161986
......@@ -47,7 +47,7 @@ CreateInputsCrit.GRiwrmInputsModel <- function(InputsModel,
}
if (! isNodeDownstream(InputsModel, AprioriIds[id], id)) {
stop("'AprioriIds': the node \"", AprioriIds[id],
"\" is not upstream the node \"", AprioriIds[id],"\"")
"\" is not upstream the node \"", id,"\"")
}
})
}
......
......@@ -178,7 +178,7 @@ serializeIniStates <- function(IniStates) {
#'
isNodeDownstream <- function(InputsModel, current_node, down_node) {
current_down_node <- InputsModel[[current_node]]$down
if (current_down_node == down_node) return(TRUE)
if (is.na(current_down_node)) return(FALSE)
if (current_down_node == down_node) return(TRUE)
return(isNodeDownstream(InputsModel, current_down_node, down_node))
}
......@@ -6,7 +6,7 @@ for(x in ls(e)) assign(x, get(x, e))
context("CreateInputsCrit.GRiwrmInputsModel")
test_that("Wrong argument class throw error", {
test_that("Wrong argument class should throw error", {
expect_error(CreateInputsCrit(InputsModel = InputsModel[[1]],
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,]))
......@@ -25,7 +25,7 @@ test_that("Wrong argument class throw error", {
regexp = "matrix or data.frame")
})
test_that("De Lavenne criteria is OK", {
test_that("De Lavenne criterion is OK", {
IC <- CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
......@@ -36,3 +36,13 @@ test_that("De Lavenne criteria is OK", {
expect_s3_class(IC57, "InputsCrit")
expect_s3_class(IC57, "Compo")
})
test_that("De Lavenne criterion: wrong sub-catchment order should throw error", {
expect_error(
CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
AprioriIds = c("54057" = "54032", "54032" = "54001", "54001" = "54029")),
regexp = "is not upstream the node"
)
})
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