-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add some basic tests for group-aware methods
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
) | ||
) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
) | ||
}) |