Skip to content

Commit

Permalink
Harmonize hubverse score tests with move of scoring functionality to …
Browse files Browse the repository at this point in the history
…forecasttools
  • Loading branch information
dylanhmorris committed Jan 4, 2025
1 parent 52c93e4 commit 08d898b
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions hewr/tests/testthat/test_hubverse_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ testthat::test_that("score_hubverse works as expected with valid inputs", {
length(date_range) * length(locations)
)

scored <- score_hewr(forecast, observed)
expect_setequal(forecast$location, scored$location)
expect_setequal(scored$horizon, c(0, 1))
scored <- forecasttools::quantile_table_to_scorable(
forecast,
observed,
obs_date_column = "reference_date"
) |>
score_hewr()

scored_all_horizon <- score_hewr(
forecast, observed,
horizons = c(0, 1, 2)
)
expect_setequal(forecast$location, scored_all_horizon$location)
expect_setequal(forecast$horizon, scored_all_horizon$horizon)
expect_setequal(forecast$location, scored$location)
expect_setequal(forecast$horizon, scored$horizon)
})


Expand All @@ -68,13 +67,18 @@ testthat::test_that("score_hubverse handles missing location data", {
locations = c("loc1")
)

result <- score_hewr(forecast, observed)
result <- forecasttools::quantile_table_to_scorable(
forecast,
observed,
obs_date_column = "reference_date"
) |>
score_hewr()
expect_false("loc2" %in% result$location)
expect_setequal(observed$location, result$location)
})


testthat::test_that("score_hubverse handles zero length forecast table", {
testthat::test_that("score_hewr handles zero length forecast table", {
forecast <- tibble::tibble(
reference_date = as.Date(character(0)),
horizon = integer(0),
Expand All @@ -95,7 +99,15 @@ testthat::test_that("score_hubverse handles zero length forecast table", {
)

expect_error(
result <- score_hewr(forecast, observed),
"Assertion on 'data' failed: Must have at least 1 rows, but has 0 rows."
forecasttools::quantile_table_to_scorable(
forecast,
observed,
obs_date_column = "reference_date"
) |>
score_hewr(),
paste0(
"Assertion on 'data' failed: ",
"Must have at least 1 rows, but has 0 rows."
)
)
})

0 comments on commit 08d898b

Please sign in to comment.