Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Feature request: approximate float equality #29

Open

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

  1. davidpdrsn commented on Jun 27, 2022

    @davidpdrsn
    Owner

    I like it!

  2. added
    help wanted
    on Jun 27, 2022
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 wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions