Skip to content

Commit

Permalink
update tests to avoid random messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse committed Jan 2, 2024
1 parent c1bdf4b commit 81a1506
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 33 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/testthat/test-add_coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-available_forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-check_forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-convenience-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-get_-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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")
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-plot_ranges.R
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down

0 comments on commit 81a1506

Please sign in to comment.