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

expect(...).to.be.closeTo(expected, delta) #156

Open
missingdays opened this issue Aug 5, 2016 · 2 comments · May be fixed by #171
Open

expect(...).to.be.closeTo(expected, delta) #156

missingdays opened this issue Aug 5, 2016 · 2 comments · May be fixed by #171

Comments

@missingdays
Copy link

missingdays commented Aug 5, 2016

chai.js has cool API that allows for checking if two values (including floats) are close to each other.
For example, you can't realy check

expect(0.1+0.2).to.be(0.3)

because there is always rounding error in floating point calculation.
So instead in chai you write

let EPS = 1e-5;
expect(0.1+0.2).to.be.closeTo(0.3, EPS)

This function is oneliner, so this totaly fits "minimalistic" idea.

I know that I can use something like

expect(abs(f1-f2)).to.be.below(EPS)

but this is not very intuitive for reader that my intention is just check that f1 and f2 are just close to each other.

@FlorianWendelborn
Copy link

Regarding the last part, wouldn't you need a Math.abs() for that?

@missingdays
Copy link
Author

@dodekeract Yes, of course. Thanks for pointing that!

@Shayan-P Shayan-P linked a pull request Dec 23, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants