From 81a15062126d2d8852f8667ed5dbe7df643b7e36 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 2 Jan 2024 16:24:32 +0100 Subject: [PATCH] update tests to avoid random messages --- .../plot-interval-coverage.svg | 20 +++++++++---------- .../plot-quantile-coverage.svg | 20 +++++++++---------- tests/testthat/test-add_coverage.R | 2 +- tests/testthat/test-available_forecasts.R | 10 +++++----- tests/testthat/test-check_forecasts.R | 2 +- tests/testthat/test-convenience-functions.R | 2 +- tests/testthat/test-get_-functions.R | 6 +++--- tests/testthat/test-plot_ranges.R | 1 + 8 files changed, 30 insertions(+), 33 deletions(-) diff --git a/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg b/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg index 91848b1dd..548878c34 100644 --- a/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg +++ b/tests/testthat/_snaps/plot_interval_coverage/plot-interval-coverage.svg @@ -57,17 +57,15 @@ 100 Nominal interval coverage % Obs inside interval -model - - - - - -EuroCOVIDhub-baseline -EuroCOVIDhub-ensemble -UMass-MechBayes -epiforecasts-EpiNow2 -NA +model + + + + +EuroCOVIDhub-baseline +EuroCOVIDhub-ensemble +UMass-MechBayes +epiforecasts-EpiNow2 plot_interval_coverage diff --git a/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg b/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg index 76808cc67..bf686eedb 100644 --- a/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg +++ b/tests/testthat/_snaps/plot_quantile_coverage/plot-quantile-coverage.svg @@ -57,17 +57,15 @@ 1.00 Quantile % Obs below quantile -model - - - - - -EuroCOVIDhub-baseline -EuroCOVIDhub-ensemble -UMass-MechBayes -epiforecasts-EpiNow2 -NA +model + + + + +EuroCOVIDhub-baseline +EuroCOVIDhub-ensemble +UMass-MechBayes +epiforecasts-EpiNow2 plot_quantile_coverage diff --git a/tests/testthat/test-add_coverage.R b/tests/testthat/test-add_coverage.R index 423181d2c..32b722a8a 100644 --- a/tests/testthat/test-add_coverage.R +++ b/tests/testthat/test-add_coverage.R @@ -3,7 +3,7 @@ ex_coverage <- example_quantile[model == "EuroCOVIDhub-ensemble"] test_that("add_coverage() works as expected", { expect_message( cov <- add_coverage(example_quantile), - "Some rows contain NA values and will be removed in subsequent operations" + "Some rows containing NA values may be removed." ) required_names <- c( diff --git a/tests/testthat/test-available_forecasts.R b/tests/testthat/test-available_forecasts.R index ffa9e4f9e..4507820b1 100644 --- a/tests/testthat/test-available_forecasts.R +++ b/tests/testthat/test-available_forecasts.R @@ -8,26 +8,26 @@ test_that("get_forecast_counts() works as expected", { expect_type(af$target_type, "character") expect_type(af$`count`, "integer") expect_equal(nrow(af[is.na(`count`)]), 0) - af <- get_forecast_counts(example_quantile, by = "model") + af <- get_forecast_counts(na.omit(example_quantile), by = "model") expect_equal(nrow(af), 4) expect_equal(af$`count`, c(256, 256, 128, 247)) # Setting `collapse = c()` means that all quantiles and samples are counted af <- get_forecast_counts( - example_quantile, + na.omit(example_quantile), by = "model", collapse = c() ) expect_equal(nrow(af), 4) expect_equal(af$`count`, c(5888, 5888, 2944, 5681)) # setting by = NULL, the default, results in by equal to forecast unit - af <- get_forecast_counts(example_quantile) + af <- get_forecast_counts(na.omit(example_quantile)) expect_equal(nrow(af), 50688) # check whether collapsing also works for model-based forecasts - af <- get_forecast_counts(example_integer, by = "model") + af <- get_forecast_counts(na.omit(example_integer), by = "model") expect_equal(nrow(af), 4) - af <- get_forecast_counts(example_integer, by = "model", collapse = c()) + af <- get_forecast_counts(na.omit(example_integer), by = "model", collapse = c()) expect_equal(af$count, c(10240, 10240, 5120, 9880)) }) diff --git a/tests/testthat/test-check_forecasts.R b/tests/testthat/test-check_forecasts.R index 004031d71..447596768 100644 --- a/tests/testthat/test-check_forecasts.R +++ b/tests/testthat/test-check_forecasts.R @@ -96,7 +96,7 @@ test_that("as_forecast() function throws an error when no predictions or observe test_that("output of check_forecasts() is accepted as input to score()", { check <- suppressMessages(as_forecast(example_binary)) expect_no_error( - score_check <- score(check) + score_check <- score(na.omit(check)) ) expect_equal(score_check, suppressMessages(score(example_binary))) }) diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index 98d784cd4..d5f83aeb9 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -51,7 +51,7 @@ test_that("function set_forecast_unit() works", { example_quantile, c("location", "target_end_date", "target_type", "horizon", "model") ) - scores2 <- score(ex2) + scores2 <- score(na.omit(ex2)) scores2 <- scores2[order(location, target_end_date, target_type, horizon, model), ] expect_equal(scores1$interval_score, scores2$interval_score) diff --git a/tests/testthat/test-get_-functions.R b/tests/testthat/test-get_-functions.R index 4776fa711..f695bb936 100644 --- a/tests/testthat/test-get_-functions.R +++ b/tests/testthat/test-get_-functions.R @@ -14,7 +14,7 @@ test_that("get_forecast_unit() works as expected", { "forecast_date", "model", "horizon") ) - data <- as_forecast(example_quantile) + data <- as_forecast(na.omit(example_quantile)) ex <- data[, location := NULL] expect_warning( get_forecast_unit(ex, check_conflict = TRUE), @@ -40,7 +40,7 @@ test_that("removing NA rows from data works as expected", { expect_equal(nrow(na.omit(ex)), 2) # test that attributes and classes are retained - ex <- as_forecast(example_integer) + ex <- as_forecast(na.omit(example_integer)) expect_equal( class(na.omit(ex)), c("forecast_sample", "data.table", "data.frame") @@ -193,7 +193,7 @@ test_that("get_forecast_type() works as expected", { fixed = TRUE ) - data <- as_forecast(example_integer) + data <- as_forecast(na.omit(example_integer)) attr(data, "forecast_type") <- "binary" expect_warning( get_forecast_type(data), diff --git a/tests/testthat/test-plot_ranges.R b/tests/testthat/test-plot_ranges.R index 9a18cffe3..36c2ea41c 100644 --- a/tests/testthat/test-plot_ranges.R +++ b/tests/testthat/test-plot_ranges.R @@ -1,6 +1,7 @@ m <- modifyList(metrics_no_cov_no_ae, list("bias" = NULL)) sum_scores <- copy(example_quantile) %>% + na.omit() %>% .[, interval_range := scoringutils:::get_range_from_quantile(quantile)] %>% score(metrics = m) %>% summarise_scores(by = c("model", "target_type", "interval_range"))