File: test-verb-head.R

package info (click to toggle)
r-cran-dbplyr 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,376 kB
  • sloc: sh: 13; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 936 bytes parent folder | download | duplicates (2)
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("head limits rows", {
  db <- head(memdb_frame(x = 1:100), 10)

  expect_equal(sql_build(db)$limit, 10)
  expect_equal(nrow(collect(db)), 10)
})

test_that("two heads are equivalent to one", {
  out <- lazy_frame(x = 1:10) %>% head(3) %>% head(5)
  expect_equal(out$lazy_query$limit, 3)
})

test_that("non-integer automatically truncated", {
  out <- lazy_frame(x = 1:10) %>% head(3.5)
  expect_equal(out$lazy_query$limit, 3)
})

test_that("can get 0 rows", {
  db <- memdb_frame(x = 1)
  out <- collect(head(db, 0))
  expect_equal(out, tibble(x = double()))
})

test_that("n must be valid", {
  db <- memdb_frame(x = 1)

  expect_error(head(db, "x"), "non-negative integer")
  expect_error(head(db, 1:2), "non-negative integer")
  expect_error(head(db, -1), "non-negative integer")
  expect_error(head(db, Inf), NA)
})

test_that("tail not supported", {
  lf <- lazy_frame(x = 1)
  expect_error(tail(lf), "not supported")
})