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