Use approx for testing color operations
This commit is contained in:
parent
b741893013
commit
cf2c8f2037
2 changed files with 10 additions and 10 deletions
|
|
@ -19,3 +19,6 @@ optional = true
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
instant = "0.1"
|
instant = "0.1"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
approx = "0.5"
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn color_manipulation() {
|
fn color_manipulation() {
|
||||||
|
use approx::assert_relative_eq;
|
||||||
|
|
||||||
let c1 = Color::from_rgb(0.5, 0.4, 0.3);
|
let c1 = Color::from_rgb(0.5, 0.4, 0.3);
|
||||||
let c2 = Color::from_rgb(0.2, 0.5, 0.3);
|
let c2 = Color::from_rgb(0.2, 0.5, 0.3);
|
||||||
|
|
||||||
|
|
@ -242,16 +244,11 @@ mod tests {
|
||||||
let lighter = l1.lighten(l2);
|
let lighter = l1.lighten(l2);
|
||||||
|
|
||||||
// Convert back to our Color
|
// Convert back to our Color
|
||||||
let r: Color = Srgba::from_linear(lighter).into();
|
let result: Color = Srgba::from_linear(lighter).into();
|
||||||
|
|
||||||
assert_eq!(
|
assert_relative_eq!(result.r, 0.5);
|
||||||
r,
|
assert_relative_eq!(result.g, 0.5);
|
||||||
Color {
|
assert_relative_eq!(result.b, 0.3);
|
||||||
r: 0.5,
|
assert_relative_eq!(result.a, 1.0);
|
||||||
g: 0.5,
|
|
||||||
b: 0.3,
|
|
||||||
a: 1.0
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue