Refactored tests using macros.

This commit is contained in:
Sébastien Crozet 2013-05-21 23:15:03 +00:00
parent 3fa933d13f
commit 65b175b4a7
2 changed files with 75 additions and 164 deletions

View File

@ -19,47 +19,33 @@ use dim3::mat3::Mat3;
#[test]
use adaptors::rotmat::Rotmat;
// FIXME: this one fails with an ICE: node_id_to_type: no type for node [...]
// #[test]
// fn test_inv_nmat()
// {
// let randmat : NMat<d7, f64> = random();
//
// assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
// }
macro_rules! test_inv_mat_impl(
($t:ty) => (
for uint::range(0u, 10000u) |_|
{
let randmat : $t = random();
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
}
);
)
#[test]
fn test_inv_mat1()
{
for uint::range(0u, 10000u) |_|
{
let randmat : Mat1<f64> = random();
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
}
}
{ test_inv_mat_impl!(Mat1<f64>); }
#[test]
fn test_inv_mat2()
{
for uint::range(0u, 10000u) |_|
{
let randmat : Mat2<f64> = random();
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
}
}
{ test_inv_mat_impl!(Mat2<f64>); }
#[test]
fn test_inv_mat3()
{
for uint::range(0u, 10000u) |_|
{
let randmat : Mat3<f64> = random();
{ test_inv_mat_impl!(Mat3<f64>); }
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
}
}
// FIXME: this one fails with an ICE: node_id_to_type: no type for node [...]
// #[test]
// fn test_inv_nmat()
// { test_inv_mat_impl!(NMat<d7, f64>); }
#[test]
fn test_rotation2()

View File

@ -25,6 +25,49 @@ use traits::dot::Dot;
#[test]
use traits::norm::Norm;
macro_rules! test_commut_dot_impl(
($t:ty) => (
for uint::range(0u, 10000u) |_|
{
let v1 : $t = random();
let v2 : $t = random();
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
);
)
macro_rules! test_basis_impl(
($t:ty) => (
for uint::range(0u, 10000u) |_|
{
let basis = Basis::canonical_basis::<$t>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
);
)
macro_rules! test_subspace_basis_impl(
($t:ty) => (
for uint::range(0u, 10000u) |_|
{
let v : Vec3<f64> = random();
let v1 = v.normalized();
let subbasis = v1.orthogonal_subspace_basis();
// check vectors are orthogonal to v1
assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// check vectors form an ortogonal basis
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
}
);
)
#[test]
fn test_cross_vec3()
@ -41,167 +84,49 @@ fn test_cross_vec3()
}
#[test]
fn test_dot_nvec()
{
for uint::range(0u, 10000u) |_|
{
let v1 : NVec<d7, f64> = random();
let v2 : NVec<d7, f64> = random();
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
fn test_commut_dot_nvec()
{ test_commut_dot_impl!(NVec<d7, f64>); }
#[test]
fn test_commut_dot_vec3()
{
for uint::range(0u, 10000u) |_|
{
let v1 : Vec3<f64> = random();
let v2 : Vec3<f64> = random();
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
{ test_commut_dot_impl!(Vec3<f64>); }
#[test]
fn test_commut_dot_vec2()
{
for uint::range(0u, 10000u) |_|
{
let v1 : Vec2<f64> = random();
let v2 : Vec2<f64> = random();
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
{ test_commut_dot_impl!(Vec2<f64>); }
#[test]
fn test_commut_dot_vec1()
{
for uint::range(0u, 10000u) |_|
{
let v1 : Vec1<f64> = random();
let v2 : Vec1<f64> = random();
assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1)));
}
}
{ test_commut_dot_impl!(Vec1<f64>); }
#[test]
fn test_basis_vec1()
{
let basis = Basis::canonical_basis::<Vec1<f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
{ test_basis_impl!(Vec1<f64>); }
#[test]
fn test_basis_vec2()
{
let basis = Basis::canonical_basis::<Vec2<f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
{ test_basis_impl!(Vec2<f64>); }
#[test]
fn test_basis_vec3()
{
let basis = Basis::canonical_basis::<Vec3<f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
{ test_basis_impl!(Vec3<f64>); }
#[test]
fn test_basis_nvec()
{
let basis = Basis::canonical_basis::<NVec<d7, f64>>();
// check vectors form an ortogonal basis
assert!(all2(basis, basis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(basis, |e| e.norm().approx_eq(&One::one())));
}
{ test_basis_impl!(NVec<d7, f64>); }
#[test]
fn test_subspace_basis_vec1()
{
for uint::range(0u, 10000u) |_|
{
let v : Vec1<f64> = random();
let v1 = v.normalized();
let subbasis = v1.orthogonal_subspace_basis();
// check vectors are orthogonal to v1
assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// check vectors form an ortogonal basis
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
}
}
{ test_subspace_basis_impl!(Vec1<f64>); }
#[test]
fn test_subspace_basis_vec2()
{
for uint::range(0u, 10000u) |_|
{
let v : Vec2<f64> = random();
let v1 = v.normalized();
let subbasis = v1.orthogonal_subspace_basis();
// check vectors are orthogonal to v1
assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// check vectors form an ortogonal basis
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
}
}
{ test_subspace_basis_impl!(Vec2<f64>); }
#[test]
fn test_subspace_basis_vec3()
{
for uint::range(0u, 10000u) |_|
{
let v : Vec3<f64> = random();
let v1 = v.normalized();
let subbasis = v1.orthogonal_subspace_basis();
{ test_subspace_basis_impl!(Vec3<f64>); }
// check vectors are orthogonal to v1
assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// check vectors form an ortogonal basis
assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// check vectors form an orthonormal basis
assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
}
}
// ICE
//
// #[test]
// fn test_subspace_basis_vecn()
// {
// for uint::range(0u, 10000u) |_|
// {
// let v : NVec<d7, f64> = random();
// let v1 = v.normalized();
// let subbasis = v1.orthogonal_subspace_basis();
//
// // check vectors are orthogonal to v1
// assert!(all(subbasis, |e| v1.dot(e).approx_eq(&Zero::zero())));
// // check vectors form an ortogonal basis
// assert!(all2(subbasis, subbasis, |e1, e2| e1 == e2 || e1.dot(e2).approx_eq(&Zero::zero())));
// // check vectors form an orthonormal basis
// assert!(all(subbasis, |e| e.norm().approx_eq(&One::one())));
// }
// }
#[test]
fn test_subspace_basis_nvec()
{ test_subspace_basis_impl!(NVec<d7, f64>); }