Skip to content

Documentation of the InRange constraint does not mention whether from...to also allows negative ranges, e.g. from 0 to -10 #872

Open
@maettu-this

Description

@maettu-this

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)))) where tolerance can be a positive or negative value. From the documentation it is not clear whether this can possibly work, or wether to must be a value larger than from. Only looking at the code (or decompiling) reveals:

if (from.CompareTo(to) > 0)
{
	throw new ArgumentException("from must be less than to");
}

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions