Skip to content

Commit

Permalink
Test/document/rename assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Aug 10, 2024
1 parent f2b1b65 commit a25617d
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 30 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export(assertRxUiPrediction)
export(assertRxUiRandomOnIdOnly)
export(assertRxUiSingleEndpoint)
export(assertRxUiTransformNormal)
export(assertRxUnbounded)
export(assertVariableExists)
export(assertVariableName)
export(assertVariableNew)
Expand Down Expand Up @@ -571,10 +572,12 @@ export(swapMatListWithCube)
export(testCompartmentExists)
export(testExists)
export(testRxLinCmt)
export(testRxUnbounded)
export(testVariableExists)
export(toTrialDuration)
export(uppergamma)
export(waiver)
export(warnRxBounded)
export(write.template.server)
export(write.template.ui)
export(xlab)
Expand Down
35 changes: 15 additions & 20 deletions R/assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ testExists <- function(ui, x) {
return(is.finite(.t$upper) || is.finite(.t$lower))
}
.err <- .errDistArgRanges[[.t$err]]
return (!identical(.t$upper, .err[1]) ||
!identical(.t$lower, .err[2]))
return (!identical(.t$lower, .err[1]) ||
!identical(.t$upper, .err[2]))
}, logical(1), USE.NAMES=FALSE), .theta$name)
}
#' Test if the rxode2 model has any parameters with user defined boundaries
Expand All @@ -569,13 +569,9 @@ testExists <- function(ui, x) {
#'
#' one.cmt <- function() {
#' ini({
#' ## You may label each parameter with a comment
#' tka <- 0.45 # Log Ka
#' tcl <- log(c(0, 2.7, 100)) # Log Cl
#' ## This works with interactive models
#' ## You may also label the preceding line with label("label text")
#' tv <- 3.45; label("log V")
#' ## the label("Label name") works with all models
#' tka <- 0.45; label("Ka")
#' tcl <- log(c(0, 2.7, 100)); label("Cl")
#' tv <- 3.45; label("V")
#' eta.ka ~ 0.6
#' eta.cl ~ 0.3
#' eta.v ~ 0.1
Expand All @@ -587,28 +583,27 @@ testExists <- function(ui, x) {
#' v <- exp(tv + eta.v)
#' linCmt() ~ add(add.sd)
#' })
# }
#'
#' testRxBounded(one.cmt)
#' }
#'
#' try(assertRxBounded(one.cmt))
#' testRxUnbounded(one.cmt)
#'
#' warnAssertRxBounded(one.cmt)
#' try(assertRxUnbounded(one.cmt))
#'
testRxBounded <- function(ui) {
any(.getRxBounded(ui))
#' warnRxBounded(one.cmt)
testRxUnbounded <- function(ui) {
!any(.getRxBounded(ui))
}

#' @describeIn testRxBounded Assert that the rxode2 model has any parameters with user defined boundaries
#' @describeIn testRxUnbounded Assert that the rxode2 model has any parameters with user defined boundaries
#' @export
assertRxBounded <- function(ui, extra="", .var.name=.vname(ui)) {
if (testRxBounded(ui,extra=extra, .var.name=.var.name)) {
assertRxUnbounded <- function(ui, extra="", .var.name=.vname(ui)) {
if (testRxUnbounded(ui)) {
return(invisible(ui))
}
stop("'", .var.name, "' can not have user defined boundaries", extra, call.=FALSE)
}

#' @describeIn testRxBounded Warn that the rxode2 model has any parameters with user defined boundaries
#' @describeIn testRxUnbounded Warn that the rxode2 model has any parameters with user defined boundaries
#' @export
warnRxBounded <- function(ui, extra="", .var.name=.vname(ui)) {
.bound <- .getRxBounded(ui, extra=extra, .var.name=.var.name)
Expand Down
3 changes: 2 additions & 1 deletion man/assertCompartmentExists.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/assertCompartmentName.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/assertCompartmentNew.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/assertRxUi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/assertVariableExists.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/assertVariableNew.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/rxode2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion tests/testthat/test-assert.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
if (!.Call(`_rxode2_isIntel`)) {
test_that("assert or testRxLinCmt", {

test_that("no warnings/errors without boundaries", {

one.cmt <- function() {
ini({
tka <- 0.45; label("Ka")
tcl <- log(2.7); label("Cl")
tv <- 3.45; label("V")
eta.ka ~ 0.6
eta.cl ~ 0.3
eta.v ~ 0.1
add.sd <- 0.7
})
model({
ka <- exp(tka + eta.ka)
cl <- exp(tcl + eta.cl)
v <- exp(tv + eta.v)
linCmt() ~ add(add.sd)
})
}

expect_true(testRxUnbounded(one.cmt))
expect_error(assertRxUnbounded(one.cmt), NA)
expect_warning(warnRxBounded(one.cmt), NA)
})
test_that("assert or testRxLinCmt and boundaries", {

one.cmt <- function() {
ini({
tka <- 0.45; label("Ka")
Expand All @@ -18,6 +44,10 @@ if (!.Call(`_rxode2_isIntel`)) {
})
}

expect_false(testRxUnbounded(one.cmt))
expect_error(assertRxUnbounded(one.cmt))
expect_warning(warnRxBounded(one.cmt))

expect_error(assertRxLinCmt(one.cmt), NA)
expect_true(testRxLinCmt(one.cmt))

Expand Down

0 comments on commit a25617d

Please sign in to comment.