Skip to content

Commit

Permalink
refactor: filter and move library calls to testthat.R
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Apr 30, 2024
1 parent 128bd7d commit 8edd5a5
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 19 deletions.
2 changes: 2 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
library(testthat)
library(epiprocess)

library(dplyr)

test_check("epiprocess")
2 changes: 0 additions & 2 deletions tests/testthat/test-archive.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library(dplyr)

test_that("first input must be a data.frame", {
expect_error(as_epi_archive(c(1, 2, 3), compactify = FALSE),
regexp = "Must be of type 'data.frame'."
Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-autoplot.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
library(dplyr)

d <- as.Date("2020-01-01")

raw_df_chr <- dplyr::bind_rows(
dplyr::tibble(geo_value = "ak", time_value = d + 1:5, value = "a"),
dplyr::tibble(geo_value = "al", time_value = d + 1:5, value = "d")
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/test-compactify.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
library(epiprocess)
library(data.table)
library(dplyr)

dt <- archive_cases_dv_subset$DT
dt <- filter(dt, geo_value == "ca") %>%
filter(version <= "2020-06-15") %>%
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-correlation.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library(tibble)

test_that("epi_cor throws an error for a non-epi_df for its first argument", {
expect_error(epi_cor(1:10, 1, 1))
expect_error(epi_cor(data.frame(x = 1:10), 1, 1))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-data.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("`archive_cases_dv_subset` is formed successfully", {
expect_true(is_epi_archive(archive_cases_dv_subset))
expect_class(archive_cases_dv_subset, "epi_archive")
})

test_that("`delayed_assign_with_unregister_awareness` works as expected on good promises", {
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-epix_slide.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library(dplyr)

test_that("epix_slide only works on an epi_archive", {
expect_error(epix_slide(data.frame(x = 1)))
})
Expand Down Expand Up @@ -506,7 +504,7 @@ test_that("epix_as_of and epix_slide with long enough window are compatible", {

test_that("epix_slide `f` is passed an ungrouped `epi_archive` when `all_versions=TRUE`", {
slide_fn <- function(x, gk, rtv) {
expect_true(is_epi_archive(x))
expect_class(x, "epi_archive")
return(NA)
}

Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test-methods-epi_archive.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
library(dplyr)

ea <- archive_cases_dv_subset

ea2_data <- tibble::tribble(
~geo_value, ~time_value, ~version, ~cases,
"ca", "2020-06-01", "2020-06-01", 1,
Expand Down Expand Up @@ -104,7 +101,7 @@ test_that("epix_truncate_version_after returns the same grouping type as input e

ea_as_of <- ea2 %>%
epix_truncate_versions_after(max_version = as.Date("2020-06-04"))
expect_true(is_epi_archive(ea_as_of, grouped_okay = FALSE))
expect_class(ea_as_of, "epi_archive")

ea2_grouped <- ea2 %>% group_by(geo_value)

Expand Down

0 comments on commit 8edd5a5

Please sign in to comment.