library(testthat) library(AutoEDA) #========================================================== # missing_pattern() #========================================================== test_that("missing_pattern works with iris", { skip_if_not_installed("mice") expect_no_error( missing_pattern(iris) ) }) test_that("missing_pattern works with missing values", { skip_if_not_installed("mice") dat <- iris dat$Sepal.Length[1:10] <- NA dat$Species[5:15] <- NA expect_no_error( missing_pattern(dat) ) }) test_that("missing_pattern works with numeric-only data", { skip_if_not_installed("mice") expect_no_error( missing_pattern( iris[, 1:4] ) ) }) test_that("missing_pattern works with tibble", { skip_if_not_installed("mice") skip_if_not_installed("tibble") dat <- tibble::as_tibble(iris) expect_no_error( missing_pattern(dat) ) }) test_that("missing_pattern works with character variables", { skip_if_not_installed("mice") dat <- data.frame( A = c("A", "B", NA, "C"), B = c("Dog", "Cat", "Dog", NA), stringsAsFactors = FALSE ) expect_no_error( missing_pattern(dat) ) }) test_that("missing_pattern works with factor variables", { skip_if_not_installed("mice") dat <- data.frame( A = factor(c("A", "B", "A", NA)), B = factor(c("Low", "Medium", "High", "Low")) ) expect_no_error( missing_pattern(dat) ) }) test_that("missing_pattern works with logical variables", { skip_if_not_installed("mice") dat <- data.frame( A = c(TRUE, FALSE, TRUE, NA), B = c(FALSE, TRUE, FALSE, TRUE) ) expect_no_error( missing_pattern(dat) ) }) test_that("missing_pattern works with Date variables", { skip_if_not_installed("mice") dat <- data.frame( Date1 = as.Date("2025-01-01") + 0:4, Date2 = as.Date("2025-02-01") + c(0, NA, 2, 3, 4) ) expect_no_error( missing_pattern(dat) ) }) test_that("missing_pattern works with POSIXct variables", { skip_if_not_installed("mice") dat <- data.frame( Time1 = as.POSIXct("2025-01-01") + 0:4, Time2 = as.POSIXct("2025-01-02") + c(0, NA, 2, 3, 4) ) expect_no_error( missing_pattern(dat) ) }) #========================================================== # Invalid input #========================================================== test_that("missing_pattern rejects non-data.frame", { expect_error( missing_pattern(1:10) ) }) test_that("missing_pattern rejects NULL", { expect_error( missing_pattern(NULL) ) }) test_that("missing_pattern rejects empty data.frame", { expect_error( missing_pattern(data.frame()) ) }) test_that("missing_pattern rejects list", { expect_error( missing_pattern(list(a = 1)) ) }) test_that("missing_pattern rejects character vector", { expect_error( missing_pattern(letters) ) }) test_that("missing_pattern rejects one-column data", { skip_if_not_installed("mice") dat <- data.frame( x = c(1, NA, 3, 4) ) expect_error( missing_pattern(dat) ) })