Skip to content

Commit

Permalink
* R/parameters.R: Check unordered ordinal.
Browse files Browse the repository at this point in the history
  • Loading branch information
MLopez-Ibanez committed May 28, 2024
1 parent 07eebf6 commit d35ad10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions R/parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-readParameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit d35ad10

Please sign in to comment.