Debian Codegraph @

tests/testthat/test-list-svd.R

raw
1 skip_on_cran()
2
3 skip_if_not_installed("modeltests")
4 library(modeltests)
5
6 mat <- scale(as.matrix(USJudgeRatings))
7 s <- svd(mat)
8 p <- prcomp(mat)
9
10 test_that("tidy_svd", {
11 check_arguments(tidy_svd)
12
13 tdu <- tidy(s, matrix = "u")
14 tdd <- tidy(s, matrix = "d")
15 tdv <- tidy(s, matrix = "v")
16
17 check_tidy_output(tdu)
18 check_tidy_output(tdd)
19 check_tidy_output(tdv, strict = FALSE)
20
21 check_dims(tdu, 516, 3)
22 check_dims(tdd, 12, 4)
23 check_dims(tdv, 144, 3)
24 })
25
26 test_that("tidy_svd errors informatively", {
27 expect_snapshot(error = TRUE, tidy_svd(matrix = c("u", "v")))
28 })