diff --git a/tests/testthat/test-count-tally.R b/tests/testthat/test-count-tally.R index 2ec1fc62be..bf7ea0e6b3 100644 --- a/tests/testthat/test-count-tally.R +++ b/tests/testthat/test-count-tally.R @@ -1,5 +1,25 @@ # count ------------------------------------------------------------------- +test_that("count sorts output by keys by default", { + # Due to usage of `summarise()` internally + df <- tibble(x = c(2, 1, 1, 2, 1)) + out <- count(df, x) + expect_equal(out, tibble(x = c(1, 2), n = c(3, 2))) +}) + +test_that("count can sort output by `n`", { + df <- tibble(x = c(1, 1, 2, 2, 2)) + out <- count(df, x, sort = TRUE) + expect_equal(out, tibble(x = c(2, 1), n = c(3, 2))) +}) + +test_that("count can rename grouping columns", { + # But should it really allow this? + df <- tibble(x = c(2, 1, 1, 2, 1)) + out <- count(df, y = x) + expect_equal(out, tibble(y = c(1, 2), n = c(3, 2))) +}) + test_that("informs if n column already present, unless overridden", { df1 <- tibble(n = c(1, 1, 2, 2, 2)) expect_message(out <- count(df1, n), "already present")