summaryrefslogtreecommitdiff
path: root/system/gd/rust/common/src/asserts.rs
blob: bcbafce4838cb0221bb747456fd987f32782a0bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// Assertion check for X is is within Y of Z
#[macro_export]
macro_rules! assert_near {
    ($thing:expr, $expected:expr, $error:expr) => {
        match (&$thing, &$expected, &$error) {
            (thing_val, expected_val, error_val) => {
                if thing_val < &(expected_val - error_val) || thing_val > &(expected_val + error_val) {
                    panic!(
                        "assertion failed: {:?} is not within {:?} of {:?}",
                        &*thing_val, &*error_val, &*expected_val
                    )
                }
            }
        }
    };
}