39c768bfd31d09df939b4e9e6d8709f0005a7022
[talweg.git] / pkg / tests / testthat / helper.R
1 #shorthand: map 1->1, 2->2, 3->3, 4->1, ..., 149->2, 150->3
2 I = function(i)
3 (i-1) %% 3 + 1
4
5 #MOCK data; NOTE: could be in inst/testdata as well
6 getDataTest = function(n)
7 {
8 data = Data$new()
9 x = seq(0,9.5,0.1)
10 L = length(x) #96 1/4h
11 s1 = cos(x)
12 s2 = sin(x)
13 s3 = c( s1[1:(L%/%2)] , s2[(L%/%2+1):L] )
14 #sum((s1-s2)^2) == 96
15 #sum((s1-s3)^2) == 58
16 #sum((s2-s3)^2) == 38
17 s = list(s1, s2, s3)
18 series = list()
19 for (i in seq_len(n))
20 {
21 serie = s[[I(i)]] + rnorm(L,sd=0.01)
22 # 10 series with NAs for index 2
23 if (I(i) == 2 && i >= 60 && i<= 90)
24 serie[sample(seq_len(L),1)] = NA
25 time = as.POSIXct((i-1)*60*60*24+15*60*(1:96), origin="2007-01-01", tz="GMT")
26 exo = runif(4)
27 exo_hat = runif(4)
28 data$append(time=time, value=serie, level_hat=cumsum(serie),
29 exo=exo, exo_hat=exo_hat)
30 }
31 data
32 }