Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions tests/testthat/test-plot.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
get_labs <- function(x) x$labels
if ("get_labs" %in% getNamespaceExports("ggplot2")) {
get_labs <- ggplot2::get_labs
}

test_that("output of autoplot.apd_pca is correct when no options are provided", {
ad <- apd_pca(mtcars)
ad_plot <- ggplot2::autoplot(ad)
Expand All @@ -6,8 +11,9 @@ test_that("output of autoplot.apd_pca is correct when no options are provided",
tidyr::gather(component, value, -percentile)

expect_equal(ad_plot$data, pctls)
expect_equal(ad_plot$labels$x, "abs(value)")
expect_equal(ad_plot$labels$y, "percentile")
labs <- get_labs(ad_plot)
expect_equal(labs$x, "abs(value)")
expect_equal(labs$y, "percentile")
})

test_that("output of autoplot.apd_pca is correct when options=matches are provided", {
Expand All @@ -19,8 +25,9 @@ test_that("output of autoplot.apd_pca is correct when options=matches are provid
tidyr::gather(component, value, -percentile)

expect_equal(ad_plot$data, pctls)
expect_equal(ad_plot$labels$x, "abs(value)")
expect_equal(ad_plot$labels$y, "percentile")
labs <- get_labs(ad_plot)
expect_equal(labs$x, "abs(value)")
expect_equal(labs$y, "percentile")
})

test_that("output of autoplot.apd_pca is correct when options=distance are provided", {
Expand All @@ -32,6 +39,7 @@ test_that("output of autoplot.apd_pca is correct when options=distance are provi
tidyr::gather(component, value, -percentile)

expect_equal(ad_plot$data, pctls)
expect_equal(ad_plot$labels$x, "abs(value)")
expect_equal(ad_plot$labels$y, "percentile")
labs <- get_labs(ad_plot)
expect_equal(labs$x, "abs(value)")
expect_equal(labs$y, "percentile")
})