From 8bca8757c20f7dba827875ec04d2230ee9bcc0c7 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 10 Jul 2013 20:13:50 +1000 Subject: [PATCH] Add hsv conversion tests --- src/color/hsv.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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)); + } +}