tests/testthat/test-label-miss-2d.R

test_df <- data.frame(x = c(NA,2,3),
                      y = c(1,NA,3),
                      z = c(1,2,3))

test_that("label_miss_2d errors on the first NULL entry",{
  expect_error(label_miss_2d(NULL, 3))
})

test_that("label_miss_2d errors on the second NULL entry",{
  expect_error(label_miss_2d(3, NULL))
})

test_that("label_miss_2d errors when both are NULL",{
  expect_error(label_miss_2d(NULL, NULL))
})

test_that("label_miss_2d returns a vector of the same length as the input",{
  expect_length(label_miss_2d(test_df$x, test_df$y),
                nrow(test_df))
})

test_that("label_miss_2d returns character vector",{
  expect_type(label_miss_2d(test_df$x, test_df$y),
              "character")
})


test_that("label_miss_2d identifies the correct location of missingness",{
  expect_equal(label_miss_2d(test_df$x, test_df$y),
               c("Missing", "Missing", "Not Missing"))
  expect_equal(label_miss_2d(test_df$y, test_df$z),
               c("Not Missing", "Missing", "Not Missing"))
  expect_equal(label_miss_2d(test_df$x, test_df$z),
               c("Missing", "Not Missing", "Not Missing"))
})

Try the naniar package in your browser

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

naniar documentation built on Feb. 16, 2023, 5:11 p.m.