library(testthat) library(AutoEDA) library(ggplot2) #================================================== # Plot Functions #================================================== #-------------------------------------------------- # Histogram #-------------------------------------------------- test_that("histogram_plot returns ggplot", { p <- histogram_plot(iris, "Sepal.Length") expect_s3_class(p, "ggplot") }) #-------------------------------------------------- # Density #-------------------------------------------------- test_that("density_plot returns ggplot", { p <- density_plot(iris, "Sepal.Length") expect_s3_class(p, "ggplot") }) #-------------------------------------------------- # Boxplot #-------------------------------------------------- test_that("box_plot returns ggplot", { p <- box_plot(iris, "Sepal.Length") expect_s3_class(p, "ggplot") }) #-------------------------------------------------- # Barplot #-------------------------------------------------- test_that("bar_plot returns ggplot", { p <- bar_plot(iris, "Species") expect_s3_class(p, "ggplot") }) #-------------------------------------------------- # Scatter Plot #-------------------------------------------------- test_that("scatter_plot returns ggplot", { p <- scatter_plot( iris, "Sepal.Length", "Petal.Length" ) expect_s3_class(p, "ggplot") }) #-------------------------------------------------- # Pair Plot #-------------------------------------------------- test_that("pair_plot returns ggmatrix", { p <- pair_plot(iris) expect_s3_class(p, "ggmatrix") }) #-------------------------------------------------- # Missing Value Plot #-------------------------------------------------- test_that("plot_missing returns ggplot", { p <- plot_missing(airquality) expect_s3_class(p, "ggplot") }) #-------------------------------------------------- # Missing Heatmap #-------------------------------------------------- test_that("missing_heatmap runs", { expect_no_error( missing_heatmap(airquality) ) }) #-------------------------------------------------- # Missing Pattern #-------------------------------------------------- test_that("missing_pattern runs", { expect_no_error( missing_pattern(airquality) ) }) #-------------------------------------------------- # Outlier Plot #-------------------------------------------------- test_that("plot_outliers returns ggplot", { p <- plot_outliers(iris) expect_s3_class(p, "ggplot") }) #================================================== # Invalid Inputs #================================================== test_that("histogram_plot rejects non-data.frame", { expect_error( histogram_plot(1:10, "Sepal.Length") ) }) test_that("density_plot rejects non-data.frame", { expect_error( density_plot(1:10, "Sepal.Length") ) }) test_that("box_plot rejects non-data.frame", { expect_error( box_plot(1:10, "Sepal.Length") ) }) test_that("bar_plot rejects non-data.frame", { expect_error( bar_plot(1:10, "Species") ) }) test_that("scatter_plot rejects non-data.frame", { expect_error( scatter_plot( 1:10, "x", "y" ) ) }) test_that("pair_plot rejects non-data.frame", { expect_error( pair_plot(1:10) ) }) test_that("plot_missing rejects non-data.frame", { expect_error( plot_missing(1:10) ) }) test_that("missing_heatmap rejects non-data.frame", { expect_error( missing_heatmap(1:10) ) }) test_that("missing_pattern rejects non-data.frame", { expect_error( missing_pattern(1:10) ) }) test_that("plot_outliers rejects non-data.frame", { expect_error( plot_outliers(1:10) ) }) #================================================== # Invalid Variable Names #================================================== test_that("histogram_plot rejects invalid variable", { expect_error( histogram_plot( iris, "ABC" ) ) }) test_that("density_plot rejects invalid variable", { expect_error( density_plot( iris, "ABC" ) ) }) test_that("box_plot rejects invalid variable", { expect_error( box_plot( iris, "ABC" ) ) }) test_that("bar_plot rejects numeric variable", { expect_error( bar_plot( iris, "Sepal.Length" ) ) }) test_that("scatter_plot rejects invalid variables", { expect_error( scatter_plot( iris, "ABC", "XYZ" ) ) }) #================================================== # Empty Data #================================================== test_that("plot_missing rejects empty data.frame", { expect_error( plot_missing(data.frame()) ) }) test_that("missing_heatmap rejects empty data.frame", { expect_error( missing_heatmap(data.frame()) ) }) test_that("missing_pattern rejects empty data.frame", { expect_error( missing_pattern(data.frame()) ) }) #================================================== # Missing Values #================================================== test_that("plot_missing handles missing values", { expect_no_error( plot_missing(airquality) ) }) test_that("missing_heatmap handles missing values", { expect_no_error( missing_heatmap(airquality) ) }) test_that("missing_pattern handles missing values", { expect_no_error( missing_pattern(airquality) ) })