Skip to content

Comparison Operations

Compare numeric values with these assertions.

Operands of different numeric types are promoted to a common type before comparing, following D’s usual arithmetic conversions, so mixing types works as expected:

double value = 3.22681e+10;
expect(value).to.be.greaterThan(0); // double vs int
expect(-1).to.be.lessThan(1u); // signed vs unsigned, compared by value

greaterThan / above / greater

Asserts that a value is greater than the expected value.

expect(42).to.be.greaterThan(10);
expect(42).to.be.above(10); // alias
expect(42).to.be.greater(10); // alias

greaterOrEqualTo / greaterOrEqual

Asserts that a value is greater than or equal to the expected value.

expect(42).to.be.greaterOrEqualTo(42);
expect(42).to.be.greaterOrEqual(10); // alias

lessThan / below / less

Asserts that a value is less than the expected value.

expect(10).to.be.lessThan(42);
expect(10).to.be.below(42); // alias
expect(10).to.be.less(42); // alias

lessOrEqualTo / lessOrEqual

Asserts that a value is less than or equal to the expected value.

expect(42).to.be.lessOrEqualTo(42);
expect(10).to.be.lessOrEqual(42); // alias

between

Asserts that a value is between two bounds (exclusive).

expect(42).to.be.between(10, 100);

within

Asserts that a value is within a range (inclusive).

expect(42).to.be.within(40, 45);