You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Assert.AreEqual overloads for nullable double are not useful #3449
We've had these four methods as far back as NUnit source history goes. The double? overloads are the same as the first two overloads except that they throw InvalidOperationException if you pass null. Since they can't be used to pass null, they don't do anything that the safer double overloads don't do.
Should we obsolete them or fix them? What would fixing them look like?
I agree that if you intend to compare two double/double? values based on a delta, you expect both expected and actual to be non-null, and that obsoleting the double? overload makes the most sense.
Though the double? for me strikes less as a "doesn't make sense" method and more a convenience method, in case a user's data (or class properties) are of type double?. I'm guessing that's why only the actual parameter is a double?. Though if we take this approach, we still don't need both, and might as well remove the non-nullable overload (since double is implicitly converted to double?). Though that wouldn't seem terribly clear to me as a user (or future maintainer) to have the expected and actual params be different data types.
I guess I'm thinking that while it could be disruptive to some users to eventually remove the double? overload, the simplicity it gives to the API (as well as the consistency with other floating-point equality assert APIs) would be worth it.
I'm also thinking that because the overloads we would remove don't behave as you would expect when passed null, if they are used it is probably by accident.
@2r2dAssert.AreEqual(1, myObject?.X); was already exactly equivalent in behavior to Assert.AreEqual(1, myObject.Value.X);without the NotNull assert, which is why we got rid of it. It appeared to do one thing but actually did something different.
Activity
CharliePoole commentedon Dec 27, 2019
The double? overloads were added in April 2008, and released with NUnit 2.5.1. See nunit-legacy/nunitv2@c50f287#diff-b2261783c755ae0aa95cb67fd6162517R1019
I agree they don't make sense.
stevenaw commentedon Feb 2, 2020
I agree that if you intend to compare two
double/double?values based on a delta, you expect bothexpectedandactualto be non-null, and that obsoleting thedouble?overload makes the most sense.Though the
double?for me strikes less as a "doesn't make sense" method and more a convenience method, in case a user's data (or class properties) are of typedouble?. I'm guessing that's why only theactualparameter is adouble?. Though if we take this approach, we still don't need both, and might as well remove the non-nullable overload (sincedoubleis implicitly converted todouble?). Though that wouldn't seem terribly clear to me as a user (or future maintainer) to have theexpectedandactualparams be different data types.I guess I'm thinking that while it could be disruptive to some users to eventually remove the
double?overload, the simplicity it gives to the API (as well as the consistency with other floating-point equality assert APIs) would be worth it.jnm2 commentedon Feb 3, 2020
I'm also thinking that because the overloads we would remove don't behave as you would expect when passed
null, if they are used it is probably by accident.stevenaw commentedon May 18, 2020
Would it make sense to obsolete these now, and remove them in NUnit 4?
jnm2 commentedon May 19, 2020
Obsoleting sounds good to me. /cc @nunit/framework-team
rprouse commentedon May 20, 2020
Sounds good to me.
Antash commentedon Feb 21, 2021
@stevenaw, @rprouse, I want to fix this in case this is not in progress yet.
rprouse commentedon Feb 21, 2021
Sure, but how do you propose to fix? We'd decided to obsolete the method, but we could remove in 4.0.
jnm2 commentedon Feb 21, 2021
Would it be best to do both?
rprouse commentedon Feb 21, 2021
I would agree with @jnm2. We should remove from the master branch (4.0) and obsolete it in the v3.13 branch.
Do you want to do one or both of these @Antash?
Antash commentedon Feb 22, 2021
@rprouse Will do both, no problem!
mikkelbu commentedon Feb 22, 2021
Thanks. I've assigned the issue to you @Antash
2r2d commentedon Jul 15, 2021
This feature makes this code
1 line longer to this:
jnm2 commentedon Jul 16, 2021
@2r2d
Assert.AreEqual(1, myObject?.X);was already exactly equivalent in behavior toAssert.AreEqual(1, myObject.Value.X);without the NotNull assert, which is why we got rid of it. It appeared to do one thing but actually did something different.