Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #540

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R/dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -1403,12 +1403,12 @@
## apply stragey depending on choice
if (strategy == "mean") {
x <- dist_spec(
mean = x$mean_mean,
sd = x$sd_mean,
mean = c(x$mean_mean),
sd = c(x$sd_mean),
mean_sd = 0,
sd_sd = 0,
distribution = x$dist,
max = x$max
max = c(x$max)
)
} else if (strategy == "sample") {
lower_bound <- ifelse(x$dist == "gamma", 0, -Inf)
Expand All @@ -1422,7 +1422,7 @@
mean_sd = 0,
sd_sd = 0,
distribution = x$dist,
max = x$max
max = c(x$max)

Check warning on line 1425 in R/dist.R

View check run for this annotation

Codecov / codecov/patch

R/dist.R#L1425

Added line #L1425 was not covered by tests
)
}
return(x)
Expand Down
2 changes: 1 addition & 1 deletion R/opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
if (!("mean" %in% names(dot_options))) {
dot_options$mean <- 1
}
dot_options$fixed <- fixed
dist <- do.call(dist_spec, dot_options)
if (fixed) dist <- fix_dist(dist)

Check warning on line 67 in R/opts.R

View check run for this annotation

Codecov / codecov/patch

R/opts.R#L67

Added line #L67 was not covered by tests
deprecated_options_given <- TRUE
} else if (!missing(disease) && !missing(source)) {
dist <- get_generation_time(disease, source, max, fixed)
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/_snaps/calc_CrI.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# calc_CrI works as expected with default arguments

value CrI
<num> <char>
1: 1.45 lower_90
2: 9.55 upper_90

# calc_CrI works as expected when grouping

type value CrI
1: car 1.45 lower_90
2: car 9.55 upper_90
type value CrI
<char> <num> <char>
1: car 1.45 lower_90
2: car 9.55 upper_90

18 changes: 12 additions & 6 deletions tests/testthat/_snaps/calc_CrIs.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# calc_CrI works as expected with default arguments

. lower_90 lower_50 lower_20 upper_20 upper_50 upper_90
1: . 1.45 3.25 4.6 6.4 7.75 9.55
Key: <.>
. lower_90 lower_50 lower_20 upper_20 upper_50 upper_90
<char> <num> <num> <num> <num> <num> <num>
1: . 1.45 3.25 4.6 6.4 7.75 9.55

# calc_CrI works as expected when grouping

type lower_90 lower_50 lower_20 upper_20 upper_50 upper_90
1: car 1.45 3.25 4.6 6.4 7.75 9.55
Key: <type>
type lower_90 lower_50 lower_20 upper_20 upper_50 upper_90
<char> <num> <num> <num> <num> <num> <num>
1: car 1.45 3.25 4.6 6.4 7.75 9.55

# calc_CrI works as expected when given a custom CrI list

. lower_95 lower_40 lower_10 upper_10 upper_40 upper_95
1: . 1.225 3.7 5.05 5.95 7.3 9.775
Key: <.>
. lower_95 lower_40 lower_10 upper_10 upper_40 upper_95
<char> <num> <num> <num> <num> <num> <num>
1: . 1.225 3.7 5.05 5.95 7.3 9.775

18 changes: 12 additions & 6 deletions tests/testthat/_snaps/calc_summary_measures.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# calc_summary_measures works as expected with default arguments

type median mean sd lower_90 lower_50 lower_20 upper_20 upper_50
1: car 5.5 5.5 3.02765 1.45 3.25 4.6 6.4 7.75
type median mean sd lower_90 lower_50 lower_20 upper_20 upper_50
<char> <num> <num> <num> <num> <num> <num> <num> <num>
1: car 5.5 5.5 3.02765 1.45 3.25 4.6 6.4 7.75
upper_90
<num>
1: 9.55

# calc_CrI works as expected when grouping

type median mean sd lower_90 lower_50 lower_20 upper_20 upper_50
1: car 5.5 5.5 3.02765 1.45 3.25 4.6 6.4 7.75
type median mean sd lower_90 lower_50 lower_20 upper_20 upper_50
<char> <num> <num> <num> <num> <num> <num> <num> <num>
1: car 5.5 5.5 3.02765 1.45 3.25 4.6 6.4 7.75
upper_90
<num>
1: 9.55

# calc_CrI works as expected when given a custom CrI list

type median mean sd lower_95 lower_40 lower_10 upper_10 upper_40
1: car 5.5 5.5 3.02765 1.225 3.7 5.05 5.95 7.3
type median mean sd lower_95 lower_40 lower_10 upper_10 upper_40
<char> <num> <num> <num> <num> <num> <num> <num> <num>
1: car 5.5 5.5 3.02765 1.225 3.7 5.05 5.95 7.3
upper_95
<num>
1: 9.775

10 changes: 6 additions & 4 deletions tests/testthat/_snaps/calc_summary_stats.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# calc_summary_stats works as expected with default arguments

median mean sd
1: 5.5 5.5 3.02765
median mean sd
<num> <num> <num>
1: 5.5 5.5 3.02765

# calc_summary_stats works as expected when grouping

type median mean sd
1: car 5.5 5.5 3.02765
type median mean sd
<char> <num> <num> <num>
1: car 5.5 5.5 3.02765

17 changes: 8 additions & 9 deletions tests/testthat/test-dist_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ test_that("dist_spec returns correct output for uncertain gamma distribution", {
})

test_that("dist_spec returns correct output for fixed distribution", {
result <- dist_spec(
result <- fix_dist(dist_spec(
mean = 5, mean_sd = 3, sd = 1, max = 19, distribution = "lognormal",
fixed = TRUE
)
))
expect_equal(dim(result$mean_mean), 0)
expect_equal(dim(result$sd_mean), 0)
expect_equal(result$fixed, array(1L))
Expand Down Expand Up @@ -74,12 +73,12 @@ test_that("+.dist_spec returns correct output for sum of two distributions", {
})

test_that("+.dist_spec returns correct output for sum of two fixed distributions", {
lognormal <- dist_spec(
mean = 5, sd = 1, max = 19, distribution = "lognormal", fixed = TRUE
)
gamma <- dist_spec(
mean = 3, sd = 2, max = 19, distribution = "gamma", fixed = TRUE
)
lognormal <- fix_dist(dist_spec(
mean = 5, sd = 1, max = 19, distribution = "lognormal"
))
gamma <- fix_dist(dist_spec(
mean = 3, sd = 2, max = 19, distribution = "gamma"
))
result <- lognormal + gamma
expect_equal(dim(result$mean_mean), 0)
expect_equal(dim(result$sd_mean), 0)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ test_that("estimate_infections fails as expected when given a very short timeout
expect_error(output <- capture.output(suppressMessages(
out <- default_estimate_infections(
reported_cases,
add_stan = list(future = TRUE, max_execution_time = 1)
add_stan = list(future = TRUE, max_execution_time = 1, samples = 2000)
))), "all chains failed")
expect_error(output <- capture.output(suppressMessages(
out <- default_estimate_infections(
reported_cases,
add_stan = list(future = FALSE, max_execution_time = 1)
add_stan = list(future = FALSE, max_execution_time = 1, samples = 2000)
))), "timed out")
})

Expand Down
Loading