From 4618f71d03b2a5686764e9876e1c2f600867170e Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Sat, 25 Aug 2012 23:11:17 -0700 Subject: [PATCH] Add tests for warnings when using stat_bin with y values --- inst/tests/test-stats.r | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/inst/tests/test-stats.r b/inst/tests/test-stats.r index 6cf95ffd69..0da33ee4c2 100644 --- a/inst/tests/test-stats.r +++ b/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", {