aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat/test_parent_only.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-05-14 00:21:12 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2015-05-14 00:21:47 +0200
commit01c69fcff8c5a82b4c80faaeb44ff00827e792ca (patch)
tree5aa6d4c2a339980b726d7f02d906b73c602a885b /tests/testthat/test_parent_only.R
parent42739646dc36ff74d43b638fc2c4f5259496e2b9 (diff)
Start of migration from RUnit to testthat
Diffstat (limited to 'tests/testthat/test_parent_only.R')
-rw-r--r--tests/testthat/test_parent_only.R48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/testthat/test_parent_only.R b/tests/testthat/test_parent_only.R
new file mode 100644
index 00000000..16fc5131
--- /dev/null
+++ b/tests/testthat/test_parent_only.R
@@ -0,0 +1,48 @@
+context("Fitting of parent only models")
+
+calc_dev.percent <- function(fitlist, reference) {
+ for (i in 1:length(fitlist)) {
+ fit <- fitlist[[i]]
+ results <- c(fit$bparms.optim,
+ endpoints(fit)$distimes$DT50,
+ endpoints(fit)$distimes$DT90)
+ dev.percent[[i]] <- abs(100 * ((reference - results)/reference))
+ }
+ return(dev.percent)
+}
+
+SFO <- mkinmod(parent = list(type = "SFO"))
+FOMC <- mkinmod(parent = list(type = "FOMC"))
+
+test_that("SFO fit for FOCUS A deviates less than 0.1% from median of values from FOCUS report", {
+ fits.A.SFO <- list()
+ fits.A.SFO[[1]] <- mkinfit("SFO", FOCUS_2006_A, quiet=TRUE)
+ fits.A.SFO[[2]] <- mkinfit(SFO, FOCUS_2006_A, quiet=TRUE)
+ fits.A.SFO[[3]] <- mkinfit(SFO, FOCUS_2006_A, quiet=TRUE, solution_type = "eigen")
+ fits.A.SFO[[4]] <- mkinfit(SFO, FOCUS_2006_A, quiet=TRUE, solution_type = "deSolve")
+
+ median.A.SFO <- as.numeric(lapply(subset(FOCUS_2006_SFO_ref_A_to_F,
+ dataset == "A",
+ c(M0, k, DT50, DT90)), "median"))
+
+ dev.percent <- calc_dev.percent(fits.A.SFO, median.A.SFO)
+ expect_equivalent(dev.percent[[1]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[2]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[3]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[4]] < 0.1, rep(TRUE, 4))
+})
+
+test_that("SFO fit for FOCUS C deviates less than 0.1% from median of values from FOCUS report", {
+ fits.C.SFO <- list()
+ fits.C.SFO[[1]] <- mkinfit("SFO", FOCUS_2006_C, quiet=TRUE)
+ fits.C.SFO[[2]] <- mkinfit(SFO, FOCUS_2006_C, quiet=TRUE)
+ fits.C.SFO[[3]] <- mkinfit(SFO, FOCUS_2006_C, quiet=TRUE, solution_type = "deSolve")
+
+ median.C.SFO <- as.numeric(lapply(subset(FOCUS_2006_SFO_ref_A_to_F,
+ dataset == "C",
+ c(M0, k, DT50, DT90)), "median"))
+ dev.percent <- calc_dev.percent(fits.C.SFO, median.C.SFO)
+ expect_equivalent(dev.percent[[1]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[2]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[3]] < 0.1, rep(TRUE, 4))
+})

Contact - Imprint