-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
Don’t fail when comparing +0 and -0 #223
Comments
I'm a bit surprised that you didn't open this bug on Mocha's diff viewer. The issue is that they are different values, and when testing for when two values are equal in JavaScript, the spec says to treat them differently. If you want loose equality, use |
Thank you for the reply.
I am using expect(0).equal(-0); // does not throw
expect(0).eql(-0); // throws
expect([0]).eql([-0]); // throws It seems to me that I’m not the only one who is confused.
@domenic, I am sure that you know the ES spec very well, but let me add some context: chai’s docs state that
I cannot find any reference to the SameValue algorithm here. What I see is the strict equality operator, which uses Strict Equality Comparison. “This algorithm differs from the SameValue Algorithm (7.2.3) in its treatment of signed zeroes and NaNs.” Apart from that, the major part of appliances of SameValue in the specs relate to property definition/access (with strings) and prototype lookups. The only “equality test” that uses it is I asked about the problems that this comparison solved in chai because I am sure that from time to time somebody actually wants to distinguish between signed zeros. Maybe a Besides spec internals I think that the current behaviour is unexpected and confusing and lets tests of mathematical calculations fail in unexpected ways. I see the value of not failing the claimed strict equality test (
I’ve thought about doing that. If I would test for SameValue I would regard this as a mocha issue and file a ticket there. But I don’t. I’m not calling this a bug in chai, since it is a design decision. I just think it does not help and adds confusion, and therefore ask to remove this behaviour again. |
At the very least, it seems like this should be documented (in the documentation, not the issues). |
@skeggse This isn't Mocha's fault - Chai throws |
I'm closing this, as #298 covers @Lexicality's points - Chai will now explicitly tell you that If anyone doesn't like that this has been closed, please speak up - or raise a new issue. |
LGTM |
I still don’t think this behaviour is more useful than treating At least it’s documented now. |
I think it matters in a testing framework that is trying to help you find potential subtle bugs. |
I’d be interested to hear of any example of a subtle bug that could be caused by negative zeros in a JavaScript program. |
@csnover try |
I’d like to know whether failing equality tests for positive and negative zero solved some real world problems.
In my case it just lead to a very long debugging session, since mocha’s diff wasn’t showing anything for two compared 2d-matrices (arrays of six numbers).
I’d argue that for most, if not all, mathematical cases the distinction between positive and negative zero is irrelevant. It’s an implementation detail of IEEE 754 floating point numbers, and did more harm than good for my personal case.
I’ve tried to find any issues referencing this distinction, but only found the change log mentioning this. If there aren’t very good reasons to have this behavior, please change it back.
The text was updated successfully, but these errors were encountered: