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 f3782d8 commit ef376dc
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 ef376dc

Please sign in to comment.