From 1c3de1a820533980e3ed3345d206d7e411075861 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 3 Jul 2023 16:42:59 +0100 Subject: [PATCH] replace example with test --- R/get.R | 5 ----- man/get_seeding_time.Rd | 6 ------ tests/testthat/test-seeding-time.R | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/test-seeding-time.R diff --git a/R/get.R b/R/get.R index e376b55e6..a13d08af3 100644 --- a/R/get.R +++ b/R/get.R @@ -310,11 +310,6 @@ get_regions_with_most_reports <- function(reported_cases, ##' @param generation_time Generation time as specified using `dist_spec` ##' @return An integer seeding time ##' @author Sebastian Funk -##' @examples -##' gt1 <- dist_spec(mean = 5, sd = 1, max = 15) -##' gt2 <- dist_spec(mean = 10, sd = 2, max = 10) -##' delays <- dist_spec(mean = 5, sd = 1, max = 15) -##' get_seeding_time(delays, gt1 + gt2) get_seeding_time <- function(delays, generation_time) { # Estimate the mean delay ----------------------------------------------- seeding_time <- sum(mean(delays)) diff --git a/man/get_seeding_time.Rd b/man/get_seeding_time.Rd index 53a9dca4f..77c7f51b6 100644 --- a/man/get_seeding_time.Rd +++ b/man/get_seeding_time.Rd @@ -18,12 +18,6 @@ An integer seeding time The seeding time is set to the mean of the specified delays, constrained to be at least the maximum generation time } -\examples{ -gt1 <- dist_spec(mean = 5, sd = 1, max = 15) -gt2 <- dist_spec(mean = 10, sd = 2, max = 10) -delays <- dist_spec(mean = 5, sd = 1, max = 15) -get_seeding_time(delays, gt1 + gt2) -} \author{ Sebastian Funk } diff --git a/tests/testthat/test-seeding-time.R b/tests/testthat/test-seeding-time.R new file mode 100644 index 000000000..5fe43a1d7 --- /dev/null +++ b/tests/testthat/test-seeding-time.R @@ -0,0 +1,14 @@ +test_that("Seeding times are correctly calculated", { + gt1 <- dist_spec(mean = 5, sd = 1, max = 10) + gt2 <- dist_spec(mean = 10, sd = 2, max = 15) + delay1 <- dist_spec(mean = 5, sd = 1, max = 10) + delay2 <- dist_spec(mean = 7, sd = 3, max = 15) + expect_equal(get_seeding_time(delay1, gt1 + gt2), 23L) ## 10 + 15 - 1 - 1 + expect_equal(get_seeding_time(delay1 + delay2, gt1), 12L) ## 5 + 7 +}) + +test_that("Short seeding times are rounded up to 1", { + delay <- dist_spec(mean = 0.5, sd = 1, max = 2) + gt <- dist_spec(mean = 1) + expect_equal(get_seeding_time(delay, gt), 1L) +})