tests/testthat/test-is_sym_pos_def.R

# ---------------------------------------------------------------------------- #
test_that("is_sym_pos_def works for sym pos def matrix", {
  spd_mtx <- matrix(c(2.51, 2.01, 2.01, 1.74), 2, 2)
  expect_true(is_sym_pos_def(spd_mtx))

  spd_mtx <- matrix(c(6.62, 3.33, 1.94, 3.33, 3.52, 0.5, 1.94, 0.5, 1.95), 3, 3)
  expect_true(is_sym_pos_def(spd_mtx))

  spd_mtx <- matrix(c(6.62, -1.8, 1.94, -1.8, 3.52, 0.5, 1.94, 0.5, 1.95), 3, 3)
  expect_true(is_sym_pos_def(spd_mtx))
})

# ---------------------------------------------------------------------------- #
test_that("is_sym_pos_def works for non- sym pos def matrix", {
  non_spd_mtx <- matrix(
    c(6.62, 4.9, 1.94, 4.9, 3.52, 0.5, 1.94, 0.5, 1.95),
    3, 3
  )
  expect_false(is_sym_pos_def(non_spd_mtx))
})

# ---------------------------------------------------------------------------- #
test_that("is_sym_pos_def fails for non-matrix", {
  non_mtx <- c(1, 20, 20, 1)
  expect_jute_error(is_sym_pos_def(non_mtx))
})

# ---------------------------------------------------------------------------- #
test_that("is_sym_pos_def fails for non-numeric matrix", {
  non_sym <- matrix(c(1, 20, "20", 1), 2, 2)
  expect_jute_error(is_sym_pos_def(non_sym))
})

# ---------------------------------------------------------------------------- #
test_that("is_sym_pos_def fails with message for non-numeric matrix", {
  non_sym <- matrix(c(1, 20, "20", 1), 2, 2)
  expect_snapshot(is_sym_pos_def(non_sym), error = TRUE)
})

# ---------------------------------------------------------------------------- #
test_that("is_sym_pos_def fails for non-symmetric matrix", {
  non_sym <- matrix(c(-1.2, 2.45, 3.678, 154.8), 2, 2)
  expect_jute_error(is_sym_pos_def(non_sym))
})

# ---------------------------------------------------------------------------- #
test_that("is_sym_pos_def fails with message for non-symmetric matrix", {
  non_sym <- matrix(c(-1.2, 2.45, 3.678, 154.8), 2, 2)
  expect_snapshot(is_sym_pos_def(non_sym), error = TRUE)
})

# ---------------------------------------------------------------------------- #
toniprice/jute documentation built on Jan. 11, 2023, 8:23 a.m.