X-Git-Url: https://git.auder.net/?p=epclust.git;a=blobdiff_plain;f=epclust%2Ftests%2Ftestthat%2Ftest-filterMA.R;h=19ec6fca70de132a305ecd69728f82f4c58910de;hp=8dda50e98ef9a79c93c26d9187bce64e3b41ce95;hb=282342bafdc9ff65c5df98c6e2304d63b33b9fb2;hpb=3c5a4b0880db63367a474a568e1322b3999932fe diff --git a/epclust/tests/testthat/test-filterMA.R b/epclust/tests/testthat/test-filterMA.R index 8dda50e..19ec6fc 100644 --- a/epclust/tests/testthat/test-filterMA.R +++ b/epclust/tests/testthat/test-filterMA.R @@ -2,16 +2,30 @@ context("filterMA") test_that("[time-]serie filtering behave as expected", { - # Currently just a mean of 3 values - M = matrix(runif(1000,min=-7,max=7), ncol=10) - ref_fM = stats::filter(M, c(1/3,1/3,1/3), circular=FALSE) - fM = epclust:::filterMA(M) + # Mean of 3 values + M <- matrix(runif(1000,min=-7,max=7), ncol=10) + ref_fM <- stats::filter(M, rep(1/3,3), circular=FALSE) + fM <- epclust:::filterMA(M, 3) # Expect an agreement on all inner values expect_equal(dim(fM), c(100,10)) expect_equal(fM[2:99,], ref_fM[2:99,]) - # Border values should be unchanged - expect_equal(fM[1,], M[1,]) - expect_equal(fM[100,], M[100,]) + # Border values should be averages of 2 values + expect_equal(fM[1,], colMeans(M[1:2,])) + expect_equal(fM[100,], colMeans(M[99:100,])) + + # Mean of 5 values + ref_fM <- stats::filter(M, rep(1/5,5), circular=FALSE) + fM <- epclust:::filterMA(M, 5) + + # Expect an agreement on all inner values + expect_equal(dim(fM), c(100,10)) + expect_equal(fM[3:98,], ref_fM[3:98,]) + + # Border values should be averages of 3 or 4 values + expect_equal(fM[1,], colMeans(M[1:3,])) + expect_equal(fM[2,], colMeans(M[1:4,])) + expect_equal(fM[99,], colMeans(M[97:100,])) + expect_equal(fM[100,], colMeans(M[98:100,])) })