Skip to content

Commit a1b857d

Browse files
committed
add tests
1 parent 9b6b542 commit a1b857d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

R/utils_pca_efa.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ get_scores <- function(x, n_items = NULL, reverse_items = NULL, verbose = TRUE)
6363
reverse_items <- colnames(dataset)[reverse_items]
6464
}
6565
if (verbose) {
66-
insight::format_message("Reversing items: ", toString(reverse_items))
66+
insight::format_alert(paste("Reversing items:", toString(reverse_items)))
6767
}
6868
# reverse the items
6969
dataset <- datawizard::reverse_scale(dataset, reverse_items, verbose = verbose)

tests/testthat/test-get_scores.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ skip_on_cran()
22

33
test_that("get_scores", {
44
skip_if_not_installed("psych")
5+
data(mtcars)
56
pca <- principal_components(mtcars[, 1:7], n = 2, rotation = "varimax")
67
scores <- get_scores(pca)
78
expect_equal(head(scores$Component_1), c(38.704, 38.755, 28.194, 58.339, 78.658, 51.064), tolerance = 1e-2)
@@ -15,4 +16,13 @@ test_that("get_scores", {
1516
regex = "Following variable(s)",
1617
fixed = TRUE
1718
)
19+
20+
expect_message(
21+
get_scores(pca, reverse_items = c("cyl", "drat")),
22+
regex = "Reversing items: cyl, drat"
23+
fixed = TRUE
24+
)
25+
26+
expect_silent(get_scores(pca, reverse_items = c("cyl", "abc"), verbose = FALSE))
27+
expect_silent(get_scores(pca, reverse_items = c("cyl", "drat"), verbose = FALSE))
1828
})

0 commit comments

Comments
 (0)