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