Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect number comparison in lenient json comparisons #2793

Closed
Tracked by #2867
zakhenry opened this issue Jan 22, 2022 · 0 comments
Closed
Tracked by #2867

Incorrect number comparison in lenient json comparisons #2793

zakhenry opened this issue Jan 22, 2022 · 0 comments
Milestone

Comments

@zakhenry
Copy link
Contributor

Which version of Kotest are you using
master

This is best explained with a failing test so here goes:

            shouldFail {
               "1.0E-3" shouldEqualJson "0.0001"
            }
            "1.0E-4" shouldEqualJson "0.0001"

both of these assertions fail - 1.0E-3 is considered equal to 0.0001 (off by one zero) and 1.0E-4 really is 0.0001 but the assertion doesn't think so.

Digging in to this there are two separate issues:

  1. the lenient option is using a regex to trim irrelevant trailing zeroes after the decimal point, but doesn't use a $ (end of input) sigil so all the intervening (significant) zeroes are stripped
  2. the comparison of scientific notation numbers does not deal with the scenario where one of expected or actual is denoted with exponential numbers and the other is not, but parsing as Double does not turn it back to regular notation.

I have a fix, so will raise that as a PR shortly, but raising the issue in case my PR is not accepted and someone else wants to take a crack.

zakhenry pushed a commit to zakhenry/kotest that referenced this issue Jan 22, 2022
zakhenry pushed a commit to zakhenry/kotest that referenced this issue Jan 22, 2022
@sksamuel sksamuel added this to the 5.1.1 milestone Jan 22, 2022
@sksamuel sksamuel modified the milestones: 5.1.1, 5.2 Mar 12, 2022
@sksamuel sksamuel mentioned this issue Mar 12, 2022
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants