From 4afb2ff47689d9122409c5b0d39d07e6a5982370 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Fri, 26 Aug 2016 11:00:10 +0200 Subject: [PATCH] Fixed tests (#198). --- src/macros/assert.rs | 14 -------------- tests/assert.rs | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/macros/assert.rs b/src/macros/assert.rs index 46976693..c791cfc4 100644 --- a/src/macros/assert.rs +++ b/src/macros/assert.rs @@ -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)) - ) - } - }) -); diff --git a/tests/assert.rs b/tests/assert.rs index bb538cb3..bd2bb33e 100644 --- a/tests/assert.rs +++ b/tests/assert.rs @@ -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(given: &T, expected: &T) where T: Debug + ApproxEq, 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]