diff --git a/NEWS.md b/NEWS.md index 5b8780a7f..cc84f1cfb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -38,6 +38,7 @@ The update introduces breaking changes. If you want to keep using the older vers - Files ending in ".Rda" were renamed to ".rds" where appropriate when used together with `saveRDS()` or `readRDS()`. - `score()` now calls `na.omit()` on the data, instead of only removing rows with missing values in the columns `observed` and `predicted`. This is because `NA` values in other columns can also mess up e.g. grouping of forecasts according to the unit of a single forecast. - added documentation for the return value of `summarise_scores()`. +- Added unit tests for `interval_coverage_quantile()` and `interval_coverage_dev_quantile()` in order to make sure that the functions provide the correct warnings when insufficient quantiles are provided. # scoringutils 1.2.2 diff --git a/tests/testthat/test-metrics-quantile.R b/tests/testthat/test-metrics-quantile.R index b941a95aa..a6faf051c 100644 --- a/tests/testthat/test-metrics-quantile.R +++ b/tests/testthat/test-metrics-quantile.R @@ -601,6 +601,17 @@ test_that("interval_coverage_quantile rejects wrong inputs", { ) }) +test_that("interval_coverage_quantile throws a warning when a required quantile is not available", { + dropped_quantile_pred <- predicted[, -4] + dropped_quantiles <- quantile[-4] + expect_warning( + interval_coverage_quantile( + observed, dropped_quantile_pred, dropped_quantiles, range = 50 + ), + "To compute the interval coverage for a range of 50%, the quantiles `0.25, 0.75` are required. Returning `NA`" + ) +}) + # ============================================================================ # # `interval_coverage_dev_quantile` ===================================== # @@ -617,6 +628,12 @@ test_that("interval_coverage_dev_quantile works", { interval_coverage_dev_quantile(observed, predicted, quantile), manual ) + expect_warning( + interval_coverage_dev_quantile( + observed, predicted, c(quantile[-4], 0.76) + ), + "To compute inteval coverage deviation, all quantiles must form central symmetric prediction intervals. Missing quantiles: 0.24, 0.75. Returning `NA`." + ) })