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', () {
// Basic comparison assertions
5.assertGreaterThan(3);
3.assertLessThan(5);
5.assertGreaterOrEqual(5);
5.assertLessOrEqual(5);
// Range verification
15.assertBetween(10, 20);
// Mathematical property assertions
10.assertDivisibleBy(2);
10.assertMultipleOf(5);
25.assertPerfectSquare();
// Sign testing
5.assertPositive();
(-5).assertNegative();
0.assertZero();
// Number property testing
4.assertEven();
3.assertOdd();
7.assertPrime();
// With custom messages
5.assertGreaterThan(3, message: 'Custom error message');
});
}
- on
Methods
-
assertBetween(
num min, num max, {String? message}) → void -
Available on num, provided by the NumericAssertions extension
Asserts that this number is betweenmin
andmax
(inclusive). -
assertDivisibleBy(
num divisor, {String? message}) → void -
Available on num, provided by the NumericAssertions extension
Asserts that this number is evenly divisible bydivisor
. -
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 tovalue
. -
assertGreaterThan(
num value, {String? message}) → void -
Available on num, provided by the NumericAssertions extension
Asserts that this number is greater thanvalue
. -
assertLessOrEqual(
num value, {String? message}) → void -
Available on num, provided by the NumericAssertions extension
Asserts that this number is less than or equal tovalue
. -
assertLessThan(
num value, {String? message}) → void -
Available on num, provided by the NumericAssertions extension
Asserts that this number is less thanvalue
. -
assertMultipleOf(
num factor, {String? message}) → void -
Available on num, provided by the NumericAssertions extension
Asserts that this number is a multiple offactor
. -
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.