Skip to content

Commit 1c564ff

Browse files
committed
improve tests and error message
1 parent 1d5f5f5 commit 1c564ff

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ importFrom(cli,cli_inform)
146146
importFrom(cli,cli_text)
147147
importFrom(cli,cli_warn)
148148
importFrom(cli,col_blue)
149+
importFrom(cli,qty)
149150
importFrom(data.table,"%like%")
150151
importFrom(data.table,':=')
151152
importFrom(data.table,.I)

R/class-forecast-sample-multivariate.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ define_grouping_cols <- function(data, across) {
8282

8383
#' @export
8484
#' @rdname assert_forecast
85+
#' @importFrom cli cli_abort qty
8586
#' @keywords validate-forecast-object
8687
assert_forecast.forecast_sample_multivariate <- function(
8788
forecast, forecast_type = NULL, verbose = TRUE, ...
@@ -105,8 +106,9 @@ assert_forecast.forecast_sample_multivariate <- function(
105106
# nolint start: object_usage_linter
106107
problematic_groups <- group_variations[.scoringutils_N > 1, .scoringutils_group_id]
107108
cli_abort(
108-
"Found groups with inconsistent sample lengths.
109-
Groups {.val {problematic_groups}} have different numbers of samples."
109+
"Found the following {qty(length(problematic_groups))} group{?s} with an
110+
inconsistent sample length, compared to other groups:
111+
{.val {problematic_groups}}"
110112
)
111113
# nolint end
112114
}

tests/testthat/test-class-forecast-sample-multivariate.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,16 @@ test_that("as_forecast_sample_multivariate() handles errors appropriately", {
158158
"All forecasts \\(as defined by the forecast unit\\) in a group must have the same number of samples"
159159
)
160160

161-
# Test with invalid grouping columns
161+
# Test with inconsistent sample lengths after forecast object creation
162+
expect_warning(
163+
example_sample_multivariate[-(1000:1010), ],
164+
"Found the following group with an inconsistent sample length"
165+
)
166+
167+
# Test with invalid grouping columns
162168
expect_error(
163169
as_forecast_sample_multivariate(data,
164170
grouping = c("nonexistent_column")),
165171
"Must be a subset of"
166172
)
167173
})
168-

0 commit comments

Comments
 (0)