Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 4, 2024
1 parent 850d7dc commit 3978ee0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.21.7.3
Version: 0.21.7.4
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/_snaps/pca.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# print model_parameters pca

Code
print(principal_components(mtcars[, 1:4], n = "auto"))
Output
# Loadings from Principal Component Analysis (no rotation)
Variable | PC1 | Complexity
-----------------------------
mpg | -0.93 | 1.00
cyl | 0.96 | 1.00
disp | 0.95 | 1.00
hp | 0.91 | 1.00
The unique principal component accounted for 87.55% of the total variance of the original data.

---

Code
print(principal_components(mtcars[, 1:4], n = "auto"), labels = c(
"Miles/(US) gallon", "Number of cylinders", "Displacement (cu.in.)",
"Gross horsepower"))
Output
# Loadings from Principal Component Analysis (no rotation)
Variable | Label | PC1 | Complexity
-----------------------------------------------------
mpg | Miles/(US) gallon | -0.93 | 1.00
cyl | Number of cylinders | 0.96 | 1.00
disp | Displacement (cu.in.) | 0.95 | 1.00
hp | Gross horsepower | 0.91 | 1.00

17 changes: 17 additions & 0 deletions tests/testthat/test-pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ test_that("principal_components", {
})


# print ----

test_that("print model_parameters pca", {
data(mtcars)
expect_snapshot(print(principal_components(mtcars[, 1:4], n = "auto")))
expect_snapshot(print(
principal_components(mtcars[, 1:4], n = "auto"),
labels = c(
"Miles/(US) gallon",
"Number of cylinders",
"Displacement (cu.in.)",
"Gross horsepower"
)
))
})


# predict ----------------------
# N.B tests will fail if `GPArotation` package is not installed

Expand Down

0 comments on commit 3978ee0

Please sign in to comment.