Skip to content

Commit

Permalink
Refactoring tests slightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlandis committed Feb 29, 2024
1 parent 56e16af commit bac015f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
35 changes: 26 additions & 9 deletions tests/testthat/test_continuous_date_axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,36 @@ test_that("default ggplot2 error",{
expect_error(ggplot_build(p), regexp = "works with objects of class <Date> only")
})

p <- ggplot(df, aes(x = date, y = temperature)) +
geom_line() +
geom_point(aes(color = month_name))
p_yside <- p + geom_ysidehistogram(bins = 30)

test_that("ggside work-around works",{
p <- ggplot(df, aes(x = date, y = temperature)) +
geom_line() +
geom_point(aes(color = month_name))
p_yside <- p + geom_ysidehistogram(bins = 30)
expect_doppelganger("date_x_yside_no_scale", p_yside)
p_yside <- p_yside + scale_ysidex_continuous()
})

p_yside <- p_yside + scale_ysidex_continuous()

test_that("ggside adding ysidex continuous scale", {
expect_doppelganger("date_x_yside", p_yside)
p_xside <- p + geom_xsidehistogram(bins = 30) + scale_xsidey_continuous(trans = "sqrt", breaks = c(0,5,10,20))
})

p_xside <- p + geom_xsidehistogram(bins = 30) + scale_xsidey_continuous(trans = "sqrt", breaks = c(0,5,10,20))

test_that("ggside xsidey scales", {
expect_doppelganger("date_x_xside", p_xside)
p_both <- p_yside + geom_xsidehistogram(bins = 30)
})

p_both <- p_yside + geom_xsidehistogram(bins = 30)

test_that("ggside xsidey and ysidex scales", {
expect_doppelganger("date_x_both", p_both)
p_wrap <- p_both + facet_wrap(~month) + ggside(collapse = "all")
expect_message(p_wrap, regexp = NA)
})

p_wrap <- p_both + facet_wrap(~month) + ggside(collapse = "all")


test_that("ggside xsidey and ysidex no message", {
expect_no_message(p_wrap)
})
30 changes: 20 additions & 10 deletions tests/testthat/test_ggside_scales.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,35 @@ expect_ggproto_id <- function(object, expected) {

}

test_that("xsidey and ysidex appear",{
p <- ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point(size = 2) +
geom_xsidedensity(aes(y = after_stat(density)), position = "stack") +
geom_ysidedensity(aes(x = after_stat(density)), position = "stack") +
theme(axis.text.x = element_text(angle = 90, vjust = .5))
p <- ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point(size = 2) +
geom_xsidedensity(aes(y = after_stat(density)), position = "stack") +
geom_ysidedensity(aes(x = after_stat(density)), position = "stack") +
theme(axis.text.x = element_text(angle = 90, vjust = .5))

test_that("xsidey and ysidex are null", {
expect_null(p$ggside$xsidey)
expect_null(p$ggside$ysidex)
})

test_that("xsidey and ysidex appear",{

xsidey_scale <- scale_xsidey_continuous(breaks = c(0,1,2))
p <- p + xsidey_scale
p2 <- p + xsidey_scale

expect_ggproto_id(p$ggside$xsidey, xsidey_scale)
expect_ggproto_id(p2$ggside$xsidey, xsidey_scale)

ysidex_scale <- scale_ysidex_continuous(breaks = NULL, labels = NULL)
p <- p + ysidex_scale
p2 <- p + ysidex_scale

expect_ggproto_id(p2$ggside$ysidex, ysidex_scale)
})

test_that("xsidey and ysidex plot", {

expect_ggproto_id(p$ggside$ysidex, ysidex_scale)
p <- p +
scale_xsidey_continuous(breaks = c(0,1,2)) +
scale_ysidex_continuous(breaks = NULL, labels = NULL)

expect_doppelganger("xsidey-ysidex-FacetNull", p)

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_ops_meaningful.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ p <- mtcars |>



testthat::test_that("non-mapping parameter works (alpha)", {
test_that("non-mapping parameter works (alpha)", {
.addSide <- function(p, my_alpha) {
p + geom_ysideboxplot(
aes(x = cyl, y = hp, fill = cyl), orientation = "x",
alpha = my_alpha
)
}
vdiffr::expect_doppelganger("alpha-0.5", p + geom_ysideboxplot(
expect_doppelganger("alpha-0.5", p + geom_ysideboxplot(
aes(x = cyl, y = hp, fill = cyl), orientation = "x",
alpha = 0.5
))
vdiffr::expect_doppelganger("alpha-0.5-from-function", .addSide(p, 0.5))
expect_doppelganger("alpha-0.5-from-function", .addSide(p, 0.5))
})


testthat::test_that("No Ops meaningful warning", {
test_that("No Ops meaningful warning", {

p2 <- p + geom_ysideboxplot(
aes(x = cyl, y = hp, fill = cyl), orientation = "x"
Expand Down

0 comments on commit bac015f

Please sign in to comment.