From 48d9cad339394c3aa0d730d9a27b1c0680ce13e8 Mon Sep 17 00:00:00 2001 From: Ranke Johannes Date: Mon, 7 Sep 2026 13:45:39 +0200 Subject: Add DTx function, check and test The tolerance of one test had to be increased in test_deSolve.R, and four vdiffr snapshots with negligible differences were updated. Tests run with a maximum of 16 cores when running in the Agroscope Apptainer environment. --- tests/testthat/test_endpoints.R | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/testthat/test_endpoints.R (limited to 'tests/testthat/test_endpoints.R') diff --git a/tests/testthat/test_endpoints.R b/tests/testthat/test_endpoints.R new file mode 100644 index 00000000..284e1379 --- /dev/null +++ b/tests/testthat/test_endpoints.R @@ -0,0 +1,49 @@ +context("DTx calculations") + +test_that("The DTx function gives the same results as the endpoints function", { + # We silently assume that the calculations in the endpoint function are correct + + SFO_fit <- fits[["SFO", "FOCUS_C"]] + SFO_distimes <- endpoints(SFO_fit)$distimes + SFO_DTx <- DTx("SFO", c(k = parms(SFO_fit)[["k_parent"]])) + + expect_equal( + as.numeric(SFO_distimes), + as.numeric(SFO_DTx) + ) + + FOMC_fit <- fits[["FOMC", "FOCUS_C"]] + FOMC_distimes <- endpoints(FOMC_fit)$distimes + FOMC_DTx <- DTx("FOMC", c( + alpha = parms(FOMC_fit)[["alpha"]], + beta = parms(FOMC_fit)[["beta"]]), exact = TRUE) + + expect_equal( + as.numeric(FOMC_distimes), + as.numeric(FOMC_DTx) + ) + + DFOP_fit <- fits[["DFOP", "FOCUS_C"]] + DFOP_distimes <- endpoints(DFOP_fit)$distimes + DFOP_DTx <- DTx("DFOP", c( + k1 = parms(DFOP_fit)[["k1"]], + k2 = parms(DFOP_fit)[["k2"]], + g = parms(DFOP_fit)[["g"]]), exact = TRUE) + + expect_equal( + as.numeric(DFOP_distimes), + as.numeric(DFOP_DTx) + ) + + HS_fit <- fits[["HS", "FOCUS_C"]] + HS_distimes <- endpoints(HS_fit)$distimes + HS_DTx <- DTx("HS", c( + k1 = parms(HS_fit)[["k1"]], + k2 = parms(HS_fit)[["k2"]], + tb = parms(HS_fit)[["tb"]]), exact = TRUE) + + expect_equal( + as.numeric(HS_distimes), + as.numeric(HS_DTx) + ) +}) -- cgit v1.2.3