Skip to content

Commit

Permalink
Add parameter skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
zsusswein committed Aug 31, 2024
1 parent 1aa4eb1 commit bb12c41
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions R/parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ read_parameters <- function(
cli::cli_alert_warning(
"No delay interval path specified. Using a delay of 0 days"
)
delay_interval <- NA
}

if (path_is_specified(right_truncation_path)) {
Expand All @@ -37,6 +38,7 @@ read_parameters <- function(
cli::cli_alert_warning(
"No right truncation path specified. Not adjusting for right truncation."
)
right_truncation <- NA
}

parameters <- list(
Expand Down
65 changes: 64 additions & 1 deletion tests/testthat/test-parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,70 @@ test_that("Can read all params on happy path", {
})


expect_equal(actual, c(rep(list(c(0.8, 0.2)), 3)))
expect_equal(
actual,
list(
generation_interval = expected,
delay_interval = expected,
right_truncation = expected
)
)
})

test_that("Can skip params on happy path", {
expected <- c(0.8, 0.2)
start_date <- as.Date("2023-01-01")
disease <- "COVID-19"

withr::with_tempdir({
write_sample_parameters_file(
value = expected,
parameter = "generation_interval",
path = "generation_interval.parquet",
disease = disease,
state = NA,
start_date = start_date,
end_date = NA
)
write_sample_parameters_file(
value = expected,
parameter = "delay",
path = "delay_interval.parquet",
disease = disease,
state = NA,
start_date = start_date,
end_date = NA
)
write_sample_parameters_file(
value = expected,
parameter = "right_truncation",
path = "right_truncation.parquet",
disease = disease,
state = "test",
start_date = start_date,
end_date = NA
)


actual <- read_parameters(
generation_interval_path = "generation_interval.parquet",
delay_interval_path = NULL,
right_truncation_path = NULL,
disease = "COVID-19",
as_of_date = start_date + 1,
state = "test"
)
})


expect_equal(
actual,
list(
generation_interval = expected,
delay_interval = NA,
right_truncation = NA
)
)
})

test_that("Can read right-truncation on happy path", {
Expand Down

0 comments on commit bb12c41

Please sign in to comment.