Skip to content

Commit

Permalink
added unit tests to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCowgill committed Jul 28, 2019
1 parent 81e6d18 commit c26341e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/testthat/test-theme_grattan.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,28 @@ test_that("grattan colour functions work as expected", {

expect_length(grattan_pal(), 5)

expect_length(grattan_pal(n = 1), 1)
expect_length(grattan_pal(n = 2), 2)

expect_length(grattan_pal(n = 3), 3)
expect_length(grattan_pal(n = 4), 4)
expect_length(grattan_pal(n = 5), 5)
expect_length(grattan_pal(n = 6), 6)
expect_length(suppressWarnings(grattan_pal(n = 7)), 7)
expect_length(suppressWarnings(grattan_pal(n = 8)), 8)
expect_length(suppressWarnings(grattan_pal(n = 9)), 9)
expect_length(suppressWarnings(grattan_pal(n = 10)), 10)
expect_length(grattan_pal(n = 3, reverse = TRUE), 3)

expect_warning(grattan_pal(n = 10))

expect_error(grattan_pal(n = 11))

plot_w_col <- base_plot +
expect_equal(grattan_pal(n = 5),
c(grattantheme::grattan_yellow, grattantheme::grattan_lightorange,
grattantheme::grattan_darkorange, grattantheme::grattan_red,
grattantheme::grattan_darkred))

plot_w_col <- base_plot +
geom_point(aes(col = factor(cyl))) +
grattan_colour_manual(n = 3)

Expand Down
41 changes: 41 additions & 0 deletions tests/testthat/test-wrap_labs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

base_plot <- ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point()

test_that("long title fails", {
p <- base_plot +
labs(title = "This is a really long title that should fail wrap_labs with an error because it flows onto more than two lines, so it should definitely fail blah blah blah")

expect_error(wrap_labs(p, type = "fullslide"))

p <- base_plot +
labs(title = "Regular title",
subtitle = "Extremely long subtitle that should fail wrap_labs with an error, it'll take up too many lines even for a monster chart etc etc etc etc lorem ipsum lorem ipsum")

expect_error(wrap_labs(p, type = "fullslide"))

})


test_that("two line title wraps", {

p <- base_plot +
labs(title = "This is a slightly long title that should wrap onto two lines but work blah blah blah")

p <- wrap_labs(p, type = "fullslide")

expect_true(grepl("\n", p$labels$title))

})

test_that("caption wraps onto two lines", {

p <- base_plot +
labs(caption = "Notes: notes go here. Source: source goes here.")

p <- wrap_labs(p, type = "fullslide")

expect_true(grepl("\n", p$labels$caption))

})

0 comments on commit c26341e

Please sign in to comment.