diff --git a/citro3d/Cargo.toml b/citro3d/Cargo.toml index 306b2d2..c70473f 100644 --- a/citro3d/Cargo.toml +++ b/citro3d/Cargo.toml @@ -15,4 +15,5 @@ ctru-sys = { git = "https://github.com/rust3ds/ctru-rs.git" } libc = "0.2.125" [dev-dependencies] +float-cmp = "0.9.0" test-runner = { git = "https://github.com/rust3ds/test-runner.git" } diff --git a/citro3d/src/math/fvec.rs b/citro3d/src/math/fvec.rs index c6624c6..fce145d 100644 --- a/citro3d/src/math/fvec.rs +++ b/citro3d/src/math/fvec.rs @@ -128,7 +128,9 @@ impl FVec { #[cfg(test)] mod tests { use super::*; + use float_cmp::assert_approx_eq; + // TODO: These could probably all be doctests instead it's just sort of a pain #[test] fn fvec4() { let l = FVec4::new(2.0, 2.0, 2.0, 2.0); @@ -136,20 +138,20 @@ mod tests { assert_eq!(l, FVec4::splat(2.0)); for component in [l.x(), l.y(), l.z(), l.w()] { - assert!((component - 2.0).abs() < f32::EPSILON); + assert_approx_eq!(f32, component, 2.0); } assert_eq!(l.perspective_divide(), FVec4::splat(1.0)); let dot = l.dot(&FVec4::splat(3.0)); - assert!((dot - 24.0).abs() < f32::EPSILON); + assert_approx_eq!(f32, dot, 24.0); - assert!((l.magnitude() - 4.0).abs() < f32::EPSILON); + assert_approx_eq!(f32, l.magnitude(), 4.0); let norm = l.normalize(); - assert!((norm.magnitude() - 1.0).abs() < f32::EPSILON); + assert_approx_eq!(f32, norm.magnitude(), 1.0); for component in [l.y(), l.z(), l.w()] { - assert!((component - l.x()).abs() < f32::EPSILON); + assert_approx_eq!(f32, component, l.x()); } } @@ -160,18 +162,18 @@ mod tests { assert_eq!(l, FVec3::splat(2.0)); for component in [l.x(), l.y(), l.z()] { - assert!((component - 2.0).abs() < f32::EPSILON); + assert_approx_eq!(f32, component, 2.0); } let dot = l.dot(&FVec3::splat(3.0)); - assert!((dot - 18.0).abs() < f32::EPSILON); + assert_approx_eq!(f32, dot, 18.0); - assert!((l.magnitude() - f32::sqrt(12.0)).abs() < f32::EPSILON); + assert_approx_eq!(f32, l.magnitude(), f32::sqrt(12.0)); let norm = l.normalize(); - assert!((norm.magnitude() - 1.0).abs() < f32::EPSILON); + assert_approx_eq!(f32, norm.magnitude(), 1.0); for component in [l.y(), l.z()] { - assert!((l.x() - component).abs() < f32::EPSILON); + assert_approx_eq!(f32, l.x(), component); } } } diff --git a/citro3d/src/math/ops.rs b/citro3d/src/math/ops.rs index 7a4f486..3be3095 100644 --- a/citro3d/src/math/ops.rs +++ b/citro3d/src/math/ops.rs @@ -85,7 +85,7 @@ mod tests { use super::*; #[test] - fn vec3_ops() { + fn vec3() { let l = FVec3::splat(1.0); let r = FVec3::splat(2.0); @@ -99,7 +99,7 @@ mod tests { } #[test] - fn vec4_ops() { + fn vec4() { let l = FVec4::splat(1.0); let r = FVec4::splat(2.0);