File: test-verb-window.R

package info (click to toggle)
r-cran-dbplyr 2.5.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,644 kB
  • sloc: sh: 13; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
test_that("window_order errors for data frame", {
  expect_snapshot({
    (expect_error(window_order(data.frame(x = 1))))
    (expect_error(window_order("a")))
  })
})

test_that("window_order only accepts variables", {
  lf <- lazy_frame(x = 1, y = 1)
  expect_equal(window_order(lf, x, y) %>% op_sort(), unname(exprs(x, y)))
  expect_equal(window_order(lf, x, desc(y)) %>% op_sort(), unname(exprs(x, desc(y))))

  expect_snapshot({
    (expect_error(window_order(lf, x + y)))
  })
})

test_that("window order works afer renaming variable", {
  expect_snapshot({
    lazy_frame(x = 1, y = 1) %>%
      window_order(y) %>%
      rename(y2 = y) %>%
      mutate(x_cum = cumsum(x))

    lazy_frame(x = 1, y = 1) %>%
      rename(y2 = y) %>%
      window_order(y2) %>%
      mutate(x_cum = cumsum(x))
  })
})

test_that("window_frame errors for data frame", {
  expect_snapshot({
    (expect_error(window_frame(data.frame(x = 1))))
  })
})