assert-json-diff
assert-json-diff copied to clipboard
Feature request: approximate float equality
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.
I like it!