Hello all,
I wanted to inquire about some behavior in NUnit that confused me at first. I think I now understand why it's doing it, but it seems like it could be worded differently. For reference, I am using NUnit 2.6.3 from NuGet.
I recently started using Constraints with Assert.That, and in this particular case I was trying to verify that something was in range, e.g.:
Assert.That(5.5f, Is.InRange<float>(5.4f, 5.6f));
Which
obviously passes, because 5.5 is between 5.4 and 5.6. What doesn't
work, however, is when I try to swap the values in Is.InRange, e.g.:
Assert.That(5.5f, Is.InRange<float>(5.6f, 5.4f));
I now get a test failure:
Expected in range (5.6, 5.4)
Actual 5.5f
I've
come to the understanding that Is.InRange is checking between a low and
a high, but the ambiguity for me lies in the fact that the Intellisense
for Is.InRange just says "from" and "to", and then the test result says
"expected in range val1, val2". I was confused because reading the test
report says that it is not in range (even though the number itself is)
and it took me a moment to figure out that it was failing because of the
order of arguments. I ended up encountering this when I had a test
involving negative numbers - at first I thought it was having difficulty
with it being negative, so I tried with positive (as above) and got the
same results.
So, in short, I wanted to ask if Is.InRange is
intended to be used as min to max (thus forcing direction), despite that
intellisense and the test report suggest direction independence.
In the meantime, I am using Assert.AreEqual
with a delta, as this particular test is performing a verification that
it be within 1% of a tolerance (but was failing with Is.InRange when
test cases used negative numbers to create the tolerance values).
Thank you.