diff --git a/src/color/hsv.rs b/src/color/hsv.rs index b3e6a7e..2cb949f 100644 --- a/src/color/hsv.rs +++ b/src/color/hsv.rs @@ -214,3 +214,48 @@ impl ToRGBA for HSVA { RGBA::from_rgb_a(self.hsv().to_rgb(), (*self).a.to_channel()) } } + +#[cfg(test)] +mod tests { + use color::*; + + #[test] + fn test_hsv_to_hsv() { + assert_eq!(HSV::new::(0.0, 0.0, 1.0).to_hsv::(), HSV::new::(0.0, 0.0, 1.0)); + assert_eq!(HSV::new::(0.0, 1.0, 0.6).to_hsv::(), HSV::new::(0.0, 1.0, 0.6)); + assert_eq!(HSV::new::(120.0, 1.0, 0.6).to_hsv::(), HSV::new::(120.0, 1.0, 0.6)); + assert_eq!(HSV::new::(240.0, 1.0, 0.6).to_hsv::(), HSV::new::(240.0, 1.0, 0.6)); + } + + #[test] + fn test_hsv_to_rgb() { + assert_eq!(HSV::new::(0.0, 0.0, 1.0).to_rgb::(), RGB::new::(0xFF, 0xFF, 0xFF)); + assert_eq!(HSV::new::(0.0, 1.0, 0.6).to_rgb::(), RGB::new::(0x99, 0x00, 0x00)); + assert_eq!(HSV::new::(120.0, 1.0, 0.6).to_rgb::(), RGB::new::(0x00, 0x99, 0x00)); + assert_eq!(HSV::new::(240.0, 1.0, 0.6).to_rgb::(), RGB::new::(0x00, 0x00, 0x99)); + } + + #[test] + fn test_tuple_to_hsva() { + assert_eq!((RGB::new::(0xFF, 0xFF, 0xFF), 0.5f32).to_hsva::(), HSVA::new::(0.0, 0.0, 1.0, 0.5)); + assert_eq!((RGB::new::(0x99, 0x00, 0x00), 0.5f32).to_hsva::(), HSVA::new::(0.0, 1.0, 0.6, 0.5)); + assert_eq!((RGB::new::(0x00, 0x99, 0x00), 0.5f32).to_hsva::(), HSVA::new::(120.0, 1.0, 0.6, 0.5)); + assert_eq!((RGB::new::(0x00, 0x00, 0x99), 0.5f32).to_hsva::(), HSVA::new::(240.0, 1.0, 0.6, 0.5)); + } + + #[test] + fn test_hsva_to_hsva() { + assert_eq!(HSVA::new::(0.0, 0.0, 1.0, 0.5).to_hsva::(), HSVA::new::(0.0, 0.0, 1.0, 0.5)); + assert_eq!(HSVA::new::(0.0, 1.0, 0.6, 0.5).to_hsva::(), HSVA::new::(0.0, 1.0, 0.6, 0.5)); + assert_eq!(HSVA::new::(120.0, 1.0, 0.6, 0.5).to_hsva::(), HSVA::new::(120.0, 1.0, 0.6, 0.5)); + assert_eq!(HSVA::new::(240.0, 1.0, 0.6, 0.5).to_hsva::(), HSVA::new::(240.0, 1.0, 0.6, 0.5)); + } + + #[test] + fn test_hsva_to_rgba() { + assert_eq!(HSVA::new::(0.0, 0.0, 1.0, 0.5).to_rgba::(), RGBA::new::(0xFF, 0xFF, 0xFF, 0x7F)); + assert_eq!(HSVA::new::(0.0, 1.0, 0.6, 0.5).to_rgba::(), RGBA::new::(0x99, 0x00, 0x00, 0x7F)); + assert_eq!(HSVA::new::(120.0, 1.0, 0.6, 0.5).to_rgba::(), RGBA::new::(0x00, 0x99, 0x00, 0x7F)); + assert_eq!(HSVA::new::(240.0, 1.0, 0.6, 0.5).to_rgba::(), RGBA::new::(0x00, 0x00, 0x99, 0x7F)); + } +}