From 9752db090fc941aee614ad25f6e9b112c0b6977e Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Thu, 22 Oct 2026 08:34:05 -0400 Subject: [PATCH] Document that Is.InRange requires from <= to Documents that `Is.InRange(from, to)` requires `from <= to` and throws `ArgumentException` otherwise, that negative bounds are allowed as long as the range is written in increasing order, and shows how to sort computed bounds before passing them. This reflects the team's decision in the linked thread to keep the current behaviour and clarify it in the docs. Fixes #872 Co-Authored-By: Claude Fable 5.1 --- .../writing-tests/constraints/RangeConstraint.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/articles/nunit/writing-tests/constraints/RangeConstraint.md b/docs/articles/nunit/writing-tests/constraints/RangeConstraint.md index a344693d7..14392cecd 100644 --- a/docs/articles/nunit/writing-tests/constraints/RangeConstraint.md +++ b/docs/articles/nunit/writing-tests/constraints/RangeConstraint.md @@ -28,7 +28,17 @@ Is.InRange(IComparable from, IComparable to) ## Notes 1. The range is **inclusive** on both ends: `Is.InRange(1, 10)` passes for values 1, 10, and everything in between. -2. For exclusive bounds, combine `Is.GreaterThan` and `Is.LessThan` with `And`: +2. `from` must be less than or equal to `to`, otherwise the constraint throws an `ArgumentException`. Negative bounds + are fine, but the range must be written in increasing order: use `Is.InRange(-10, 0)`, not `Is.InRange(0, -10)`. + If the bounds are computed and could end up in either order, sort them first: + + ```csharp + int lower = Math.Min(a, b); + int upper = Math.Max(a, b); + Assert.That(actual, Is.InRange(lower, upper)); + ``` + +3. For exclusive bounds, combine `Is.GreaterThan` and `Is.LessThan` with `And`: ```csharp Assert.That(5, Is.GreaterThan(1).And.LessThan(10)); // Exclusive bounds