Fixed tests that used assert_approx_eq

This commit is contained in:
kvark 2014-01-08 20:06:02 -05:00
parent 2fdf34cd18
commit 522d20ffe5
7 changed files with 38 additions and 27 deletions

View file

@ -202,4 +202,9 @@ impl<S: Float> Transform3D<S> {
pub fn new(scale: S, rot: Quat<S>, disp: Vec3<S>) -> Transform3D<S> {
Transform3D( Decomposed { scale: scale, rot: rot, disp: disp })
}
#[inline]
pub fn get<'a>(&'a self) -> &'a Decomposed<S,Vec3<S>,Quat<S>> {
let &Transform3D(ref d) = self;
d
}
}

View file

@ -14,14 +14,15 @@
// limitations under the License.
use cgmath::angle::*;
use cgmath::approx::ApproxEq;
#[test]
fn conv() {
assert_approx_eq!(deg(-5.0).to_rad().to_deg(), deg(-5.0));
assert_approx_eq!(deg(30.0).to_rad().to_deg(), deg(30.0));
assert!(deg(-5.0).to_rad().to_deg().approx_eq( &deg(-5.0) ));
assert!(deg(30.0).to_rad().to_deg().approx_eq( &deg(30.0) ));
assert_approx_eq!(rad(-5.0).to_deg().to_rad(), rad(-5.0));
assert_approx_eq!(rad(30.0).to_deg().to_rad(), rad(30.0));
assert!(rad(-5.0).to_deg().to_rad().approx_eq( &rad(-5.0) ));
assert!(rad(30.0).to_deg().to_rad().approx_eq( &rad(30.0) ));
}
#[test]

View file

@ -15,6 +15,7 @@
use cgmath::matrix::*;
use cgmath::vector::*;
use cgmath::approx::ApproxEq;
type float = f64;
pub mod mat2 {
@ -287,11 +288,11 @@ fn test_invert() {
// Mat4
assert!(Mat4::<f64>::identity().invert().unwrap().is_identity());
assert_approx_eq!(mat4::C.invert().unwrap(),
Mat4::new( 5.0, -4.0, 1.0, 0.0,
-4.0, 8.0, -4.0, 0.0,
4.0, -8.0, 4.0, 8.0,
-3.0, 4.0, 1.0, -8.0).mul_s(0.125));
assert!(mat4::C.invert().unwrap().approx_eq(&
Mat4::new( 5.0, -4.0, 1.0, 0.0,
-4.0, 8.0, -4.0, 0.0,
4.0, -8.0, 4.0, 8.0,
-3.0, 4.0, 1.0, -8.0).mul_s(0.125)));
let mut mut_c = mat4::C;
mut_c.invert_self();
assert_eq!(mut_c, mat4::C.invert().unwrap());

View file

@ -14,9 +14,10 @@
// limitations under the License.
use cgmath::point::*;
use cgmath::approx::ApproxEq;
#[test]
fn test_homogeneous() {
let p = Point3::new(1.0, 2.0, 3.0);
assert_approx_eq!(p, Point3::from_homogeneous( &p.to_homogeneous() ));
assert!(p.approx_eq( &Point3::from_homogeneous( &p.to_homogeneous() ) ));
}

View file

@ -2,6 +2,7 @@ use cgmath::sphere::*;
use cgmath::point::*;
use cgmath::vector::*;
use cgmath::ray::*;
use cgmath::approx::ApproxEq;
use cgmath::intersect::Intersect;
use std::num;
@ -13,7 +14,7 @@ fn test_intersection() {
let r2 = Ray::new(Point3::new(1f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize());
let r3 = Ray::new(Point3::new(2f64, 0f64, 5f64), Vec3::new(0f64, 0f64, -5f64).normalize());
assert_eq!((sphere,r0).intersection(), Some(Point3::new(0f64, 0f64, 1f64)));
assert_approx_eq!((sphere,r1).intersection().unwrap(), Point3::new(num::cos(1f64), 0f64, num::sin(1f64)));
assert!((sphere,r1).intersection().unwrap().approx_eq( &Point3::new(num::cos(1f64), 0f64, num::sin(1f64)) ));
assert_eq!((sphere,r2).intersection(), Some(Point3::new(1f64, 0f64, 0f64)));
assert_eq!((sphere,r3).intersection(), None);
}

View file

@ -16,12 +16,13 @@
use cgmath::quaternion::*;
use cgmath::transform::*;
use cgmath::vector::*;
use cgmath::approx::ApproxEq;
#[test]
fn test_invert() {
let v = Vec3::new(1.0, 2.0, 3.0);
let t = Transform3D::new( 1.5, Quat::new(0.5,0.5,0.5,0.5), Vec3::new(6.0,-7.0,8.0) );
let ti = t.invert().expect("Expected successful inversion");
let vt = t.transform_vec( &v );
assert_approx_eq!(v, ti.transform_vec( &vt ));
let t = Transform3D::new(1.5, Quat::new(0.5,0.5,0.5,0.5), Vec3::new(6.0,-7.0,8.0));
let ti = t.get().invert().expect("Expected successful inversion");
let vt = t.get().transform_vec( &v );
assert!(v.approx_eq( &ti.transform_vec( &vt ) ));
}

View file

@ -15,6 +15,7 @@
use cgmath::angle::*;
use cgmath::vector::*;
use cgmath::approx::ApproxEq;
#[test]
fn test_from_value() {
@ -136,23 +137,23 @@ mod test_length {
#[test]
fn test_angle() {
assert_approx_eq!(Vec2::new(1.0, 0.0).angle(&Vec2::new(0.0, 1.0)), rad(Real::frac_pi_2()));
assert_approx_eq!(Vec2::new(10.0, 0.0).angle(&Vec2::new(0.0, 5.0)), rad(Real::frac_pi_2()));
assert_approx_eq!(Vec2::new(-1.0, 0.0).angle(&Vec2::new(0.0, 1.0)), -rad(Real::frac_pi_2()));
assert!(Vec2::new(1.0, 0.0).angle(&Vec2::new(0.0, 1.0)).approx_eq( &rad(Real::frac_pi_2()) ));
assert!(Vec2::new(10.0, 0.0).angle(&Vec2::new(0.0, 5.0)).approx_eq( &rad(Real::frac_pi_2()) ));
assert!(Vec2::new(-1.0, 0.0).angle(&Vec2::new(0.0, 1.0)).approx_eq( &-rad(Real::frac_pi_2()) ));
assert_approx_eq!(Vec3::new(1.0, 0.0, 1.0).angle(&Vec3::new(1.0, 1.0, 0.0)), rad(Real::frac_pi_3()));
assert_approx_eq!(Vec3::new(10.0, 0.0, 10.0).angle(&Vec3::new(5.0, 5.0, 0.0)), rad(Real::frac_pi_3()));
assert_approx_eq!(Vec3::new(-1.0, 0.0, -1.0).angle(&Vec3::new(1.0, -1.0, 0.0)), rad(2.0 * Real::frac_pi_3()));
assert!(Vec3::new(1.0, 0.0, 1.0).angle(&Vec3::new(1.0, 1.0, 0.0)).approx_eq( &rad(Real::frac_pi_3()) ));
assert!(Vec3::new(10.0, 0.0, 10.0).angle(&Vec3::new(5.0, 5.0, 0.0)).approx_eq( &rad(Real::frac_pi_3()) ));
assert!(Vec3::new(-1.0, 0.0, -1.0).angle(&Vec3::new(1.0, -1.0, 0.0)).approx_eq( &rad(2.0 * Real::frac_pi_3()) ));
assert_approx_eq!(Vec4::new(1.0, 0.0, 1.0, 0.0).angle(&Vec4::new(0.0, 1.0, 0.0, 1.0)), rad(Real::frac_pi_2()));
assert_approx_eq!(Vec4::new(10.0, 0.0, 10.0, 0.0).angle(&Vec4::new(0.0, 5.0, 0.0, 5.0)), rad(Real::frac_pi_2()));
assert_approx_eq!(Vec4::new(-1.0, 0.0, -1.0, 0.0).angle(&Vec4::new(0.0, 1.0, 0.0, 1.0)), rad(Real::frac_pi_2()));
assert!(Vec4::new(1.0, 0.0, 1.0, 0.0).angle(&Vec4::new(0.0, 1.0, 0.0, 1.0)).approx_eq( &rad(Real::frac_pi_2()) ));
assert!(Vec4::new(10.0, 0.0, 10.0, 0.0).angle(&Vec4::new(0.0, 5.0, 0.0, 5.0)).approx_eq( &rad(Real::frac_pi_2()) ));
assert!(Vec4::new(-1.0, 0.0, -1.0, 0.0).angle(&Vec4::new(0.0, 1.0, 0.0, 1.0)).approx_eq( &rad(Real::frac_pi_2()) ));
}
#[test]
fn test_normalize() {
// TODO: test normalize_to, normalize_sel.0, and normalize_self_to
assert_approx_eq!(Vec2::new(3.0, 4.0).normalize(), Vec2::new(3.0/5.0, 4.0/5.0));
assert_approx_eq!(Vec3::new(2.0, 3.0, 6.0).normalize(), Vec3::new(2.0/7.0, 3.0/7.0, 6.0/7.0));
assert_approx_eq!(Vec4::new(1.0, 2.0, 4.0, 10.0).normalize(), Vec4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0));
assert!(Vec2::new(3.0, 4.0).normalize().approx_eq( &Vec2::new(3.0/5.0, 4.0/5.0) ));
assert!(Vec3::new(2.0, 3.0, 6.0).normalize().approx_eq( &Vec3::new(2.0/7.0, 3.0/7.0, 6.0/7.0) ));
assert!(Vec4::new(1.0, 2.0, 4.0, 10.0).normalize().approx_eq( &Vec4::new(1.0/11.0, 2.0/11.0, 4.0/11.0, 10.0/11.0) ));
}