2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-10 08:09:36 +08:00
|
|
|
use std::vec;
|
|
|
|
#[test]
|
|
|
|
use std::num::{Real, Zero, One, abs};
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-02 02:50:00 +08:00
|
|
|
use std::rand::{random};
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-06-02 02:50:00 +08:00
|
|
|
use std::cmp::ApproxEq;
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-05-19 05:56:03 +08:00
|
|
|
use traits::inv::Inv;
|
|
|
|
#[test]
|
2013-05-19 19:53:19 +08:00
|
|
|
use traits::rotation::Rotation;
|
2013-06-10 08:09:36 +08:00
|
|
|
#[test]
|
|
|
|
use traits::dim::d7;
|
2013-05-19 19:53:19 +08:00
|
|
|
#[test]
|
2013-06-08 18:09:17 +08:00
|
|
|
use dim1::vec1::Vec1;
|
2013-05-19 19:53:19 +08:00
|
|
|
#[test]
|
2013-05-19 01:04:03 +08:00
|
|
|
use dim1::mat1::Mat1;
|
|
|
|
#[test]
|
|
|
|
use dim2::mat2::Mat2;
|
|
|
|
#[test]
|
|
|
|
use dim3::mat3::Mat3;
|
2013-06-10 08:09:36 +08:00
|
|
|
#[test]
|
|
|
|
use ndim::nmat::NMat;
|
2013-05-19 19:53:19 +08:00
|
|
|
#[test]
|
|
|
|
use adaptors::rotmat::Rotmat;
|
2013-06-10 08:09:36 +08:00
|
|
|
#[test]
|
|
|
|
use traits::flatten::Flatten;
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-05-22 07:15:03 +08:00
|
|
|
macro_rules! test_inv_mat_impl(
|
2013-06-09 22:04:54 +08:00
|
|
|
($t: ty) => (
|
2013-06-02 02:50:00 +08:00
|
|
|
for 10000.times
|
2013-05-22 07:15:03 +08:00
|
|
|
{
|
|
|
|
let randmat : $t = random();
|
|
|
|
|
|
|
|
assert!((randmat.inverse() * randmat).approx_eq(&One::one()));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-06-10 08:09:36 +08:00
|
|
|
macro_rules! test_flatten_impl(
|
|
|
|
($t: ty, $n: ty) => (
|
|
|
|
for 10000.times
|
|
|
|
{
|
|
|
|
let v: $t = random();
|
|
|
|
let mut l: ~[$n] = vec::from_elem(42 + Flatten::flat_size::<$n, $t>(), Zero::zero::<$n>());
|
|
|
|
|
|
|
|
v.to_flattened_inplace(l, 42);
|
|
|
|
|
|
|
|
assert!(Flatten::from_flattened::<$n, $t>(v.to_flattened(), 0) == v);
|
|
|
|
assert!(Flatten::from_flattened::<$n, $t>(l, 42) == v);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
|
|
|
fn test_inv_mat1()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_inv_mat_impl!(Mat1<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inv_mat2()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_inv_mat_impl!(Mat2<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inv_mat3()
|
2013-05-22 07:15:03 +08:00
|
|
|
{ test_inv_mat_impl!(Mat3<f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-06-02 02:50:00 +08:00
|
|
|
// FIXME: ICE
|
2013-05-22 07:15:03 +08:00
|
|
|
// #[test]
|
|
|
|
// fn test_inv_nmat()
|
|
|
|
// { test_inv_mat_impl!(NMat<d7, f64>); }
|
2013-05-19 01:04:03 +08:00
|
|
|
|
2013-06-10 08:09:36 +08:00
|
|
|
#[test]
|
|
|
|
fn test_flatten_mat1()
|
|
|
|
{ test_flatten_impl!(Mat1<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_flatten_mat2()
|
|
|
|
{ test_flatten_impl!(Mat2<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_flatten_mat3()
|
|
|
|
{ test_flatten_impl!(Mat3<f64>, f64); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_flatten_nmat()
|
|
|
|
{ test_flatten_impl!(NMat<d7, f64>, f64); }
|
|
|
|
|
2013-05-19 01:04:03 +08:00
|
|
|
#[test]
|
2013-05-19 19:53:19 +08:00
|
|
|
fn test_rotation2()
|
2013-05-19 01:04:03 +08:00
|
|
|
{
|
2013-06-02 02:50:00 +08:00
|
|
|
for 10000.times
|
2013-05-19 19:53:19 +08:00
|
|
|
{
|
|
|
|
let randmat = One::one::<Rotmat<Mat2<f64>>>();
|
2013-06-08 18:09:17 +08:00
|
|
|
let ang = &Vec1::new(abs::<f64>(random()) % Real::pi());
|
2013-05-19 19:53:19 +08:00
|
|
|
|
2013-05-21 23:25:01 +08:00
|
|
|
assert!(randmat.rotated(ang).rotation().approx_eq(ang));
|
2013-05-19 19:53:19 +08:00
|
|
|
}
|
2013-05-19 01:04:03 +08:00
|
|
|
}
|