Debian Codegraph @

tests/testthat/helper-expectations.R

raw
1 # Simpler expectations for data frames.
2
3 expect_n_columns <- function(object, n) {
4 stopifnot(is.numeric(n), length(n) == 1)
5 act <- testthat::quasi_label(rlang::enquo(object))
6 act$n <- length(act$val)
7 testthat::expect(act$n == n, sprintf(
8 "%s has %i columns, not %i columns.",
9 act$lab, act$n, n
10 ))
11 invisible(act$val)
12 }
13
14 expect_n_rows <- function(object, n) {
15 stopifnot(is.numeric(n), length(n) == 1)
16 act <- testthat::quasi_label(rlang::enquo(object))
17 act$n <- nrow(act$val)
18 testthat::expect(
19 act$n == n,
20 sprintf("%s has %i rows, not %i rows", act$lab, act$n, n)
21 )
22 invisible(act$val)
23 }
24
25 expect_NA <- function(object) {
26 act <- testthat::quasi_label(rlang::enquo(object))
27 testthat::expect(is.na(act$val), sprintf("%s is not NA", act$lab))
28 invisible(act$val)
29 }