library(testthat) library(AutoEDA) library(ggplot2) #========================================================== # outlier_detection() #========================================================== test_that("outlier_detection returns OutlierSummary", { x <- outlier_detection(iris) expect_s3_class( x, "OutlierSummary" ) }) test_that("outlier_detection accepts IQR", { expect_no_error( outlier_detection( iris, method = "IQR" ) ) }) test_that("outlier_detection accepts ZScore", { expect_no_error( outlier_detection( iris, method = "ZScore" ) ) }) test_that("outlier_detection accepts MAD", { expect_no_error( outlier_detection( iris, method = "MAD" ) ) }) test_that("outlier_detection rejects invalid method", { expect_error( outlier_detection( iris, method = "ABC" ) ) }) test_that("outlier_detection rejects invalid threshold", { expect_error( outlier_detection( iris, threshold = 0 ) ) }) test_that("outlier_detection rejects non-data.frame", { expect_error( outlier_detection( 1:10 ) ) }) test_that("outlier_detection rejects empty data.frame", { expect_error( outlier_detection( data.frame() ) ) }) #========================================================== # outlier_summary() #========================================================== test_that("outlier_summary returns OutlierSummary", { x <- outlier_summary(iris) expect_s3_class( x, "OutlierSummary" ) }) test_that("outlier_summary accepts valid data", { expect_no_error( outlier_summary(iris) ) }) test_that("outlier_summary rejects invalid input", { expect_error( outlier_summary(1:10) ) }) #========================================================== # plot_outliers() #========================================================== test_that("plot_outliers returns ggplot", { p <- plot_outliers(iris) expect_s3_class( p, "ggplot" ) }) test_that("plot_outliers accepts valid data", { expect_no_error( plot_outliers(iris) ) }) test_that("plot_outliers rejects invalid input", { expect_error( plot_outliers(1:10) ) }) #========================================================== # outlier_values() #========================================================== test_that("outlier_values returns data.frame", { x <- outlier_values( iris, "Sepal.Length" ) expect_s3_class( x, "data.frame" ) }) test_that("outlier_values accepts valid input", { expect_no_error( outlier_values( iris, "Sepal.Length" ) ) }) test_that("outlier_values preserves columns", { x <- outlier_values( iris, "Sepal.Length" ) expect_equal( names(x), names(iris) ) }) test_that("outlier_values returns zero or more rows", { x <- outlier_values( iris, "Sepal.Length" ) expect_gte( nrow(x), 0 ) }) test_that("outlier_values handles missing values", { d <- iris d$Sepal.Length[1:5] <- NA expect_no_error( outlier_values( d, "Sepal.Length" ) ) }) test_that("outlier_values works when no outliers exist", { d <- data.frame( x = c(10,11,12,13,14,15) ) x <- outlier_values( d, "x" ) expect_equal( nrow(x), 0 ) }) test_that("outlier_values rejects non-data.frame", { expect_error( outlier_values( 1:10, "x" ) ) }) test_that("outlier_values rejects empty data.frame", { expect_error( outlier_values( data.frame(), "x" ) ) }) test_that("outlier_values rejects invalid variable", { expect_error( outlier_values( iris, "ABC" ) ) }) test_that("outlier_values rejects categorical variable", { expect_error( outlier_values( iris, "Species" ) ) })