Skip to content
Cyrille DUPUYDAUBY edited this page Feb 3, 2018 · 5 revisions

The following checks are available for numeric types: int, long, double, decimal, float, short, byte, uint, ulong, ushort, sbyte

Properties

IsZero()

Checks that the sut is zero, fails otherwise.

// This check succeeds
Check.That(0).IsZero();
// This check fails
Check.That(1).IsZero();

IsNotZero()

Checks that the sut is not zero, fails otherwise.

// This check succeeds
Check.That(1).IsNotZero();
// This check fails
Check.That(0).IsNotZero();

IsPositiveOrZero()

Checks that the sut is 0 or more, fails otherwise.

// This check succeeds
Check.That(1).IsPositiveOrZero();
// This check fails
Check.That(-1).IsPositiveOrZero();

IsStrictlyPositive()

Checks that the sut is more than 0, fails otherwise.

// This check succeeds
Check.That(1).IsStrictlyPositive();
// This check fails
Check.That(0).IsStrictlyPositive();

IsNegativeOrZero()

Checks that the sut is 0 or less, fails otherwise.

// This check succeeds
Check.That(-1).IsNegativeOrZero();
// This check fails
Check.That(1).IsNegativeOrZero();

IsStrictlyNegative()

Checks that the sut is negative, fails otherwise.

// This check succeeds
Check.That(-1).IsStrictlyNegative();
// This check fails
Check.That(1).IsStrictlyNegative();

Comparison checks

IsStrictlyGreaterThan(expected)

Checks that the sut is greater than the expected value, fails if less or same.

// This check succeeds
Check.That(-1).IsStrictlyGreaterThan(-5);
// This check fails
Check.That(-1).IsStrictlyGreaterThan(0);

IsStrictlyLessThan(expected)

Checks that the sut is less than the expected value, fails if greater or same.

// This check succeeds
Check.That(-1).IsStrictlyLessThan(0);
// This check fails
Check.That(-1).IsStrictlyLessThan(-5);

Floating Checks

IsCloseTo(expected, tolerance)

Checks that the sut has a value close to expected, such as Math.Abs(expected-sut)<=tolerance, fails otherwise.

// This check succeeds
Check.That(1.1).IsCloseTo(1, .2);
// This check fails
Check.That(1.3).IsCloseTo(1, .2);

IsFinite()

Checks that the sut is a finite number, fails otherwise.

// This check succeeds
Check.That(1.0).IsFinite();
// This check fails
Check.That(1.0/0).IsFinite();

IsNan()

Checks that the sut is NotANumber, fails otherwise.

// This check succeeds
Check.That(0.0/0).IsNan();
// This check fails
Check.That(0.0).IsNan();
Clone this wiki locally