tests/testthat/test_is.invertible.R

#' ---
#' title: "Test: is.invertible"
#' author: "Ivan Jacob Agaloos Pesigan"
#' date: "`r Sys.Date()`"
#' output: rmarkdown::html_vignette
#' vignette: >
#'   %\VignetteIndexEntry{Test: is.invertible}
#'   %\VignetteEngine{knitr::rmarkdown}
#'   %\VignetteEncoding{UTF-8}
#' ---
#'
#+ knitr_options, include=FALSE, cache=FALSE
knitr::opts_chunk$set(
  error = TRUE,
  collapse = TRUE,
  comment = "#>",
  out.width = "100%"
)
#'
#+ setup
library(testthat)
library(jeksterslabRmatrix)
context("Test is.invertible.")
#'
#' ## Parameters
#'
#+ parameters
matrix.T <- diag(2)
matrix.F <- matrix(
  data = 1,
  nrow = 2,
  ncol = 2
)
colnames(matrix.T) <- paste0("col", 1:ncol(matrix.T))
rownames(matrix.T) <- paste0("row", 1:nrow(matrix.T))
colnames(matrix.F) <- paste0("col", 1:ncol(matrix.F))
rownames(matrix.F) <- paste0("row", 1:nrow(matrix.F))
knitr::kable(
  x = matrix.T,
  row.names = TRUE,
  caption = "Invertible Matrix"
)
knitr::kable(
  x = matrix.F,
  row.names = TRUE,
  caption = "Non-Invertible Matrix"
)
#'
#' ## Results
#'
#+ results
knitr::kable(
  x = data.frame(
    Item = c(
      "Invertible Matrix",
      "Non-Invertible Matrix"
    ),
    Parameter = c(
      "TRUE",
      "FALSE"
    ),
    Results = c(
      is.invertible(matrix.T),
      is.invertible(matrix.F)
    )
  ),
  row.names = FALSE
)
#'
#' ## testthat
#'
#+ testthat_01, echo=TRUE
test_that("is.invertible is TRUE", {
  expect_true(
    is.invertible(matrix.T)
  )
})
#'
#+ testthat_02, echo=TRUE
test_that("is.invertible is FALSE", {
  expect_false(
    is.invertible(matrix.F)
  )
})
#'
#+ testthat_03, echo=TRUE
test_that("is.invertible is FALSE (expect_error)", {
  expect_error(
    is.invertible(matrix.F, stop = TRUE)
  )
})
jeksterslabds/jeksterslabRmatrix documentation built on Aug. 4, 2020, 5:18 a.m.