aboutsummaryrefslogtreecommitdiff
path: root/src/ansi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansi.rs')
-rw-r--r--src/ansi.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ansi.rs b/src/ansi.rs
index 282be0f..2024164 100644
--- a/src/ansi.rs
+++ b/src/ansi.rs
@@ -2085,4 +2085,23 @@ mod tests {
let expected: Vec<usize> = (0..256).collect();
assert_eq!(handler.reset_colors, expected);
}
+
+ #[test]
+ #[cfg(not(feature = "no_std"))]
+ fn contrast() {
+ let rgb1 = Rgb { r: 0xff, g: 0xff, b: 0xff };
+ let rgb2 = Rgb { r: 0x00, g: 0x00, b: 0x00 };
+ assert!((rgb1.contrast(rgb2) - 21.).abs() < f64::EPSILON);
+
+ let rgb1 = Rgb { r: 0xff, g: 0xff, b: 0xff };
+ assert!((rgb1.contrast(rgb1) - 1.).abs() < f64::EPSILON);
+
+ let rgb1 = Rgb { r: 0xff, g: 0x00, b: 0xff };
+ let rgb2 = Rgb { r: 0x00, g: 0xff, b: 0x00 };
+ assert!((rgb1.contrast(rgb2) - 2.285_543_608_124_253_3).abs() < f64::EPSILON);
+
+ let rgb1 = Rgb { r: 0x12, g: 0x34, b: 0x56 };
+ let rgb2 = Rgb { r: 0xfe, g: 0xdc, b: 0xba };
+ assert!((rgb1.contrast(rgb2) - 9.786_558_997_257_74).abs() < f64::EPSILON);
+ }
}