test_that("ai_dashboard computes weighted overall correctly with complete scores", { d <- ai_dashboard(reliability = 0.8, fairness = 0.8, robustness = 0.8, calibration = 0.8, hallucination = 0.8) expect_equal(round(d$overall, 6), 0.8) }) test_that("ai_dashboard renormalizes weights when a score is missing, with a warning", { expect_warning( d <- ai_dashboard(reliability = 0.9, fairness = NA, robustness = 0.9, calibration = 0.9, hallucination = 0.9), "Renormalizing" ) # with one NA out of five equal-weighted scores, remaining 4 should # renormalize and overall should equal 0.9, not be deflated expect_equal(round(d$overall, 6), 0.9) }) ## ---- print method and grade boundaries ----------------------------- test_that("print.aiEvalR_dashboard renders bars and a grade", { d <- ai_dashboard(reliability = 0.94, fairness = 0.82, robustness = 0.70, calibration = 0.88, hallucination = 0.81) expect_output(print(d), "AI Evaluation Dashboard") expect_output(print(d), "Overall") }) test_that("ai_dashboard assigns letter grades by overall score", { hi <- ai_dashboard(0.95, 0.95, 0.95, 0.95, 0.95) lo <- ai_dashboard(0.50, 0.50, 0.50, 0.50, 0.50) expect_equal(hi$grade, "A") expect_equal(lo$grade, "F") }) test_that("ai_dashboard honors custom weights that sum to 1", { w <- c(Reliability = 0.6, Fairness = 0.1, Robustness = 0.1, Calibration = 0.1, Hallucination = 0.1) d <- ai_dashboard(1.0, 0, 0, 0, 0, weights = w) expect_equal(round(d$overall, 6), 0.6) }) test_that("ai_dashboard rejects weights that do not sum to 1", { w <- c(Reliability = 0.6, Fairness = 0.1, Robustness = 0.1, Calibration = 0.1, Hallucination = 0.5) expect_error(ai_dashboard(1, 1, 1, 1, 1, weights = w)) }) test_that("ai_dashboard rejects scores outside [0, 1]", { expect_error(ai_dashboard(1.5, 0.5, 0.5, 0.5, 0.5)) })