| 1 | context("filterMA") |
| 2 | |
| 3 | test_that("[time-]serie filtering behave as expected", |
| 4 | { |
| 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) |
| 9 | |
| 10 | # Expect an agreement on all inner values |
| 11 | expect_equal(dim(fM), c(100,10)) |
| 12 | expect_equal(fM[2:99,], ref_fM[2:99,]) |
| 13 | |
| 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,])) |
| 31 | }) |