Skip to content

Commit f06fdac

Browse files
committed
Add test
1 parent 99e2f87 commit f06fdac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/testthat/test-stat-ydensity.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,25 @@ test_that("calc_bw() requires at least two values and correct method", {
33
expect_silent(calc_bw(1:5, "nrd0"))
44
expect_snapshot_error(calc_bw(1:5, "test"))
55
})
6+
7+
test_that("`drop = FALSE` preserves groups with 1 observations", {
8+
df <- head(data_frame0(
9+
x = factor(rep(1:2, each = 4)),
10+
y = rep(1:2, 4),
11+
g = rep(c("A", "A", "B", 'B'), 2)
12+
), -1)
13+
14+
p <- ggplot(df, mapping = aes(x, y, fill = g))
15+
16+
expect_warning(
17+
ld <- layer_data(p + geom_violin(drop = TRUE)),
18+
"Groups with fewer than two datapoints have been dropped"
19+
)
20+
expect_equal(length(unique(ld$x)), 3)
21+
22+
expect_warning(
23+
ld <- layer_data(p + geom_violin(drop = FALSE)),
24+
"Cannot compute density for groups with fewer than two datapoints"
25+
)
26+
expect_equal(length(unique(ld$x)), 4)
27+
})

0 commit comments

Comments
 (0)