drop enercast submodule; drop Rcpp requirement; fix doc, complete code, fix fix fix
[epclust.git] / epclust / tests / testthat / test-filterMA.R
CommitLineData
a52836b2 1context("filterMA")
6ad3f3fd 2
0486fbad
BA
3test_that("[time-]serie filtering behave as expected",
4{
282342ba
BA
5 # Mean of 3 values
6 M <- matrix(runif(1000,min=-7,max=7), ncol=10)
7 ref_fM <- stats::filter(M, rep(1/3,3), circular=FALSE)
8 fM <- epclust:::filterMA(M, 3)
0486fbad 9
a52836b2 10 # Expect an agreement on all inner values
0486fbad 11 expect_equal(dim(fM), c(100,10))
0fe757f7 12 expect_equal(fM[2:99,], ref_fM[2:99,])
0486fbad 13
282342ba
BA
14 # Border values should be averages of 2 values
15 expect_equal(fM[1,], colMeans(M[1:2,]))
16 expect_equal(fM[100,], colMeans(M[99:100,]))
17
18 # Mean of 5 values
19 ref_fM <- stats::filter(M, rep(1/5,5), circular=FALSE)
20 fM <- epclust:::filterMA(M, 5)
21
22 # Expect an agreement on all inner values
23 expect_equal(dim(fM), c(100,10))
24 expect_equal(fM[3:98,], ref_fM[3:98,])
25
26 # Border values should be averages of 3 or 4 values
27 expect_equal(fM[1,], colMeans(M[1:3,]))
28 expect_equal(fM[2,], colMeans(M[1:4,]))
29 expect_equal(fM[99,], colMeans(M[97:100,]))
30 expect_equal(fM[100,], colMeans(M[98:100,]))
0fe757f7 31})