1 context("computeFilaments")
3 #shorthand: map 1->1, 2->2, 3->3, 4->1, ..., 149->2, 150->3
7 #MOCK data; NOTE: could be in inst/testdata as well
8 getDataTest = function(n)
12 L = length(x) #96 1/4h
15 s3 = c( s1[1:(L%/%2)] , s2[(L%/%2+1):L] )
23 serie = s[[I(i)]] + rnorm(L,sd=0.01)
26 # 10 series with NAs for index 2
27 if (I(i) == 2 && i >= 60 && i<= 90)
28 serie[sample(seq_len(L),1)] = NA
29 time = as.POSIXct(i*15*60, origin="2007-01-01", tz="GMT")
32 data$append(time, serie, level, exo, exo_hat)
37 test_that("output is as expected on simulated series",
39 data = getDataTest(150)
41 # index 143 : serie type 2
42 pred = computeForecast(data, 143, "Neighbors", "Zero",
43 horizon=length(data$getSerie(1)), simtype="endo", h_window=1)
44 f = computeFilaments(data, pred, 1, limit=60, plot=FALSE)
46 # Expected output: 50-3-10 series of type 2, then 23 series of type 3 (closest next)
47 expect_identical(length(f$neighb_indices), as.integer(60))
48 expect_identical(length(f$colors), as.integer(60))
49 expect_equal(f$index, 143)
50 expect_true(all(I(f$neighb_indices) >= 2))
53 expect_equal(I(f$neighb_indices[i]), 2)
54 expect_match(f$colors[i], f$colors[1])
58 expect_equal(I(f$neighb_indices[i]), 3)
59 expect_match(f$colors[i], f$colors[38])
61 expect_match(f$colors[1], "#1*")
62 expect_match(f$colors[38], "#E*")
64 # index 142 : serie type 1
65 pred = computeForecast(data, 142, "Neighbors", "Zero",
66 horizon=length(data$getSerie(1)), simtype="endo", h_window=1)
67 f = computeFilaments(data, pred, 1, limit=50, plot=FALSE)
69 # Expected output: 50-10-3 series of type 1, then 13 series of type 3 (closest next)
70 # NOTE: -10 because only past days with no-NAs tomorrow => exclude type 1 in [60,90[
71 expect_identical(length(f$neighb_indices), as.integer(50))
72 expect_identical(length(f$colors), as.integer(50))
73 expect_equal(f$index, 142)
74 expect_true(all(I(f$neighb_indices) != 2))
77 expect_equal(I(f$neighb_indices[i]), 1)
78 expect_match(f$colors[i], f$colors[1])
82 expect_equal(I(f$neighb_indices[i]), 3)
83 expect_match(f$colors[i], f$colors[38])
85 expect_match(f$colors[1], "#1*")
86 expect_match(f$colors[38], "#E*")