test_that("awe_explore summarises a data frame", { e <- awe_explore(mtcars) expect_s3_class(e, "AWEExplore") expect_equal(e$n_rows, nrow(mtcars)) expect_equal(e$n_cols, ncol(mtcars)) }) test_that("awe_preprocess imputes and splits", { d <- mtcars d$mpg[1:3] <- NA sp <- awe_preprocess(d, target = "mpg", test_prop = 0.2, seed = 1) expect_false(anyNA(sp$train)) expect_false(anyNA(sp$test)) expect_equal(nrow(sp$train) + nrow(sp$test), nrow(d)) }) test_that("awe_preprocess stratified split preserves class proportions", { sp <- awe_preprocess(iris, target = "Species", test_prop = 0.3, stratify = TRUE, seed = 1) train_prop <- prop.table(table(sp$train$Species)) test_prop <- prop.table(table(sp$test$Species)) expect_equal(as.numeric(train_prop), as.numeric(test_prop), tolerance = 0.05) expect_setequal(levels(droplevels(sp$test$Species)), levels(iris$Species)) }) test_that("awe_preprocess stratify = FALSE still returns a valid split", { sp <- awe_preprocess(iris, target = "Species", test_prop = 0.3, stratify = FALSE, seed = 1) expect_equal(nrow(sp$train) + nrow(sp$test), nrow(iris)) }) test_that("awe_model selects a regression model", { m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) expect_s3_class(m, "AWEModel") expect_equal(m$target_type, "continuous") expect_true(m$best_name %in% names(m$candidates_fitted)) expect_true(all(c("linear_regression", "decision_tree") %in% m$leaderboard$model)) }) test_that("awe_model selects a classification model", { d <- iris m <- awe_model(d, target = "Species", k = 3, seed = 1) expect_s3_class(m, "AWEModel") expect_equal(m$target_type, "multiclass") }) test_that("awe_wrap + predict works end to end", { m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) w <- awe_wrap(m) expect_s3_class(w, "AWEWrapper") p <- predict(w) expect_length(p, nrow(mtcars)) }) test_that("awe_explain computes importance and pdp", { m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) w <- awe_wrap(m) ex <- awe_explain(w, n_permutations = 2) expect_s3_class(ex, "AWEExplainer") expect_true(nrow(ex$importance) > 0) expect_true(length(ex$pdp) > 0) }) test_that("awe_evaluate computes regression and classification metrics", { m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) w <- awe_wrap(m) ev <- awe_evaluate(w, newdata = mtcars) expect_s3_class(ev, "AWEEvaluation") expect_true(is.finite(ev$metrics$RMSE)) d <- iris mc <- awe_model(d, target = "Species", k = 3, seed = 1) wc <- awe_wrap(mc) evc <- awe_evaluate(wc, newdata = d) expect_true(evc$metrics$accuracy >= 0 && evc$metrics$accuracy <= 1) }) test_that("full awe() pipeline runs end to end on a regression target", { fit <- awe(mtcars, target = "mpg", k = 3, explain = TRUE, seed = 1) expect_s3_class(fit, "awe") expect_true(!is.null(fit$story)) p <- predict(fit) expect_length(p, nrow(fit$preprocess$train)) }) test_that("full awe() pipeline runs end to end on a classification target", { fit <- awe(iris, target = "Species", k = 3, explain = TRUE, seed = 1) expect_s3_class(fit, "awe") expect_equal(fit$model$target_type, "multiclass") }) test_that("awe_report writes a markdown report", { fit <- awe(mtcars, target = "mpg", k = 3, explain = TRUE, seed = 1) path <- awe_report(fit, file = file.path(tempdir(), "test_report"), format = "md") expect_true(file.exists(path)) }) test_that("awe_select_features filters and scores predictors", { fs <- awe_select_features(mtcars, target = "mpg", top_n = 5) expect_s3_class(fs, "AWEFeatureSelection") expect_length(fs$selected, 5) expect_true(all(fs$selected %in% names(mtcars))) expect_true(nrow(fs$scores) >= 5) }) test_that("awe_select_features drops near-zero-variance and correlated predictors", { d <- mtcars d$const <- 1 # zero variance fs <- awe_select_features(d, target = "mpg", nzv = TRUE, correlation = TRUE, corr_cutoff = 0.9) expect_true("const" %in% fs$dropped$near_zero_variance || !"const" %in% fs$selected) }) test_that("awe() with select_features = TRUE runs end to end", { fit <- awe(mtcars, target = "mpg", k = 3, select_features = TRUE, top_n_features = 5, seed = 1) expect_s3_class(fit, "awe") expect_s3_class(fit$feature_selection, "AWEFeatureSelection") expect_true(length(fit$model$predictors) <= 5) }) test_that("awe_model respects the models argument", { m <- awe_model(mtcars, target = "mpg", k = 3, models = c("linear_regression", "decision_tree"), seed = 1) expect_true(all(m$leaderboard$model %in% c("linear_regression", "decision_tree"))) }) test_that("awe_wrap can wrap a specific named candidate", { m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) w <- awe_wrap(m, which = "decision_tree") expect_equal(w$model_name, "decision_tree") expect_true(inherits(w$model, "rpart")) }) test_that("varImp works for a wrapped model", { m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) w <- awe_wrap(m, which = "decision_tree") vi <- varImp(w) expect_s3_class(vi, "AWEVarImp") expect_true(all(c("variable", "importance") %in% names(vi))) }) test_that("plot_tree runs without error on a decision tree candidate", { m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) expect_error(plot_tree(m, which = "decision_tree"), NA) }) test_that("plotting helpers run without error", { expect_error(plot_correlation(mtcars), NA) expect_error(plot_missingness(mtcars), NA) m <- awe_model(mtcars, target = "mpg", k = 3, seed = 1) expect_error(plot_leaderboard(m), NA) fs <- awe_select_features(mtcars, target = "mpg", top_n = 5) expect_error(plot_feature_selection(fs), NA) }) test_that("classification model bank includes svm/naive_bayes/knn when engines are installed", { m <- awe_model(iris, target = "Species", k = 3, seed = 1) expect_true(nrow(m$leaderboard) >= 3) })