test_that("profile works", { p <- vb_profile(iris) expect_equal(nrow(p), ncol(iris)) expect_true(all(c("variable", "type", "missing_pct") %in% names(p))) }) test_that("summary works", { s <- vb_summary(iris) expect_equal(nrow(s), ncol(iris)) expect_true(any(s$variable == "Sepal.Length")) }) test_that("missing and outliers work", { d <- iris d$Sepal.Length[1] <- NA expect_equal(vb_missing(d)$missing[1], 1) expect_true(nrow(vb_outliers(d)) > 0) }) test_that(".check_data validates input", { expect_error( AutoViz:::.check_data("not a data frame"), "`data` must be a data.frame." ) expect_error( AutoViz:::.check_data(data.frame()), "`data` must contain at least one row." ) dat <- data.frame(x = 1:3) expect_identical( AutoViz:::.check_data(dat), dat ) }) test_that(".var_type identifies common variable types", { expect_equal( AutoViz:::.var_type(as.Date("2026-01-01")), "date" ) expect_equal( AutoViz:::.var_type(as.POSIXct("2026-01-01 12:00:00")), "date" ) expect_equal( AutoViz:::.var_type(c(TRUE, FALSE, TRUE)), "logical" ) expect_equal( AutoViz:::.var_type(c(1, 2, 3)), "numeric" ) expect_equal( AutoViz:::.var_type(c("dog", "cat", "dog")), "categorical" ) expect_equal( AutoViz:::.var_type(factor(c("dog", "cat", "dog"))), "categorical" ) }) test_that(".var_type identifies text and other variables", { high_cardinality <- paste0("value_", seq_len(21)) expect_equal( AutoViz:::.var_type(high_cardinality), "text" ) expect_equal( AutoViz:::.var_type(list(1, 2, 3)), "other" ) }) test_that(".var_type handles missing values correctly", { x <- c("dog", "cat", NA, "dog", NA) expect_equal( AutoViz:::.var_type(x), "categorical" ) }) test_that(".safe_unique_n counts non-missing unique values", { x <- c("dog", "cat", "dog", NA, "cat", NA) expect_equal( AutoViz:::.safe_unique_n(x), 2 ) expect_equal( AutoViz:::.safe_unique_n(c(1, 1, 2, 3)), 3 ) }) test_that(".as_df converts non-data-frame objects", { dat <- data.frame( x = 1:3, y = 4:6 ) expect_identical( AutoViz:::.as_df(dat), dat ) mat <- matrix(1:6, nrow = 3) result <- AutoViz:::.as_df(mat) expect_true(is.data.frame(result)) expect_equal(dim(result), c(3, 2)) })