Skip to content

Feature request: approximate float equality #29

Description

@Raz-Hemo

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 #17.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions