summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-05-26 00:04:10 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-05-26 00:04:10 +0200
commitcf2c8f2037907d8d619348a70594bab28f166d64 (patch)
treef3ae3169ddaf545a8de27d74718908f3c0d3f760 /core
parentb741893013eda90045e5a3950c37ba21d073b351 (diff)
downloadiced-cf2c8f2037907d8d619348a70594bab28f166d64.tar.gz
iced-cf2c8f2037907d8d619348a70594bab28f166d64.tar.bz2
iced-cf2c8f2037907d8d619348a70594bab28f166d64.zip
Use approx for testing color operations
Diffstat (limited to 'core')
-rw-r--r--core/Cargo.toml3
-rw-r--r--core/src/color.rs19
2 files changed, 11 insertions, 11 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml
index fc5de36f..55f2e85f 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -19,3 +19,6 @@ optional = true
[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = "0.1"
+
+[dev-dependencies]
+approx = "0.5"
diff --git a/core/src/color.rs b/core/src/color.rs
index 88115f25..1392f28b 100644
--- a/core/src/color.rs
+++ b/core/src/color.rs
@@ -231,6 +231,8 @@ mod tests {
#[test]
fn color_manipulation() {
+ use approx::assert_relative_eq;
+
let c1 = Color::from_rgb(0.5, 0.4, 0.3);
let c2 = Color::from_rgb(0.2, 0.5, 0.3);
@@ -242,16 +244,11 @@ mod tests {
let lighter = l1.lighten(l2);
// Convert back to our Color
- let r: Color = Srgba::from_linear(lighter).into();
-
- assert_eq!(
- r,
- Color {
- r: 0.5,
- g: 0.5,
- b: 0.3,
- a: 1.0
- }
- );
+ let result: Color = Srgba::from_linear(lighter).into();
+
+ assert_relative_eq!(result.r, 0.5);
+ assert_relative_eq!(result.g, 0.5);
+ assert_relative_eq!(result.b, 0.3);
+ assert_relative_eq!(result.a, 1.0);
}
}