tests/testthat/test_tr.R

context("tr() function: The trace function works ")

test_that("Tr of 3 x 3 Identity or Constant matrix is 3", {
  expect_equal(tr(I(3)), 3)
  expect_equal(tr(J(3)), 3)
})

test_that("Cannot take trace of not square matrix", {
  A <- matrix(seq(1, 6, 1), nrow = 3, ncol = 2, byrow = TRUE)
  expect_error(tr(A), "A is not a square matrix")
})

# test_that( 'Test that is not numeric', {
#  B <- matrix( letters[1:6], nrow = 3)
#  expect_error( tr(B), "A must be a numeric matrix.")
# })

Try the matrixNormal package in your browser

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

matrixNormal documentation built on Sept. 16, 2022, 5:07 p.m.