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

Add float_compare_mode for comparing floats with epsilon

Open JonathanMurray opened this issue 2 years ago • 2 comments

Solves https://github.com/davidpdrsn/assert-json-diff/issues/29

JonathanMurray avatar Jun 27 '23 08:06 JonathanMurray

Hi! I have some test-cases that need to account for small differences in floating point values. The need is very similar to what's suggested in https://github.com/davidpdrsn/assert-json-diff/issues/29, so I took a stab at implementing it here.

I started out with the less verbose syntax .float_eq_epsilon(0.001), but changed it to an enum midway to try to maintain more consistency with the existing options, and make it easier to document the two cases (what happens if you specify an epsilon, and what happens if you don't). If we prefer the more concise version, that's easy to change though.

Does the approach look sensible, or am I missing some nuance?

Oh, I also had to pull in an extra dependency. Seemed reasonable to me, not trying to implement the float comparisons by hand, although it pained me to grow the list of dependencies from 2 to 3 😄

JonathanMurray avatar Jun 27 '23 09:06 JonathanMurray

@davidpdrsn Does this implementation look reasonable to you?

JonathanMurray avatar Aug 02 '23 14:08 JonathanMurray