Nothing
require(ncar)
require(NonCompart)
# Regression tests for the admissibility gate in Res2Txt().
#
# The gate used to be `if (length(y[y > 0]) < 3) return("Too few non-zero points for NCA")`.
# That is a reporting-layer-only rule: sNCA/tblNCA happily summarise a profile with 1 or 2
# measurable concentrations, so the text/pdf/rtf report refused input for which the analysis
# table carried numbers. Conversely the gate let negative concentrations through, which
# sNCA rejects outright, so the report rendered values where the table had all NA.
#
# The gate now mirrors sNCA(): reject empty, length-mismatched or negative concentration
# data, and reject a profile with no measurable concentration at all (which cannot be
# tabulated); render everything else.
Fail = function(msg) stop(paste("Test Failed!", msg))
Tab = function(x, y) tblNCA(data.frame(ID="A", Time=x, conc=y), key="ID", dose=100)
Rendered = function(txt) length(txt) > 1
Value = function(txt, code) {
ln = grep(paste0("^", code, " "), txt, value=TRUE)
if (length(ln) != 1) Fail(paste("could not read", code, "from the report"))
as.numeric(tail(strsplit(trimws(ln), " +")[[1]], 2)[1])
}
## 1. Three or more measurable points: unchanged behaviour.
x = c(0, 1, 2, 4, 8); y = c(0, 0, 5, 3, 2)
txt = txtNCA(x, y, dose=100)
if (!Rendered(txt)) Fail("3 measurable points should render")
## 2. One and two measurable points must render, and must agree with tblNCA.
for (y in list(c(0, 0, 0, 5, 2), c(0, 0, 0, 0, 2))) {
txt = txtNCA(x, y, dose=100)
if (!Rendered(txt)) {
Fail(paste0("profile with ", sum(y > 0), " measurable point(s) was refused: ", txt[1]))
}
tb = Tab(x, y)
if (Value(txt, "CMAX") != tb$CMAX) Fail("report CMAX disagrees with tblNCA")
if (Value(txt, "TMAX") != tb$TMAX) Fail("report TMAX disagrees with tblNCA")
}
## 3. No measurable concentration at all: still refused, with the historical message.
txt = txtNCA(x, c(0, 0, 0, 0, 0), dose=100)
if (Rendered(txt)) Fail("an all-zero profile should not be tabulated")
if (txt != "Too few non-zero points for NCA") Fail(paste("unexpected message:", txt))
## 4. Negative concentrations: refused, matching sNCA/tblNCA returning all NA.
yNeg = c(0, 5, -1, 3, 2)
txt = txtNCA(x, yNeg, dose=100)
if (Rendered(txt)) Fail("a profile with a negative concentration should be refused")
if (!is.na(Tab(x, yNeg)$CMAX)) Fail("tblNCA should return NA for negative concentrations")
cat("Test-Res2Txt.R: OK\n")
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.