revise package structure: always predict from 1am to horizon, dataset not cut at...
[talweg.git] / pkg / tests / testthat / test-computeFilaments.R
CommitLineData
3ddf1c12 1context("computeFilaments")
1e20780e 2
af3b84f4 3test_that("output is as expected on simulated series",
6d97bfec 4{
af3b84f4 5 data = getDataTest(150)
a65907cc 6
d2ab47a7
BA
7 # index 144-1 == 143 : serie type 2
8 pred = computeForecast(data, 144, "Neighbors", "Zero", predict_from=8,
c36568fa 9 horizon=length(data$getSerie(1)), simtype="endo", local=FALSE, h_window=1)
d2ab47a7 10 f = computeFilaments(data, pred, 1, 8, limit=60, plot=FALSE)
98e958ca
BA
11
12 # Expected output: 50-3-10 series of type 2, then 23 series of type 3 (closest next)
13 expect_identical(length(f$neighb_indices), as.integer(60))
14 expect_identical(length(f$colors), as.integer(60))
d2ab47a7 15 expect_equal(f$index, 144)
98e958ca
BA
16 expect_true(all(I(f$neighb_indices) >= 2))
17 for (i in 1:37)
6d97bfec 18 {
98e958ca 19 expect_equal(I(f$neighb_indices[i]), 2)
44a9990b 20 expect_match(f$colors[i], f$colors[1])
6d97bfec 21 }
98e958ca 22 for (i in 38:60)
6d97bfec 23 {
98e958ca
BA
24 expect_equal(I(f$neighb_indices[i]), 3)
25 expect_match(f$colors[i], f$colors[38])
6d97bfec 26 }
98e958ca
BA
27 expect_match(f$colors[1], "#1*")
28 expect_match(f$colors[38], "#E*")
6d97bfec 29
d2ab47a7
BA
30 # index 143-1 == 142 : serie type 1
31 pred = computeForecast(data, 143, "Neighbors", "Zero", predict_from=8,
c36568fa 32 horizon=length(data$getSerie(1)), simtype="endo", local=FALSE, h_window=1)
d2ab47a7 33 f = computeFilaments(data, pred, 1, 8, limit=50, plot=FALSE)
98e958ca
BA
34
35 # Expected output: 50-10-3 series of type 1, then 13 series of type 3 (closest next)
44a9990b 36 # NOTE: -10 because only past days with no-NAs tomorrow => exclude type 1 in [60,90[
98e958ca
BA
37 expect_identical(length(f$neighb_indices), as.integer(50))
38 expect_identical(length(f$colors), as.integer(50))
d2ab47a7 39 expect_equal(f$index, 143)
98e958ca
BA
40 expect_true(all(I(f$neighb_indices) != 2))
41 for (i in 1:37)
6d97bfec 42 {
98e958ca 43 expect_equal(I(f$neighb_indices[i]), 1)
6d97bfec
BA
44 expect_match(f$colors[i], f$colors[1])
45 }
98e958ca 46 for (i in 38:50)
6d97bfec 47 {
98e958ca
BA
48 expect_equal(I(f$neighb_indices[i]), 3)
49 expect_match(f$colors[i], f$colors[38])
6d97bfec 50 }
98e958ca
BA
51 expect_match(f$colors[1], "#1*")
52 expect_match(f$colors[38], "#E*")
1e20780e 53})