library(testthat) # Create a test for the main function test_that("Testing main function", { # Using the iris dataset for testing formula <- Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width # Run the main function results <- main(iris, formula, choose_imput = TRUE, k = 5) # Check if the results are a list expect_type(results, "list") # Check if all prediction results are returned expect_true("rf_predictions" %in% names(results)) expect_true("svm_predictions" %in% names(results)) expect_true("decision_tree_predictions" %in% names(results)) expect_true("logistic_predictions" %in% names(results)) # Check if the best model information is returned expect_true("best_model_info" %in% names(results)) # Check the structure of the best model information expect_type(results$best_model_info, "list") expect_true("best_model" %in% names(results$best_model_info)) expect_true("error" %in% names(results$best_model_info)) # Check that the best model's name and error are not NULL expect_true(!is.null(results$best_model_info$best_model)) expect_true(!is.null(results$best_model_info$error)) # Check that the error is a valid numeric value between 0 and 1 expect_true(is.numeric(results$best_model_info$error)) expect_true(results$best_model_info$error >= 0 && results$best_model_info$error <= 1) })