From 5a0597231aabbfcb408e6fecfd7430849d68adea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wo=C5=BAniak?= Date: Sun, 12 May 2024 20:31:52 +1000 Subject: [PATCH] forecast method test closes #5 --- inst/tinytest/test_forecast.R | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 inst/tinytest/test_forecast.R diff --git a/inst/tinytest/test_forecast.R b/inst/tinytest/test_forecast.R new file mode 100644 index 0000000..19f14bd --- /dev/null +++ b/inst/tinytest/test_forecast.R @@ -0,0 +1,40 @@ + +data(ilo_cubic_panel) + +# for bsvar +set.seed(1) +suppressMessages( + specification_no1 <- specify_bvarPANEL$new(ilo_cubic_panel) +) +run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) +ff <- forecast(run_no1, horizon = 2) + +set.seed(1) +suppressMessages( + ff2 <- ilo_cubic_panel |> + specify_bvarPANEL$new() |> + estimate(S = 3, thin = 1, show_progress = FALSE) |> + forecast(horizon = 2) +) + + +expect_identical( + ff$forecasts[1,1,1,1], ff2$forecasts[1,1,1,1], + info = "forecast: forecast identical for normal and pipe workflow." +) + +expect_true( + is.numeric(ff$forecasts) & is.array(ff$forecasts), + info = "forecast: returns numeric array." +) + + +expect_error( + specify_bvarPANEL$new(ilo_cubic_panel) |> forecast(horizon = 3), + info = "forecast: wrong input provided." +) + +expect_error( + forecast(run_no1, horizon = 1.5), + info = "forecast: specify horizon as integer." +)