Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests for warnings when using stat_bin with y values

  • Loading branch information...
commit 4618f71d03b2a5686764e9876e1c2f600867170e 1 parent 3e4c02c
@wch wch authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 inst/tests/test-stats.r
View
22 inst/tests/test-stats.r
@@ -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", {
Please sign in to comment.
Something went wrong with that request. Please try again.