assert-json-diff icon indicating copy to clipboard operation
assert-json-diff copied to clipboard

Feature request: approximate float equality

Open Raz-Hemo opened this issue 2 years ago • 1 comments

It would be really cool if we could configure the assertion to ignore tiny differences in float values, e.g.

let assert_config = assert_json_diff::Config::new(assert_json_diff::CompareMode::Strict)
    .numeric_mode(assert_json_diff::NumericMode::AssumeFloat)
    .float_eq_epsilon(0.001);

assert_json_diff::assert_json_matches!(
    serde_json::json!({"a": 1.1000001}),
    serde_json::json!({"a": 1.1000002}),
    assert_config
);

This should work, but right now will fail with

json atoms at path ".a" are not equal:
    lhs:
        1.1000001
    rhs:
        1.1000002

It would also more elegantly solve the discussion over at https://github.com/davidpdrsn/assert-json-diff/issues/17.

Raz-Hemo avatar Jun 27 '22 13:06 Raz-Hemo

I like it!

davidpdrsn avatar Jun 27 '22 17:06 davidpdrsn