-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Float/double equality comparers #28
Comments
I like it! The next update is adding string-specific comparers, so this will go well as a part of that update. |
Looks like it won't be very straightforward: In particular, "tolerance" equality isn't transitive, so I'm not sure if these can be made into equality operators or not. |
Yeah, it might not make sense to add it to the core library. I was alternatively thinking having an overload accepting a lambda ( My use case is mainly testing. I usually add my own Here's an example what I'd like to do: var comparer = EqualityComparerBuilder
.For<DataSample>()
.EquateBy(sample => sample.Timestamp)
.ThenEquateBy(sample => sample.Value, (a, b) => Math.Abs(a - b) < 0.1f);
Assert.Equal(expected, actual, comparer); EDIT: |
The problem with doing that to I think it does make sense for this library to implement a kind of "best known practice" for floating-point comparisons (tolerance and relative tolerance) but they would be in their own utility class and not ever exposed as actual comparers (and by extension, not be used in |
How about adding special equality comparers for
float
anddouble
types, which allow you to specify the allowed tolerance for difference?As far as I know there are none in .NET or this library.
The text was updated successfully, but these errors were encountered: