NumericAssertions extension

Extension providing assertion methods for numeric values.

This extension adds various assertion methods to num types to help with testing numeric conditions. Each method performs a specific validation and throws a test failure if the condition is not met.

Example usage:

void main() {
  test('numeric assertions', () {
    5.assertGreaterThan(3);
    10.assertDivisibleBy(2);
    7.assertPrime();
  });
}
on

Methods

assertBetween(num min, num max, {String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is between min and max (inclusive).
assertDivisibleBy(num divisor, {String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is evenly divisible by divisor.
assertEven({String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is even.
assertGreaterOrEqual(num value, {String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is greater than or equal to value.
assertGreaterThan(num value, {String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is greater than value.
assertLessOrEqual(num value, {String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is less than or equal to value.
assertLessThan(num value, {String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is less than value.
assertMultipleOf(num factor, {String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is a multiple of factor.
assertNegative({String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is negative (less than zero).
assertOdd({String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is odd.
assertPerfectSquare({String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is a perfect square.
assertPositive({String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is positive (greater than zero).
assertPrime({String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is prime.
assertZero({String? message}) → void

Available on num, provided by the NumericAssertions extension

Asserts that this number is exactly zero.