From 64130dfb2f124f56657a2835435983964a82663f Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Thu, 1 Jan 2015 10:41:15 +1300 Subject: [PATCH] tests for ApproxEq ULPs --- tests/assert.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/assert.rs b/tests/assert.rs index 3b181aa6..9348a0f1 100644 --- a/tests/assert.rs +++ b/tests/assert.rs @@ -33,3 +33,36 @@ fn assert_approx_eq_eps_f32() { fn assert_approx_eq_eps_f64_fail() { assert_approx_eq_eps!(1.0f64, 1.1, 0.05); } + +#[test] +fn assert_approx_eq_ulps_f32() { + let x = 1000000_f32; + let y = 1000000.1_f32; + assert!(x != y); + assert_approx_eq_ulps!(x, y, 3); +} + +#[test] +#[should_fail] +fn assert_approx_eq_ulps_f32_fail() { + let x = 1000000_f32; + let y = 1000000.1_f32; + assert_approx_eq_ulps!(x, y, 2); +} + +#[test] +fn assert_approx_eq_ulps_f64() { + let x = 1000000_f64; + let y = 1000000.0000000003_f64; + assert!(x != y); + assert_approx_eq_ulps!(x, y, 4); +} + +#[test] +#[should_fail] +fn assert_approx_eq_ulps_f64_fail() { + let x = 1000000_f64; + let y = 1000000.0000000003_f64; + assert!(x != y); + assert_approx_eq_ulps!(x, y, 3); +}