tests/testthat/test_focal_functions.R

context("c++ focal functions")

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#### Testing the focal euclidean function on a matrix
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

test_that("Testing the focal euclidean function on a matrix",{
  mat <- rbind(
    c(1,2,3),
    c(1,2,3),
    c(1,2,3)
  )

  W <- matrix(1,nrow = 3, ncol = 3)

  expected <- rbind(
    c(2,4,2),
    c(3,6,3),
    c(2,4,2)
  )

  obtained <-focal_euclidean_mat_window(mat, W)

  expect_equal(sum(abs(expected - obtained)),0)
})


test_that("Testing the focal euclidean function on a list of matrices",{
  mat <- rbind(
    c(1,2,3),
    c(1,2,3),
    c(1,2,3)
  )

  W <- matrix(1,nrow = 3, ncol = 3)

  list_mat <- list(mat,mat,mat)

  expected <- rbind(
    c(2,4,2),
    c(3,6,3),
    c(2,4,2)
  )

  expected <- expected*3

  obtained <-focal_euclidean_list(list_mat, W)

  expect_equal(sum(abs(expected - obtained)),0)

})

Try the geocmeans package in your browser

Any scripts or data that you put into this service are public.

geocmeans documentation built on Sept. 12, 2023, 9:06 a.m.