Skip to content

Issue 735: Fix truncation slicing when t < truncation #736

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

Merged
merged 9 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
hack around truncate overloading
  • Loading branch information
seabbs committed Aug 8, 2024
commit 1e937a70bfad213773d64cc0a673bfd4a3bfb8af
4 changes: 3 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ if (identical(Sys.getenv("NOT_CRAN"), "true")) {
if (!(tolower(Sys.info()[["sysname"]]) %in% "windows")) {
suppressMessages(
expose_stan_fns(files,
target_dir = system.file("stan/functions", package = "EpiNow2")
target_dir = "inst/stan/functions"
)
)
# avoid problems due to base::truncate
stan_truncate <- truncate
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-stan-truncate.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ test_that("truncate() can perform truncation as expected", {
reports <- c(10, 20, 30, 40, 50)
trunc_rev_cmf <- c(1, 0.8, 0.5, 0.2)
expected <- c(reports[1], reports[2:5] * trunc_rev_cmf)
expect_equal(truncate(reports, trunc_rev_cmf, FALSE), expected)
expect_equal(stan_truncate(reports, trunc_rev_cmf, FALSE), expected)
})

test_that("truncate() can perform reconstruction as expected", {
reports <- c(10, 20, 15, 8, 10)
trunc_rev_cmf <- c(1, 0.8, 0.5, 0.2)
expected <- c(reports[1], reports[2:5] / trunc_rev_cmf)
expect_equal(truncate(reports, trunc_rev_cmf, TRUE), expected)
expect_equal(stan_truncate(reports, trunc_rev_cmf, TRUE), expected)
})

test_that("truncate() can handle longer trunc_rev_cmf than reports", {
reports <- c(10, 20, 30)
trunc_rev_cmf <- c(1, 0.8, 0.5, 0.2, 0.1)
expected <- reports * trunc_rev_cmf[3:5]
expect_equal(truncate(reports, trunc_rev_cmf, FALSE), expected)
expect_equal(stan_truncate(reports, trunc_rev_cmf, FALSE), expected)
})

test_that("truncate() can handle reconstruction with longer trunc_rev_cmf than reports", {
reports <- c(10, 16, 15)
trunc_rev_cmf <- c(1, 0.8, 0.5, 0.2, 0.1)
expected <- reports / trunc_rev_cmf[3:5]
expect_equal(truncate(reports, trunc_rev_cmf, TRUE), expected)
expect_equal(stan_truncate(reports, trunc_rev_cmf, TRUE), expected)
})