library(testthat) library(AutoEDA) #========================================================== # categorical_summary() #========================================================== test_that("categorical_summary returns CategoricalSummary object", { result <- categorical_summary(iris) expect_s3_class( result, "CategoricalSummary" ) }) test_that("categorical_summary returns data.frame", { result <- categorical_summary(iris) expect_true( is.data.frame(result) ) }) test_that("categorical_summary accepts data.frame", { expect_no_error( categorical_summary(iris) ) }) test_that("categorical_summary detects categorical variable", { result <- categorical_summary(iris) expect_true( "Species" %in% result$Variable ) }) test_that("categorical_summary contains expected columns", { result <- categorical_summary(iris) expect_named( result, c( "Variable", "N", "Missing", "Levels", "Most_Frequent", "Frequency", "Percent" ) ) }) test_that("categorical_summary handles character variables", { x <- data.frame( Name = c("A","B","C","A"), Sex = c("M","F","M","F") ) expect_no_error( categorical_summary(x) ) }) test_that("categorical_summary handles missing values", { x <- data.frame( Sex = c("M","F",NA,"F") ) expect_no_error( categorical_summary(x) ) }) #========================================================== # Invalid input #========================================================== test_that("categorical_summary rejects non-data.frame", { expect_error( categorical_summary(1:10) ) }) test_that("categorical_summary rejects empty data.frame", { expect_error( categorical_summary(data.frame()) ) }) test_that("categorical_summary rejects data with no categorical variables", { expect_error( categorical_summary(iris[, 1:4]) ) }) #========================================================== # print.CategoricalSummary() #========================================================== test_that("print.CategoricalSummary works", { result <- categorical_summary(iris) expect_no_error( print(result) ) })