tests/testthat/test-meanMat.R

test_that("meanMat works correctly", {
  s <- 3 # matrix dimension

  # generate lists of matrices
  x1 <- x2 <- replicate(5, matrix(runif(s^2), s, s), simplify = FALSE)
  x2[[1]][1, 1] <- NA

  y1 <- meanMat(x1)
  expect_true(inherits(y1, "matrix"))
  expect_identical(nrow(y1), as.integer(s))

  # na handling
  y2 <- meanMat(x2)
  expect_true(inherits(y2, "matrix"))
  expect_true(is.na(y2[1, 1]))

  y3 <- meanMat(x2, na.rm = TRUE)
  expect_false(is.na(y3[1, 1]))
})

test_that("meanMat warns and fails gracefully", {
  x3 <- list(matrix(0:3, nrow = 2), matrix(1:9, nrow = 3))
  expect_error(meanMat(x3))
})

Try the Rage package in your browser

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

Rage documentation built on Sept. 30, 2023, 1:06 a.m.