Skip to content

Commit

Permalink
Merge pull request #12 from danielinteractive/test_stat_quadrant_counts
Browse files Browse the repository at this point in the history
Add test for `stat_quadrant_counts`
  • Loading branch information
aphalo authored Nov 22, 2022
2 parents 97f8bc4 + 3fdecfe commit 6ded04f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/testthat/test-stat_quadrant_counts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
context("stat_quadrant_counts")

library(ggplot2)

test_that("stat_quadrant_counts", {
df <- data.frame(
x = c(2.2, -0.2, -0.2, -2.5, -0.6, -0.1),
y = c(1.1, -0.6, -0.9, -1.6, 0.3, 1.6),
group = c("A", "A", "A", "B", "B", "B")
)
p <- ggplot(df, aes(x, y)) +
stat_quadrant_counts()
result <- layer_data(p)[, c("npcx", "npcy", "label")]
expected <- data.frame(
npcx = c(0.95, 0.05, 0.05, 0.95),
npcy = c(0.95, 0.05, 0.95, 0.05),
label = c("n=1", "n=3", "n=2", "n=0")
)
expect_identical(result, expected)
})

0 comments on commit 6ded04f

Please sign in to comment.