-
Notifications
You must be signed in to change notification settings - Fork 731
Be more strict when trying to convert types in IsSameOrEqualTo #1202
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
Conversation
dennisdoomen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I was planning to fix this thing in the same way this weekend.
|
I came to think that this might break (undocumented?) runtime behavior for some. With the current code, the second test of |
Can't find that one. |
|
|
Duh. Wasn't looking in the PR itself. |
Maybe we should be much more restrictive in what we consider equal. In other words, list the types for which we apply the rules. |
When comparing whether two objects are equal, a conversion should be precision preserving. Two examples of comparisons that currently unexpectedly passes: * `10` is not equal to `true` even though `10` is convertible to `true` as `true` is not convertible to `10`. * `0.02` is not equal to `0`, as that is due to truncation when converting the `double` into an `int`.
|
I've updated the PR to use a white-list of numeric types, for which we will try conversion between. |
Before fluentassertions#1202 we had an asymmetry where: * `When_comparing_an_enum_and_a_numeric_for_equality_it_should_not_throw` passed, but * `When_comparing_a_numeric_and_an_enum_for_equality_it_should_not_throw` failed. After fluentassertions#1202 both of them failed. This PR makes them both pass to minimize the change of behavior while fixing the asymmetry. fluentassertions#1204 has a discussion of how to compare enums, integers and strings.
When comparing whether two objects are equal, a conversion should be precision preserving.
Two examples of comparisons that currently unexpectedly passes:
10is not equal totrueeven though10is convertible totrueastrueis not convertible to10.0.02is not equal to0, as that is due to truncation when converting thedoubleinto anint.This fixes #1010
This fixes #1183