Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markfairbanks committed Oct 25, 2022
1 parent d7f7055 commit d0cba2d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/testthat/test-tidyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ test_that("n() is equivalent to .N", {
)
})

test_that("row_number() is equivalent .I", {
test_that("row_number() is equivalent seq_len(.N)", {
dt <- lazy_dt(data.frame(g = c(1, 1, 2), x = 1:3))

expect_equal(
Expand All @@ -286,6 +286,21 @@ test_that("row_number(x) is equivalent to rank", {
)
})

test_that("ranking functions are translated", {
df <- lazy_dt(tibble(x = c(1, 2, NA, 1, 0, NaN)))

res <- df %>%
mutate(percent_rank = percent_rank(x),
min_rank = min_rank(x),
dense_rank = dense_rank(x),
cume_dist = cume_dist(x))

expect_equal(pull(res, percent_rank), c(1 / 3, 1, NA, 1 / 3, 0, NA))
expect_equal(pull(res, min_rank), c(2L, 4L, NA, 2L, 1L, NA))
expect_equal(pull(res, dense_rank), c(2L, 3L, NA, 2L, 1L, NA))
expect_equal(pull(res, cume_dist), c(.75, 1, NA, .75, .25, NA))
})

test_that("scoped verbs produce nice output", {
dt <- lazy_dt(data.table(x = 1:5), "DT")

Expand Down

0 comments on commit d0cba2d

Please sign in to comment.