'update'
[talweg.git] / pkg / tests / testthat / test-computeFilaments.R
CommitLineData
3a38473a
BA
1context("computeFilaments")
2
3test_that("output is as expected on simulated series",
4{
5 data = getDataTest(150)
6
7 # index 144 : serie type 3, yersteday type 2
8 pred = computeForecast(data, 144, "Neighbors", "Zero", predict_from=1,
9 horizon=length(data$getSerie(1)), simtype="endo", local=FALSE, window=1, opera=TRUE)
10 f = computeFilaments(data, pred, 1, limit=60, plot=FALSE)
11
12 # Expected output: 50-3-10 series of type 2+1 = 3,
13 # then 23 series of type 3+1 %% 3 = 1 (3 = closest next)
14 expect_identical(length(f$neighb_indices), as.integer(60))
15 expect_identical(length(f$colors), as.integer(60))
16 expect_equal(f$index, 144)
17 expect_true(all(I(f$neighb_indices) != 2))
18 for (i in 1:37)
19 {
20 expect_equal(I(f$neighb_indices[i]), 3)
21 expect_match(f$colors[i], f$colors[1])
22 }
23 for (i in 38:60)
24 {
25 expect_equal(I(f$neighb_indices[i]), 1)
26 expect_match(f$colors[i], f$colors[38])
27 }
28 expect_match(f$colors[1], "#1*")
29 expect_match(f$colors[38], "#E*")
30
31 # index 143 : serie type 2
32 pred = computeForecast(data, 143, "Neighbors", "Zero", predict_from=1,
33 horizon=length(data$getSerie(1)), simtype="endo", local=FALSE, window=1, opera=TRUE)
34 f = computeFilaments(data, pred, 1, limit=50, plot=FALSE)
35
36 # Expected output: 50-10-3 series of type 1+1=2,
37 # then 13 series of type 3+1 %% 3 = 1 (closest next)
38 # NOTE: -10 because only past tomorrows with no-NAs yerstedays
39 # => exclude type 2 in [60,90[
40 expect_identical(length(f$neighb_indices), as.integer(50))
41 expect_identical(length(f$colors), as.integer(50))
42 expect_equal(f$index, 143)
43 expect_true(all(I(f$neighb_indices) <= 2))
44 for (i in 1:37)
45 {
46 expect_equal(I(f$neighb_indices[i]), 2)
47 expect_match(f$colors[i], f$colors[1])
48 }
49 for (i in 38:50)
50 {
51 expect_equal(I(f$neighb_indices[i]), 1)
52 expect_match(f$colors[i], f$colors[38])
53 }
54 expect_match(f$colors[1], "#1*")
55 expect_match(f$colors[38], "#E*")
56})