macro_rules! expect_near {
($actual:expr, $expected:expr, $max_abs_error:expr, $($format_args:expr),+ $(,)?) => { ... };
($actual:expr, $expected:expr, $max_abs_error:expr $(,)?) => { ... };
}Expand description
Marks the test as failed and continues execution if the float given by first argument is not equal to second argument with error tolerance of max_abs_error.
This is a not-fatal failure. The test continues execution even after the macro execution.
This can only be invoked inside tests with the
gtest attribute. The failure must be generated
in the same thread as that running the test itself.
Example:
ⓘ
use googletest::prelude::*;
#[gtest]
fn should_fail() {
expect_near!(1.12345, 1.12346, 1e-6);
println!("This will print!");
}One may include formatted arguments in the failure message:
ⓘ
use googletest::prelude::*;
#[gtest]
fn should_fail() {
let argument = "argument"
expect_near!(1.12345, 1.12346, 1e-6, "custom failure message: {argument}");
println!("This will print!");
}