Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/articles/nunit/writing-tests/constraints/RangeConstraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading