forked from M-Labs/nalgebra
Fixed tests (#198).
This commit is contained in:
parent
a90c2c23fa
commit
4afb2ff476
@ -27,17 +27,3 @@ macro_rules! assert_approx_eq_ulps(
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
/// Asserts approximate equality of two values with the `ApproxEq` trait.
|
||||
#[macro_export]
|
||||
macro_rules! assert_approx_eq(
|
||||
($given: expr, $expected: expr) => ({
|
||||
let (given_val, expected_val) = (&($given), &($expected));
|
||||
if !ApproxEq::approx_eq(given_val, expected_val) {
|
||||
panic!("assertion failed: `left ≈ right` (left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)",
|
||||
*given_val, *expected_val,
|
||||
ApproxEq::approx_epsilon(Some(*given_val))
|
||||
)
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@ -4,13 +4,24 @@
|
||||
extern crate nalgebra;
|
||||
|
||||
use nalgebra::{ApproxEq, Vector2};
|
||||
use std::fmt::Debug;
|
||||
|
||||
// Replace the assert_approx_eq! macro so that we can have type inference.
|
||||
fn test_approx_eq<T, N>(given: &T, expected: &T) where T: Debug + ApproxEq<N>, N: Debug {
|
||||
if !given.approx_eq(expected) {
|
||||
panic!("assertion failed: `left ≈ right` (left: `{:?}`, right: `{:?}`, tolerance: `{:?}`)",
|
||||
*given, *expected,
|
||||
T::approx_epsilon()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assert_approx_eq_f64() {
|
||||
let a = 1.0f64;
|
||||
let b = 1.0f64 + 1.0e-12f64;
|
||||
assert_approx_eq!(a, b);
|
||||
assert_approx_eq!(&a, &b);
|
||||
test_approx_eq(&a, &b);
|
||||
test_approx_eq(&(&a), &(&b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -18,7 +29,7 @@ fn assert_approx_eq_f64() {
|
||||
fn assert_approx_eq_vec2_f32_fail() {
|
||||
let a = Vector2::new(1.0f32, 0.0);
|
||||
let b = Vector2::new(1.1f32, 0.1);
|
||||
assert_approx_eq!(a, b);
|
||||
test_approx_eq(&a, &b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user