adapt Bruno method into package, add 'operational' mode
[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
638f27f4
BA
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)
d2ab47a7 10 f = computeFilaments(data, pred, 1, 8, limit=60, plot=FALSE)
98e958ca 11
638f27f4
BA
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)
98e958ca
BA
14 expect_identical(length(f$neighb_indices), as.integer(60))
15 expect_identical(length(f$colors), as.integer(60))
638f27f4
BA
16 expect_equal(f$index, 144)
17 expect_true(all(I(f$neighb_indices) != 2))
98e958ca 18 for (i in 1:37)
6d97bfec 19 {
638f27f4 20 expect_equal(I(f$neighb_indices[i]), 3)
44a9990b 21 expect_match(f$colors[i], f$colors[1])
6d97bfec 22 }
98e958ca 23 for (i in 38:60)
6d97bfec 24 {
638f27f4 25 expect_equal(I(f$neighb_indices[i]), 1)
98e958ca 26 expect_match(f$colors[i], f$colors[38])
6d97bfec 27 }
98e958ca
BA
28 expect_match(f$colors[1], "#1*")
29 expect_match(f$colors[38], "#E*")
6d97bfec 30
638f27f4
BA
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)
d2ab47a7 34 f = computeFilaments(data, pred, 1, 8, limit=50, plot=FALSE)
98e958ca 35
638f27f4
BA
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[
98e958ca
BA
40 expect_identical(length(f$neighb_indices), as.integer(50))
41 expect_identical(length(f$colors), as.integer(50))
d2ab47a7 42 expect_equal(f$index, 143)
638f27f4 43 expect_true(all(I(f$neighb_indices) <= 2))
98e958ca 44 for (i in 1:37)
6d97bfec 45 {
638f27f4 46 expect_equal(I(f$neighb_indices[i]), 2)
6d97bfec
BA
47 expect_match(f$colors[i], f$colors[1])
48 }
98e958ca 49 for (i in 38:50)
6d97bfec 50 {
638f27f4 51 expect_equal(I(f$neighb_indices[i]), 1)
98e958ca 52 expect_match(f$colors[i], f$colors[38])
6d97bfec 53 }
98e958ca
BA
54 expect_match(f$colors[1], "#1*")
55 expect_match(f$colors[38], "#E*")
1e20780e 56})