-
Notifications
You must be signed in to change notification settings - Fork 157
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
Documentation of the InRange constraint does not mention whether from...to also allows negative ranges, e.g. from 0 to -10 #872
Comments
@maettu-this The range constraint allows negative ranges, but it does not allow range specified in decreasing order, so you have to phrase it like
I your case I guess you need to add logic to determine where to place I'll just see if we get other comments, but otherwise I think we should improve the documentation. I don't think we should support ranges in decreasing order as that does not make sense from a mathematical view - e.g. |
@mikkelbu I can reason the argueing mathematically seen. However, in my opinion
Opposed to a simpler:
And also consider that enabling decreasing ranges wouldn't mean a breaking change, as all existing code is so far required to use increasing ranges, thus is not impacted. |
I also don't feel strongly one way or another about the behavior here, and I'd probably want to experiment a bit at a computer before forming an opinion. If we did decide to keep the existing behavior, we may want to consider renaming the parameters to |
@stevenaw |
@maettu-this Sorry, but I'm starting to lean towards @mikkelbu suggestion as well based on a bit of experimentation with other APIs which people may be used to and expect similar behaviour. It looks as though SQL's WHERE BETWEEN 0 AND -10 I've also seen similar behaviour within dotnet itself. Enumerable.Range() takes a Enumerable.Range(0, -10) I'll also leave this open for a bit to see if there's any other opinions from team members |
My few cents. Unit tests should be independent, i.e. stateless, so it shouldn't matter if you execute one in order 1, 2, 3 or in 3, 2, 1 or even 2, 1, 3 in parallel. |
@manfred-brands That was never in question. This issue is about a single assertion within a single test case. |
I've transferred this to the documenation repo since it sounds like we want to keep the behaviour the same as it is today |
Referring to https://docs.nunit.org/articles/nunit/writing-tests/constraints/RangeConstraint.html, the documentation misses information on whether from...to also allows a negative range, e.g. from 0 to -10. Why can this be important? Sometimes an assertion needs a tolerance, e.g.
Is.InRange(data.Length, (data.Length + (int)(Math.Round(data.Length * tolerance))))
wheretolerance
can be a positive or negative value. From the documentation it is not clear whether this can possibly work, or wetherto
must be a value larger thanfrom
. Only looking at the code (or decompiling) reveals:(NUnit 2.6.4.14350)
I personally would prefer that
InRange
allowed positive and negative ranges.And in any case, documentation thereof should be improved.
The text was updated successfully, but these errors were encountered: