aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/test_FOCUS_D_UBA_expertise.R2
-rw-r--r--tests/testthat/test_deSolve.R19
-rw-r--r--tests/testthat/test_mkinpredict_SFO_SFO.R14
3 files changed, 34 insertions, 1 deletions
diff --git a/tests/testthat/test_FOCUS_D_UBA_expertise.R b/tests/testthat/test_FOCUS_D_UBA_expertise.R
index faf473c4..323fb7b3 100644
--- a/tests/testthat/test_FOCUS_D_UBA_expertise.R
+++ b/tests/testthat/test_FOCUS_D_UBA_expertise.R
@@ -40,7 +40,7 @@ test_that("Fits without internal transformations are correct for FOCUS D", {
fit.ff.notrans <- mkinfit(SFO_SFO.ff, FOCUS_2006_D,
transform_fractions = FALSE, transform_rates = FALSE,
quiet = TRUE, solution_type = "deSolve"),
- "sum of formation fractions")
+ "The sum of formation fractions may exceed one")
expect_equivalent(round(fit.ff.notrans$bparms.optim, c(2, 4, 4, 4)),
c(99.60, 0.0987, 0.0053, 0.5145))
diff --git a/tests/testthat/test_deSolve.R b/tests/testthat/test_deSolve.R
new file mode 100644
index 00000000..3d15de35
--- /dev/null
+++ b/tests/testthat/test_deSolve.R
@@ -0,0 +1,19 @@
+context("Solutions with deSolve")
+
+test_that("Solutions with deSolve work if we have no observations at time zero", {
+ skip_on_cran()
+
+ # For testing purposes, we replace 0 values in the time column with 0.1
+ # This confused mkinfit with solution_type "deSolve" up to version 0.1.3.0
+ FOCUS_D_nozero <- FOCUS_D
+ FOCUS_D_nozero[FOCUS_D$time == 0, "time"] <- c(0.1, 0.1)
+
+ f_sfo_sfo_nozero <- mkinfit(SFO_SFO, FOCUS_D_nozero, quiet = TRUE)
+ f_sfo_sfo_nozero_deSolve <- mkinfit(SFO_SFO, FOCUS_D_nozero,
+ solution_type = "deSolve", quiet = TRUE)
+ expect_equal(
+ parms(f_sfo_sfo_nozero),
+ parms(f_sfo_sfo_nozero_deSolve)
+ )
+})
+
diff --git a/tests/testthat/test_mkinpredict_SFO_SFO.R b/tests/testthat/test_mkinpredict_SFO_SFO.R
index d0dc7cdb..bf1043a3 100644
--- a/tests/testthat/test_mkinpredict_SFO_SFO.R
+++ b/tests/testthat/test_mkinpredict_SFO_SFO.R
@@ -11,6 +11,10 @@ test_that("Variants of model predictions for SFO_SFO model give equivalent resul
m1 = mkinsub("SFO"), use_of_ff = "max", quiet = TRUE)
ot = seq(0, 100, by = 1)
+ r.1.a <- subset(as.data.frame(mkinpredict(SFO_SFO.1,
+ c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "analytical")),
+ time %in% c(1, 10, 50, 100))
r.1.e <- subset(as.data.frame(mkinpredict(SFO_SFO.1,
c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
c(parent = 100, m1 = 0), ot, solution_type = "eigen")),
@@ -20,6 +24,10 @@ test_that("Variants of model predictions for SFO_SFO model give equivalent resul
c(parent = 100, m1 = 0), ot, solution_type = "deSolve")),
time %in% c(1, 10, 50, 100))
+ r.2.a <- subset(as.data.frame(mkinpredict(SFO_SFO.2,
+ c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "analytical")),
+ time %in% c(1, 10, 50, 100))
r.2.e <- subset(as.data.frame(mkinpredict(SFO_SFO.2,
c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
c(parent = 100, m1 = 0), ot, solution_type = "eigen")),
@@ -29,6 +37,12 @@ test_that("Variants of model predictions for SFO_SFO model give equivalent resul
c(parent = 100, m1 = 0), ot, solution_type = "deSolve")),
time %in% c(1, 10, 50, 100))
+ # Compare analytical and deSolve for minimum use of formation fractions
+ dev.1.a_d.percent = 100 * (r.1.a[-1] - r.1.d[-1])/r.1.a[-1]
+ dev.1.a_d.percent = as.numeric(unlist((dev.1.a_d.percent)))
+ dev.1.a_d.percent = ifelse(is.na(dev.1.a_d.percent), 0, dev.1.a_d.percent)
+ expect_equivalent(dev.1.a_d.percent < tol, rep(TRUE, length(dev.1.a_d.percent)))
+
# Compare eigen and deSolve for minimum use of formation fractions
dev.1.e_d.percent = 100 * (r.1.e[-1] - r.1.d[-1])/r.1.e[-1]
dev.1.e_d.percent = as.numeric(unlist((dev.1.e_d.percent)))

Contact - Imprint