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

Hot fix validate pmf #191

Merged
merged 3 commits into from
Sep 28, 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
5 changes: 4 additions & 1 deletion R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,18 @@ validate_both_datasets <- function(input_count_data,
#' @param calibration_time integer indicating the calibration time
#' @param count_data tibble containing the input count data ready to be passed
#' to stan
#' @param tolerance numeric indicating the allowable difference between the
#' sum of the pmf and 1, default is `1e-6`
#' @param arg name of the argument supplying the object
#' @param call The calling environment to be reflected in the error message
#' @return NULL, invisibly
validate_pmf <- function(pmf,
calibration_time,
count_data,
tolerance = 1e-6,
arg = "x",
call = rlang::caller_env()) {
if (!all.equal(sum(pmf), 1)) {
if (!isTRUE(all.equal(sum(pmf), 1, tolerance = 1e-6))) {
cli::cli_abort(
c(
"{.arg {arg}} does not sum to 1."
Expand Down
4 changes: 4 additions & 0 deletions man/validate_pmf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test_checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ test_that(
}
)

test_that(
"Test that validate pmfs returns the expected error message.",
{
invalid_pmf <- c(0.4, 0.4, 0.4)
expect_error(validate_pmf(invalid_pmf),
regexp = "does not sum to 1"
)
}
)

test_that(
"Test that assert dates in range function works as expected.",
{
Expand Down