use mcu_hct::Hct;
pub struct DislikeAnalyzer;
impl DislikeAnalyzer {
pub fn is_disliked(hct: &Hct) -> bool {
let hue_passes = hct.hue().round() >= 90.0 && hct.hue().round() <= 111.0;
let chroma_passes = hct.chroma().round() > 16.0;
let tone_passes = hct.tone().round() < 65.0;
hue_passes && chroma_passes && tone_passes
}
pub fn fix_if_disliked(hct: &Hct) -> Hct {
if Self::is_disliked(hct) {
Hct::from(hct.hue(), hct.chroma(), 70.0)
} else {
*hct
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_disliked_dark_yellow_green() {
let hct = Hct::from(100.0, 50.0, 40.0);
assert!(DislikeAnalyzer::is_disliked(&hct));
}
#[test]
fn test_not_disliked_light_color() {
let hct = Hct::from(100.0, 50.0, 70.0);
assert!(!DislikeAnalyzer::is_disliked(&hct));
}
#[test]
fn test_fix_if_disliked_changes_tone() {
let hct = Hct::from(100.0, 50.0, 40.0);
let fixed = DislikeAnalyzer::fix_if_disliked(&hct);
assert!((fixed.tone() - 70.0).abs() < 1.0);
}
#[test]
fn test_fix_if_disliked_preserves_liked_color() {
let hct = Hct::from(200.0, 50.0, 50.0);
let fixed = DislikeAnalyzer::fix_if_disliked(&hct);
assert_eq!(fixed.to_int(), hct.to_int());
}
}