Skip to content

Commit

Permalink
qualify internal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Jul 18, 2023
1 parent 6afdbc2 commit 1205d1a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/test-delays.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test_stan_delays <- function(generation_time = generation_time_opts(),
delays = delay_opts(),
truncation = trunc_opts(),
params = c()) {
data <- create_stan_delays(
data <- EpiNow2:::create_stan_delays(
generation_time = generation_time,
delays = delays,
truncation = truncation,
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-dist_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ test_that("Testing `+.dist_spec` function with tolerance parameter", {
)

# Compute combined distribution with default tolerance
combined_default <- `+.dist_spec`(lognormal, gamma)
combined_default <- EpiNow2:::`+.dist_spec`(lognormal, gamma)

# Compute combined distribution with larger tolerance
combined_larger_tolerance <- EpiNow2:::dist_spec_plus(
Expand Down Expand Up @@ -148,21 +148,21 @@ test_that("mean.dist_spec returns correct output for fixed lognormal distributio
mean = convert_to_logmean(3, 1), sd = convert_to_logsd(3, 1),
max = 20, distribution = "lognormal"
)
result <- mean.dist_spec(lognormal)
result <- EpiNow2:::mean.dist_spec(lognormal)
expect_equal(result, 2.49, tolerance = 0.01) # here we can see the bias from
# using this kind of discretisation approach
})

test_that("mean.dist_spec returns correct output for uncertain gamma distribution", {
gamma <- dist_spec(mean = 3, sd = 2, mean_sd = 0.5, sd_sd = 0.5, max = 20, distribution = "gamma")
result <- mean.dist_spec(gamma)
result <- EpiNow2:::mean.dist_spec(gamma)
expect_equal(result, 3)
})

test_that("mean.dist_spec returns correct output for sum of two distributions", {
lognormal <- dist_spec(mean = 1, sd = 1, max = 20, distribution = "lognormal")
gamma <- dist_spec(mean = 3, sd = 2, max = 20, distribution = "gamma")
result <- mean.dist_spec(lognormal + gamma)
result <- EpiNow2:::mean.dist_spec(lognormal + gamma)
expect_equal(result, c(5.84), tolerance = 0.001)
})

Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test-match_output_arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ test_that("match_output_arguments works as expected", {
out <- rep(FALSE, 3)
names(out) <- c("fit", "plots", "samples")
expect_equal(
match_output_arguments(supported_args = names(out)),
EpiNow2:::match_output_arguments(supported_args = names(out)),
out
)
out["plots"] <- TRUE
expect_equal(match_output_arguments("plots", supported_args = names(out)), out)
expect_equal(
EpiNow2:::match_output_arguments("plots", supported_args = names(out)), out
)
out["samples"] <- TRUE
expect_equal(match_output_arguments(c("plots", "samples"),
expect_equal(EpiNow2:::match_output_arguments(c("plots", "samples"),
supported_args = names(out)
), out)
expect_equal(match_output_arguments("p", supported_args = names(out)), out)
expect_equal(
EpiNow2:::match_output_arguments("p", supported_args = names(out)), out
)
})
10 changes: 7 additions & 3 deletions tests/testthat/test-seeding-time.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ test_that("Seeding times are correctly calculated", {
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
expect_equal(
EpiNow2:::get_seeding_time(delay1, gt1 + gt2), 23L ## 10 + 15 - 1 - 1
)
expect_equal(
EpiNow2:::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)
expect_equal(EpiNow2:::get_seeding_time(delay, gt), 1L)
})

0 comments on commit 1205d1a

Please sign in to comment.