Skip to content

Commit

Permalink
Add tests for warnings when using stat_bin with y values
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Aug 26, 2012
1 parent 3e4c02c commit 4618f71
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions inst/tests/test-stats.r
Expand Up @@ -23,6 +23,28 @@ test_stat <- function(stat) {
stat$calc_statistic(dat, NULL)
}

context("stat-bin")

test_that("stat_sum", {
dat <- data.frame(x = c("a", "b", "c"), y = c(1, 5, 10))

# Should get a warning when mapping/setting y and also using stat_bin
expect_warning(p <- ggplot_build(ggplot(dat, aes(x=x, y=y)) + geom_bar()),
"Mapping a variable to y and also using stat=\"bin\"")
expect_warning(p <- ggplot_build(ggplot(dat, aes(x=x, y=y)) + geom_bar(stat="bin")),
"Mapping a variable to y and also using stat=\"bin\"")

expect_warning(p <- ggplot_build(ggplot(dat, aes(x=x)) + geom_bar(y=5)),
"Mapping a variable to y and also using stat=\"bin\"")

# This gives an error and a warning (it would probably be OK if just one
# of these happened, but this test looks for both)
dat2 <- data.frame(x = c("a", "b", "c", "a", "b", "c"), y = c(1, 5, 10, 2, 3, 4))
expect_warning(expect_error(
p <- ggplot_build(ggplot(dat2, aes(x=x, y=y)) + geom_bar())))
})


context("stat-sum")

test_that("stat_sum", {
Expand Down

0 comments on commit 4618f71

Please sign in to comment.