Comparison constraints are able to test whether one value is greater or less than another. Comparison constraints work on numeric values, as well as other objects that implement the IComparable interface or - beginning with NUnit 2.5 - IComparable<T>.
Beginning with NUnit 2.5, you may supply your own comparison algorithm through the Using modifier.
Tests that one value is greater than another.
GreaterThanConstraint(object expected)
Is.GreaterThan(object expected) Is.Positive // Equivalent to Is.GreaterThan(0)
...Using(IComparer comparer) ...Using(IComparer<T> comparer) ...Using (Comparison<T> comparer)
Assert.That(7, Is.GreaterThan(3)); Assert.That(myOwnObject, Is.GreaterThan(theExpected).Using(myComparer)); Assert.That(42, Is.Positive);
Tests that one value is greater than or equal to another.
GreaterThanOrEqualConstraint(object expected)
Is.GreaterThanOrEqualTo(object expected) Is.AtLeast(object expected)
...Using(IComparer comparer) ...Using(IComparer<T> comparer) ...Using (Comparison<T> comparer)
Assert.That(7, Is.GreaterThanOrEqualTo(3)); Assert.That(7, Is.AtLeast(3)); Assert.That(7, Is.GreaterThanOrEqualTo(7)); Assert.That(7, Is.AtLeast(7)); Assert.That(myOwnObject, Is.GreaterThanOrEqualTo(theExpected).Using(myComparer));
Tests that one value is less than another.
LessThanConstraint(object expected)
Is.LessThan(object expected) Is.Negative // Equivalent to Is.LessThan(0)
...Using(IComparer comparer) ...Using(IComparer<T> comparer) ...Using (Comparison<T> comparer)
Assert.That(3, Is.LessThan(7)); Assert.That(myOwnObject, Is.LessThan(theExpected).Using(myComparer)); Assert.That(-5, Is.Negative);
Tests that one value is less than or equal to another.
LessThanOrEqualConstraint(object expected)
Is.LessThanOrEqualTo(object expected) Is.AtMost(object expected)
...Using(IComparer comparer) ...Using(IComparer<T> comparer) ...Using (Comparison<T> comparer)
Assert.That(3, Is.LessThanOrEqualTo(7)); Assert.That(3, Is.AtMost(7)); Assert.That(3, Is.LessThanOrEqualTo(3)); Assert.That(3, Is.AtMost(3)); Assert.That(myOwnObject, Is.LessThanOrEqualTo(theExpected).Using(myComparer));
RangeConstraint(IComparable from, IComparable to)
Is.InRange(IComparable from, IComparable to)
...Using(IComparer comparer) ...Using(IComparer<T> comparer) ...Using (Comparison<T> comparer)
int[] iarray = new int[] { 1, 2, 3 } Assert.That( 42, Is.InRange(1, 100) ); Assert.That( iarray, Is.All.InRange(1, 3) ); Assert.That(myOwnObject, Is.InRange(lowExpected, highExpected).Using(myComparer));