library(testthat) library(AutoEDA) library(ggplot2) #========================================================== # cluster_elbow() #========================================================== test_that("cluster_elbow returns ggplot", { skip_if_not_installed("factoextra") p <- cluster_elbow(iris) expect_s3_class( p, "ggplot" ) }) test_that("cluster_elbow works with numeric-only data", { skip_if_not_installed("factoextra") expect_no_error( cluster_elbow( iris[, 1:4] ) ) }) test_that("cluster_elbow works with tibble", { skip_if_not_installed("factoextra") skip_if_not_installed("tibble") dat <- tibble::as_tibble(iris) expect_no_error( cluster_elbow(dat) ) }) #========================================================== # Invalid input #========================================================== test_that("cluster_elbow rejects non-data.frame", { expect_error( cluster_elbow( 1:10 ) ) }) test_that("cluster_elbow rejects NULL", { expect_error( cluster_elbow( NULL ) ) }) test_that("cluster_elbow rejects character vector", { expect_error( cluster_elbow( letters ) ) }) test_that("cluster_elbow rejects empty data.frame", { expect_error( cluster_elbow( data.frame() ) ) }) test_that("cluster_elbow rejects one numeric variable", { expect_error( cluster_elbow( data.frame( x = 1:10 ) ) ) }) test_that("cluster_elbow rejects non-numeric data", { expect_error( cluster_elbow( data.frame( A = letters[1:10], B = LETTERS[1:10] ) ) ) }) test_that("cluster_elbow rejects mixed numeric and character data", { expect_error( cluster_elbow( data.frame( x = 1:10, y = letters[1:10] ) ) ) }) test_that("cluster_elbow rejects missing values", { dat <- iris dat$Sepal.Length[1:10] <- NA expect_error( cluster_elbow(dat), "Missing values" ) })