assert_abs_diff_le_x

Macro assert_abs_diff_le_x 

Source
macro_rules! assert_abs_diff_le_x {
    ($a:expr, $b:expr, $x:expr $(,)?) => { ... };
    ($a:expr, $b:expr, $x:expr, $($message:tt)+) => { ... };
}
Expand description

Assert an absolute difference is less than or equal to an expression.

Pseudocode:
|Δ| ≤ x

  • If true, return (lhs, rhs).

  • Otherwise, call panic! with a message and the values of the expressions with their debug representations.

§Examples

use assertables::*;

let a = 10;
let b = 13;
let x = 4;
assert_abs_diff_le_x!(a, b, x);

// This will panic
let a = 10;
let b = 13;
let x = 2;
assert_abs_diff_le_x!(a, b, x);
// assertion failed: `assert_abs_diff_le_x!(a, b)`
// https://docs.rs/assertables/…/assertables/macro.assert_abs_diff_le_x.html
//  a label: `a`,
//  a debug: `10`,
//  b label: `b`,
//  b debug: `13`,
//  x label: `x`,
//  x debug: `2`,
//      |Δ|: `3`,
//  |Δ| ≤ x: false

§Module macros