From d35ad101085b93b59171ca02d6550dd7dc1012a0 Mon Sep 17 00:00:00 2001 From: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com> Date: Mon, 15 Apr 2024 08:00:51 +0100 Subject: [PATCH] * R/parameters.R: Check unordered ordinal. --- R/parameters.R | 7 +++++++ tests/testthat/test-readParameters.R | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/R/parameters.R b/R/parameters.R index f454204f..34e11cf5 100644 --- a/R/parameters.R +++ b/R/parameters.R @@ -211,7 +211,14 @@ Parameter <- function(name, type, domain, label, condition, transf, dups <- duplicated(domain) stop("duplicated values (", paste0('\"', domain[dups], "\"", collapse = ', '), ") for parameter '", name, "'") } + if (type == "o") { + tmp <- suppressWarnings(as.numeric(domain)) + if (!anyNA(tmp) && !identical(order(tmp), seq_along(tmp))) + stop("the domain of parameter '", name, "' appears to be a discretization of a numerical range, but the values are not in increasing order: ", + paste0(domain, collapse = ', ')) + } } + if (transf != "") transf <- transform_domain(transf, domain, type) diff --git a/tests/testthat/test-readParameters.R b/tests/testthat/test-readParameters.R index 1ed7560a..a44b786b 100644 --- a/tests/testthat/test-readParameters.R +++ b/tests/testthat/test-readParameters.R @@ -88,6 +88,12 @@ expect_error(readParameters(text = ' # '), "No parameter definition found") +test_that("ordinal out of order", { +expect_error(readParameters(text = ' +param "" o (0, 2, 1) +'), "the values are not in increasing order") +}) + expect_error(readParameters(text = 'param1 "--param1 " r,log (0, 100)'), "of parameter of type 'log' contains non-positive values")