Skip to content

Commit

Permalink
tests: add some basic tests for group-aware methods
Browse files Browse the repository at this point in the history
  • Loading branch information
TimTaylor committed May 23, 2024
1 parent e32be84 commit 66304d5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/testthat/test-mutate.R
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)
)
)

})
13 changes: 13 additions & 0 deletions tests/testthat/test-nest.R
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))
)
})
17 changes: 17 additions & 0 deletions tests/testthat/test-split.R
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)
})
14 changes: 14 additions & 0 deletions tests/testthat/test-summarise.R
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))
)
})

0 comments on commit 66304d5

Please sign in to comment.