Skip to content

Commit 4618f71

Browse files
committed
Add tests for warnings when using stat_bin with y values
1 parent 3e4c02c commit 4618f71

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

inst/tests/test-stats.r

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ test_stat <- function(stat) {
2323
stat$calc_statistic(dat, NULL)
2424
}
2525

26+
context("stat-bin")
27+
28+
test_that("stat_sum", {
29+
dat <- data.frame(x = c("a", "b", "c"), y = c(1, 5, 10))
30+
31+
# Should get a warning when mapping/setting y and also using stat_bin
32+
expect_warning(p <- ggplot_build(ggplot(dat, aes(x=x, y=y)) + geom_bar()),
33+
"Mapping a variable to y and also using stat=\"bin\"")
34+
expect_warning(p <- ggplot_build(ggplot(dat, aes(x=x, y=y)) + geom_bar(stat="bin")),
35+
"Mapping a variable to y and also using stat=\"bin\"")
36+
37+
expect_warning(p <- ggplot_build(ggplot(dat, aes(x=x)) + geom_bar(y=5)),
38+
"Mapping a variable to y and also using stat=\"bin\"")
39+
40+
# This gives an error and a warning (it would probably be OK if just one
41+
# of these happened, but this test looks for both)
42+
dat2 <- data.frame(x = c("a", "b", "c", "a", "b", "c"), y = c(1, 5, 10, 2, 3, 4))
43+
expect_warning(expect_error(
44+
p <- ggplot_build(ggplot(dat2, aes(x=x, y=y)) + geom_bar())))
45+
})
46+
47+
2648
context("stat-sum")
2749

2850
test_that("stat_sum", {

0 commit comments

Comments
 (0)