-
Notifications
You must be signed in to change notification settings - Fork 34
Equality test should not require arguments to be orderable #163
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
Comments
This is something that has come up before (see #141) and I don't have a great answer. It's something that I adopted from another Arduino testing library: https://github.com./mmurdoch/arduinounit/blob/master/src/ArduinoUnitUtility/Compare.h The implementation on this (as you can see) is a macro, and my understanding from last time I looked into this relates to things like floating-point numbers, in which equality is a difficult thing to capture. I never dove into the subtlety of this topic and would welcome the advice of someone more knowledgable, or at least the set of use cases that show why it should be one way or the other. |
I'd be surprised if this approach improved the situation. Dealing with float representations is vastly, hugely, mind-bogglingly hard. I'd expect that if two floats were not equal, then one would be greater than the other. One common approach is to have a dedicated I feel that the current approach adds no value and prevents otherwise useful equality comparisons. |
I tried to dig into this a little bit, and I'm not sure I have clear idea of how to move forward. In my previous reply, I had forgotten that the dependency on inequality operators is what allows us to simply define a larger set of It sounds like the trick here is come up with an alternate macro for raw equality / inequality (i.e. one not based on The workaround in the meantime is just to |
After some thought I'm very tempted to say that this is the correct course of action. What I'm struggling to come up with is a use case where the un-orderable things you're comparing will fill out the error message in the macro properly. In other words, I can't imagine a type for which the error message would read something like "Expected Can you think of an instance where that wouldn't be the case? |
It seems to me that there are two questions here:
It appears to me that you are suggesting that objects that are orderable typically have good string representations, so can be allowed to compare for equality. It seems to me that these issues are sufficiently unrelated so that one should not influence the other. It seems to me that an error message of "Expected How will we explain this later? It seems to me that if an object understands equality comparison, then we should be able to test it for equality. |
That's part of it. On one hand, anything that implements an But on the other hand, "Expected The other points that I'm considering when it comes to this are
I still haven't made up my mind but I was surprised how deep this particular rabbit hole went. |
[Although I'm continuing the discussion, I can live with the work-around and don't consider this a "hill to die on"!] As you have noted, equality comparison can be a complicated topic and is domain-specific. While some domains, particularly rational numbers, have well-accepted definitions for equality, after that it gets murky. While strings are, in some sense, orderable, is "Ian" == "IAN"? Yes, if you are doing case-insensitive comparisons (for a person name lookup). What about diacritical marks? Is "resume" the same as "résumé"? Yes, if you are doing a dictionary lookup, or simple sorting. And, yes, if the string representation of an object doesn't include all the fields involved in an equality comparison, then you could get something like "Expected We allow If potential ambiguity is a reason to disfavor You are providing a testing framework to developers. Issues of how to define equality are the responsibility of those developers, but should not matter to the testing framework. If I can test for Orderability should not be a determining factor in whether to allow equality comparison. |
Please don't get the wrong impression, I'm very happy to be having this discussion and it's causing me to check quite a few of my own assumptions (in a good way)
This is my main guiding principle here, I want to make sure that any changes I might make to the framework are very durable. I was going to have to explore this topic in depth no matter what. But I think I got to the bottom of the issue on my end -- the framework is reporting |
I'm curious for your thoughts in PR #238 , which adds the ability to compare equality when there isn't a total ordering (greater than / less than operators) in the class. It's mostly an alignment of the operator used, the text printed to the screen, and the name of the function itself. I kept the original ones too, with more descriptive names. Given that this is a reimplementation of a builtin function, I'm trying to ensure that the behavior would be the same in all cases. Please let me know if you can think of other use cases I should be testing. |
I've added comments to the PR. I like aligning the name, operator, and string. I don't think of anything else (but I didn't think too hard since others can be added later as needed). |
cpp/unittest/Compare.h: 13 and 14 seem to test equality in terms of ordering. I'd like to be able to compare two objects that understand equality without implying an order ("Is Adam < Eve?").
In particular, I'd like to implement
operator==()
in my subclass ofDataStreamObserver
so that I can encapsulate the comparison and not have to do it in every test. The work-around isn't too hard, but this seems like an unnecessary limitation.The text was updated successfully, but these errors were encountered: