Skip to content

Commit 5b906b9

Browse files
committed
add test
1 parent 0e75964 commit 5b906b9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/testthat/test-stat-chain.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
test_that("stat_chain can chain multiple stats", {
2+
3+
df <- data.frame(x = c(1, 1.9, 2.1, 3, 3, 3))
4+
5+
p <- ggplot(df, aes(x)) +
6+
stat_chain(
7+
stats = "bin", stat.params = list(list(breaks = c(0.5:3.5)))
8+
) +
9+
stat_chain(
10+
stats = c("unique", "bin"),
11+
stat.params = list(NULL, list(breaks = 0.5:3.5))
12+
) +
13+
stat_chain(
14+
stats = c("unique", "bin"),
15+
stat.params = list(NULL, list(breaks = 0.5:3.5)),
16+
redirect = list(NULL, aes(y = -count))
17+
)
18+
p <- ggplot_build(p)
19+
20+
ld <- get_layer_data(p, 1L)
21+
expect_equal(ld$x, 1:3)
22+
expect_equal(ld$y, 1:3)
23+
24+
ld <- get_layer_data(p, 2L)
25+
expect_equal(ld$x, 1:3)
26+
expect_equal(ld$y, c(1, 2, 1))
27+
28+
ld <- get_layer_data(p, 3L)
29+
expect_equal(ld$x, 1:3)
30+
expect_equal(ld$y, c(-1, -2, -1))
31+
})

0 commit comments

Comments
 (0)