1 context("Check that computeFilaments behaves as expected")
3 getDataTest = function(n, shift)
9 s3 = c( s1[1:(L%/%2)] , s2[(L%/%2+1):L] )
10 #sum((s1-s2)^2) == 97.59381
11 #sum((s1-s3)^2) == 57.03051
12 #sum((s2-s3)^2) == 40.5633
13 s = list( s1, s2, s3 )
18 level = mean(s[[index]])
19 serie = s[[index]] - level + rnorm(L,sd=0.05)
20 # 10 series with NAs for index 2
21 if (index == 2 && i >= 60 && i<= 90)
22 serie[sample(seq_len(L),1)] = NA
23 series[[i]] = list("level"=level,"serie"=serie) #no need for more
27 # Simulate shift at origin when predict_at > 0
28 series[2:(n+1)] = series[1:n]
29 series[[1]] = list("level"=0, "serie"=s[[1]][1:(L%/%2)])
31 new("Data", data=series)
34 test_that("output is as expected on simulated series",
36 data = getDataTest(150, FALSE)
38 # index 142 : serie type 2
39 f = computeFilaments(data, 142, limit=60, plot=FALSE)
40 # Expected output: 22 series of type 3 (closer), then 50-2-10 series of type 2
41 expect_identical(length(f$indices), 60)
42 expect_identical(length(f$colors), 60)
45 expect_identical((f$indices[i] %% 3) + 1, 3)
46 expect_match(f2$colors[i], f$colors[1])
50 expect_identical((f$indices[i] %% 3) + 1, 2)
51 expect_match(f2$colors[i], f$colors[23])
53 expect_match(colors[1], "...")
54 expect_match(colors[23], "...")
57 test_that("output is as expected on simulated series",
59 data = getDataTest(150, TRUE)
61 # index 143 : serie type 3
62 f = computeFilaments(data, 143, limit=70, plot=FALSE)
63 # Expected output: 22 series of type 2 (closer) then 50-2 series of type 3
64 expect_identical(length(f$indices), 70)
65 expect_identical(length(f$colors), 70)
68 # -1 because of the initial shift
69 expect_identical(( (f$indices[i]-1) %% 3 ) + 1, 2)
70 expect_match(f$colors[i], f$colors[1])
74 expect_identical(( (f$indices[i]-1) %% 3 ) + 1, 3)
75 expect_match(f$colors[i], f$colors[23])
77 expect_match(colors[1], "...")
78 expect_match(colors[23], "...")
81 test_that("output is as expected on simulated series",
83 data = getDataTest(150, TRUE)
85 # index 144 : serie type 1
86 f = computeFilaments(data, 144, limit=50, plot=FALSE)
87 # Expected output: 2 series of type 3 (closer), then 50-2 series of type 1
88 expect_identical(length(f$indices), 50)
89 expect_identical(length(f$colors), 50)
92 # -1 because of the initial shift
93 expect_identical(( (f$indices[i]-1) %% 3 ) + 1, 3)
94 expect_match(f$colors[i], f$colors[1])
98 expect_identical(( (f$indices[i]-1) %% 3 ) + 1, 1)
99 expect_match(f$colors[i], f$colors[3])
101 expect_match(colors[1], "...")
102 expect_match(colors[3], "...")