tests/testthat/test-complete.R

test_that("with no variables returns data as tidytable", {
  expect_equal(complete(mtcars), as_tidytable(mtcars))
})

test_that("basic invocation works", {
  df <- tidytable(x = 1:2, y = 1:2, z = 3:4)
  out <- complete(df, x, y)
  expect_equal(nrow(out), 4)
  expect_equal(out$z, c(3, NA, NA, 4))
})

test_that("empty expansion returns original", {
  df <- tidytable(x = character())
  rs <- complete(df, y = NULL)
  expect_equal(rs, df)

  df <- tidytable(x = 1:4)
  rs <- complete(df, y = NULL)
  expect_equal(rs, df)
})

test_that("not drop unspecified levels in complete", {
  df <- tidytable(x = 1:3, y = 1:3, z = c("a", "b", "c"))
  df2 <- df %>% complete(z = c("a", "b"))
  expect <- df[, c("z", "x", "y")]
  expect_equal(df2, expect)
})

test_that("complete. works", {
  df <- tidytable(x = 1:2, y = 1:2, z = 3:4)
  out <- suppressWarnings(complete.(df, x, y))
  expect_equal(nrow(out), 4)
  expect_equal(out$z, c(3, NA, NA, 4))
})

Try the tidytable package in your browser

Any scripts or data that you put into this service are public.

tidytable documentation built on Oct. 5, 2023, 5:07 p.m.