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
private struct C : IComparable<float>
{
public C(float v) => this.V = v;
public float V { get; }
public int CompareTo(float other) => this.V.CompareTo(other);
}
public void TestMethod()
{
C x = new C(1.1f);
float y = 1.0f;
Assert.That(x.CompareTo(y), Is.GreaterThan(0));
Assert.That(x,Is.GreaterThan(y));
}
The last test fails because NunitComparer.Compare checks y is IComparable before checking for xType.CompareTo(yType) and hence calls the Single.CompareTo(Object) method instead of C.CompareTo(float) method.
Can I switch the order such that the two tests on IComparable are last thereby preferencing IComparable<T> over IComparable?
I you think there are no unforeseen issues, I will raise a PR.
The text was updated successfully, but these errors were encountered:
This sounds good to me. I think we will only be preferring the most specific comparison available, and if that isn't what someone wants, they will have to use a custom comparer or do the comparison outside NUnit.
Uh oh!
There was an error while loading. Please reload this page.
Giving the following code:
The last test fails because
NunitComparer.Compare
checksy is IComparable
before checking forxType.CompareTo(yType)
and hence calls theSingle.CompareTo(Object)
method instead ofC.CompareTo(float)
method.Can I switch the order such that the two tests on
IComparable
are last thereby preferencingIComparable<T>
overIComparable
?I you think there are no unforeseen issues, I will raise a PR.
The text was updated successfully, but these errors were encountered: