TDO debug 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
8
9
10 #TODO: debug
11
12
13
14 # index 144-1 == 143 : serie type 2
15 pred = computeForecast(data, 143, "Neighbors", "Zero", predict_from=8,
16 horizon=length(data$getSerie(1)), simtype="endo", local=FALSE, h_window=1)
17 f = computeFilaments(data, pred, 1, 8, limit=60, plot=FALSE)
18
19 # Expected output: 50-3-10 series of type 2, then 23 series of type 3 (closest next)
20 expect_identical(length(f$neighb_indices), as.integer(60))
21 expect_identical(length(f$colors), as.integer(60))
22 expect_equal(f$index, 143)
23 expect_true(all(I(f$neighb_indices) >= 2))
24 for (i in 1:37)
25 {
26 expect_equal(I(f$neighb_indices[i]), 2)
27 expect_match(f$colors[i], f$colors[1])
28 }
29 for (i in 38:60)
30 {
31 expect_equal(I(f$neighb_indices[i]), 3)
32 expect_match(f$colors[i], f$colors[38])
33 }
34 expect_match(f$colors[1], "#1*")
35 expect_match(f$colors[38], "#E*")
36
37 # index 143-1 == 142 : serie type 1
38 pred = computeForecast(data, 143, "Neighbors", "Zero", predict_from=8,
39 horizon=length(data$getSerie(1)), simtype="endo", local=FALSE, h_window=1)
40 f = computeFilaments(data, pred, 1, 8, limit=50, plot=FALSE)
41
42 # Expected output: 50-10-3 series of type 1, then 13 series of type 3 (closest next)
43 # NOTE: -10 because only past days with no-NAs tomorrow => exclude type 1 in [60,90[
44 expect_identical(length(f$neighb_indices), as.integer(50))
45 expect_identical(length(f$colors), as.integer(50))
46 expect_equal(f$index, 143)
47 expect_true(all(I(f$neighb_indices) != 2))
48 for (i in 1:37)
49 {
50 expect_equal(I(f$neighb_indices[i]), 1)
51 expect_match(f$colors[i], f$colors[1])
52 }
53 for (i in 38:50)
54 {
55 expect_equal(I(f$neighb_indices[i]), 3)
56 expect_match(f$colors[i], f$colors[38])
57 }
58 expect_match(f$colors[1], "#1*")
59 expect_match(f$colors[38], "#E*")
60 })