diff --git a/DESCRIPTION b/DESCRIPTION index 13f82df..9076b29 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,7 +51,7 @@ Suggests: tidyr, roxygen2, usethis, - testthat, + testthat (>= 3.0.0), rcmdcheck, httptest VignetteBuilder: @@ -63,3 +63,4 @@ LazyData: true Remotes: hubverse-org/hubData BugReports: https://github.com/CDCgov/forecasttools/issues +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..a328e6d --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(forecasttools) + +test_check("forecasttools") diff --git a/tests/testthat/test_epiweek_to_date.R b/tests/testthat/test_epiweek_to_date.R index 83e0d3e..75970b9 100644 --- a/tests/testthat/test_epiweek_to_date.R +++ b/tests/testthat/test_epiweek_to_date.R @@ -4,13 +4,13 @@ schema <- tidyr::crossing( day_of_week = 1:7 ) -testthat::test_that(paste0( +test_that(paste0( "epiweek_to_date() function's internal ", "validation passes for USA epiweeks for ", "every epiweek in 1:52 for every epiyear ", "in 1800:2200, for every day of the epiweek" ), { - testthat::expect_no_error( + expect_no_error( with_usa_dates <- schema |> dplyr::mutate( date = forecasttools::epiweek_to_date( @@ -24,13 +24,13 @@ testthat::test_that(paste0( ) }) -testthat::test_that(paste0( +test_that(paste0( "epiweek_to_date() function's internal ", "validation passes for ISO (epi)weeks for ", "every epiweek in 1:52 for every epiyear ", "in 1800:2200, for every day of the epiweek" ), { - testthat::expect_no_error( + expect_no_error( with_iso_dates <- schema |> dplyr::mutate( date = forecasttools::epiweek_to_date( @@ -45,14 +45,14 @@ testthat::test_that(paste0( }) -testthat::test_that(paste0( +test_that(paste0( "epiweek_to_date() function's internal ", "validation fails if you try to get the ", "start of an epiweek that doesn't exist ", "but passes if you get a valid epiweek" ), { ## 2020 had an epiweek 53 - testthat::expect_no_error( + expect_no_error( forecasttools::epiweek_to_date( 53, 2020, @@ -62,7 +62,7 @@ testthat::test_that(paste0( ) ## 2021 did not - testthat::expect_error( + expect_error( forecasttools::epiweek_to_date( 53, 2021, @@ -72,7 +72,7 @@ testthat::test_that(paste0( ) ## a single failure should raise an error - testthat::expect_error( + expect_error( forecasttools::epiweek_to_date( 53, c(2020, 2021), @@ -83,7 +83,7 @@ testthat::test_that(paste0( ## but the validation should be vectorized ## and succeed accordingly - testthat::expect_no_error( + expect_no_error( forecasttools::epiweek_to_date( c(53, 52), c(2020, 2021), diff --git a/tests/testthat/test_inferencedata_dataframe_to_tidydraws.R b/tests/testthat/test_inferencedata_dataframe_to_tidydraws.R index def21b5..8a78b9e 100644 --- a/tests/testthat/test_inferencedata_dataframe_to_tidydraws.R +++ b/tests/testthat/test_inferencedata_dataframe_to_tidydraws.R @@ -1,11 +1,11 @@ -testthat::test_that("inferencedata_to_tidy_draws converts data correctly", { +test_that("inferencedata_to_tidy_draws converts data correctly", { data("ex_inferencedata_dataframe") result <- inferencedata_to_tidy_draws(ex_inferencedata_dataframe) - testthat::expect_setequal(colnames(result), c("group", "data")) - testthat::expect_setequal(result$group, c("posterior", "predictions")) + expect_setequal(colnames(result), c("group", "data")) + expect_setequal(result$group, c("posterior", "predictions")) - testthat::expect_equal( + expect_equal( colnames(result$data[[1]]), c( ".chain", ".iteration", ".draw", "a", "b[troll_shore]", "b[drawn]", @@ -17,7 +17,7 @@ testthat::test_that("inferencedata_to_tidy_draws converts data correctly", { ) ) - testthat::expect_equal( + expect_equal( colnames(result$data[[2]]), c( ".chain", ".iteration", ".draw", "obs[woken]", "obs[awash]", @@ -25,10 +25,10 @@ testthat::test_that("inferencedata_to_tidy_draws converts data correctly", { ) ) - testthat::expect_no_error( + expect_no_error( tidybayes::spread_draws(result$data[[1]], a, b[x], c[y, z]) ) - testthat::expect_no_error( + expect_no_error( tidybayes::spread_draws(result$data[[2]], obs[a]) ) }) diff --git a/tests/testthat/test_simple_bottom_up.R b/tests/testthat/test_simple_bottom_up.R index 3162c46..ee0e022 100644 --- a/tests/testthat/test_simple_bottom_up.R +++ b/tests/testthat/test_simple_bottom_up.R @@ -32,8 +32,8 @@ test_u_mat <- matrix(c(0.1, 0.3, 0.7), nrow = 1) location_names <- c("A", "B", "C") colnames(test_u_mat) <- location_names -testthat::test_that("`validate_base_forecasts` throws an error", { - testthat::expect_error(validate_base_forecasts(bad_test_base_forecasts, +test_that("`validate_base_forecasts` throws an error", { + expect_error(validate_base_forecasts(bad_test_base_forecasts, test_cp, value_to_aggregate_col = "hosps", rank_quantity_col = "rank_quantity", @@ -42,7 +42,7 @@ testthat::test_that("`validate_base_forecasts` throws an error", { )) }) -testthat::test_that("`count_trajectories` returns correct number of trajs", { +test_that("`count_trajectories` returns correct number of trajs", { result <- count_trajectories(test_base_forecasts, location_col = "location", date_col = "date" @@ -51,10 +51,10 @@ testthat::test_that("`count_trajectories` returns correct number of trajs", { location = c("A", "B", "C"), n_sample_trajs = c(2, 2, 2) ) - testthat::expect_equal(result, expected_output) + expect_equal(result, expected_output) }) -testthat::test_that("`copula2tbl` returns the expected output", { +test_that("`copula2tbl` returns the expected output", { i <- 1 location_col <- "location" @@ -65,10 +65,10 @@ testthat::test_that("`copula2tbl` returns the expected output", { location = location_names ) - testthat::expect_equal(result, expected_output) + expect_equal(result, expected_output) }) -testthat::test_that("`rank_sampled_trajectories` returns correct rankings", { +test_that("`rank_sampled_trajectories` returns correct rankings", { ranked_base_forecasts <- rank_sampled_trajectories(test_base_forecasts, location_col = "location", @@ -83,10 +83,10 @@ testthat::test_that("`rank_sampled_trajectories` returns correct rankings", { rank = c(1, 2, 1, 2, 1, 2) ) - testthat::expect_equal(ranked_base_forecasts, expected_rankings) + expect_equal(ranked_base_forecasts, expected_rankings) }) -testthat::test_that("sample_aggregated_trajectories", { +test_that("sample_aggregated_trajectories", { i <- 1 location_col <- "location" test_sample <- copula2tbl( @@ -123,5 +123,5 @@ testthat::test_that("sample_aggregated_trajectories", { forecast = c(123, 200) ) - testthat::expect_equal(result, expected_output) + expect_equal(result, expected_output) }) diff --git a/tests/testthat/test_to_hubverse.R b/tests/testthat/test_to_hubverse.R index 0a11854..048b239 100644 --- a/tests/testthat/test_to_hubverse.R +++ b/tests/testthat/test_to_hubverse.R @@ -1,17 +1,17 @@ -testthat::test_that( +test_that( paste0( "get_hubverse_table errors if reference date ", "is the wrong day of the week" ), { - testthat::expect_error( + expect_error( forecasttools::get_hubverse_table( tibble::tibble(), "2025-01-01" ), "which is day number 4" ) - testthat::expect_error( + expect_error( forecasttools::get_hubverse_table( tibble::tibble(), "2025-01-01", @@ -19,7 +19,7 @@ testthat::test_that( ), "which is day number 1" ) - testthat::expect_error( + expect_error( forecasttools::get_hubverse_table( tibble::tibble(), "2025-01-01",