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