Expand description
Primitive accessibility scoring helpers.
The score intentionally stays simple: Pass contributes full weight,
Warn contributes half weight, and Fail contributes zero. The final score
is normalized to a 0..=100 scale when total weight is positive.
§Examples
use use_accessibility_score::{
AccessibilityCheckResult, CheckStatus, count_failed, count_passed, count_warnings,
score_results,
};
let results = [
AccessibilityCheckResult {
name: String::from("contrast"),
status: CheckStatus::Pass,
weight: 2.0,
},
AccessibilityCheckResult {
name: String::from("label"),
status: CheckStatus::Warn,
weight: 1.0,
},
AccessibilityCheckResult {
name: String::from("focus"),
status: CheckStatus::Fail,
weight: 1.0,
},
];
let score = score_results(&results).unwrap();
assert_eq!(count_passed(&results), 1);
assert_eq!(count_warnings(&results), 1);
assert_eq!(count_failed(&results), 1);
assert_eq!(score.passed, 1);
assert_eq!(score.warnings, 1);
assert_eq!(score.failed, 1);
assert_eq!(score.score, 62.5);