diff --git a/tests/testthat/test-mutate.R b/tests/testthat/test-mutate.R new file mode 100644 index 00000000..fc994155 --- /dev/null +++ b/tests/testthat/test-mutate.R @@ -0,0 +1,25 @@ +test_that("mutate works", { + skip_if_not_installed("outbreaks") + + data(ebola_sim_clean, package = "outbreaks") + dat <- + ebola_sim_clean$linelist |> + subset(!is.na(hospital)) |> + incidence_(date_of_onset, hospital, interval = "isoweek") + + expect_identical( + as_tibble( + mutate( + dat, + ave = data.table::frollmean(count, n = 3L, align = "right") + ) + ), + + mutate( + as_tibble(dat), + ave = data.table::frollmean(count, n = 3L, align = "right"), + .by = c(count_variable, hospital) + ) + ) + +}) diff --git a/tests/testthat/test-nest.R b/tests/testthat/test-nest.R new file mode 100644 index 00000000..6dfb25cf --- /dev/null +++ b/tests/testthat/test-nest.R @@ -0,0 +1,13 @@ +test_that("nest works", { + skip_if_not_installed("outbreaks") + data(ebola_sim_clean, package = "outbreaks") + dat <- + ebola_sim_clean$linelist |> + subset(!is.na(hospital)) |> + incidence_(date_of_onset, hospital, interval = "isoweek") + + expect_identical( + nest(dat), + nest(as_tibble(dat), .by = c(count_variable, hospital)) + ) +}) diff --git a/tests/testthat/test-split.R b/tests/testthat/test-split.R new file mode 100644 index 00000000..777c3787 --- /dev/null +++ b/tests/testthat/test-split.R @@ -0,0 +1,17 @@ +test_that("split works", { + skip_if_not_installed("outbreaks") + + data(ebola_sim_clean, package = "outbreaks") + + dat <- + ebola_sim_clean$linelist |> + subset(!is.na(hospital)) |> + incidence_(date_of_onset, hospital, interval = "isoweek") + + out <- split(dat) + + expected <- vctrs::vec_split(as_tibble(dat), as_tibble(dat)[c("count_variable", "hospital")]) + + expect_identical(c(out), expected$val) + expect_identical(attr(out, "key"), expected$key) +}) diff --git a/tests/testthat/test-summarise.R b/tests/testthat/test-summarise.R new file mode 100644 index 00000000..720d7371 --- /dev/null +++ b/tests/testthat/test-summarise.R @@ -0,0 +1,14 @@ +test_that("summarise works", { + skip_if_not_installed("outbreaks") + + data(ebola_sim_clean, package = "outbreaks") + dat <- + ebola_sim_clean$linelist |> + subset(!is.na(hospital)) |> + incidence_(date_of_onset, hospital, interval = "isoweek") + + expect_identical( + summarise(dat, sum(count)), + summarise(as_tibble(dat), sum(count), .by = c(count_variable, hospital)) + ) +})