Numbers
API
Greater than
You can use the greaterThan method to check if a number is greater than another.
import { expect } from "@rbxts/expect";
expect(10).to.be.greaterThan(5);
expect(10).to.be.gt(5);
expect(10).to.be.above(5);
Example error
Expected '1' to be greater than '2'
Greater than or equal to
You can use the greaterThanOrEqualTo method to check if a number is greater than or equal to another.
import { expect } from "@rbxts/expect";
expect(10).to.be.greaterThanOrEqualTo(10);
expect(10).to.be.gte(5);
expect(10).to.be.at.least(5);
Example error
Expected '1' to be greater than or equal to '2'
Less than
You can use the lessThan method to check if a number is less than another.
import { expect } from "@rbxts/expect";
expect(5).to.be.lessThan(10);
expect(5).to.be.lt(10);
expect(5).to.be.below(10);
Example error
Expected '2' to be less than '1'
Less than or equal to
You can use the lessThanOrEqualTo method to check if a number is less than or equal to another.
import { expect } from "@rbxts/expect";
expect(5).to.be.lessThanOrEqualTo(5);
expect(5).to.be.lte(10);
expect(5).to.be.at.most(10);
Example error
Expected '2' to be less than or equal to '1'
Negative
You can use the negative method to check if a number is less than zero.
import { expect } from "@rbxts/expect";
expect(-5).to.be.negative();
expect(0).to.not.be.negative();
expect(5).to.not.be.negative();
Example error
Expected '1' to be a negative number, but it was positive
Positive
You can use the positive method to check if a number is greater than zero.
import { expect } from "@rbxts/expect";
expect(5).to.be.positive();
expect(0).to.not.be.positive();
expect(-5).to.not.be.positive();
Example error
Expected '-1' to be a positive number, but it was negative
Even
You can use the even method to check if a number is even.
import { expect } from "@rbxts/expect";
expect(2).to.be.even();
expect(4).to.be.even();
expect(-20).to.be.even();
Example error
Expected '3' to be even, but it was odd.
Odd
You can use the odd method to check if a number is odd.
import { expect } from "@rbxts/expect";
expect(1).to.be.odd();
expect(3).to.be.odd();
expect(-11).to.be.odd();
Example error
Expected '2' to be odd, but it was even.
Between
You can use the between or within methods to check if a number is within a specified range (inclusively).
import { expect } from "@rbxts/expect";
expect(5).to.be.within(1, 10);
expect(0).to.be.between(0, 100);
expect(-10).to.be.within(-20, 20);
Example error
Expected '10' to be a number between 5 and 8, but it was too high.
Finite
You can use the finite method to check if a number is within +-math.huge
import { expect } from "@rbxts/expect";
expect(5).to.be.finite();
expect(-5).to.be.finite();
expect("5").to.not.be.finite();
expect(math.huge).to.not.be.finite();
Example error
Expected 'inf' to be a finite number, but it was 'math.huge'
Near
You can use the near or closeTo methods to check if a number is within a margin of another.
When a margin isn't specified, epsilon is used instead (per IEEE 754 float64).
import { expect } from "@rbxts/expect";
expect(5).to.be.near(5 + 1e-8);
expect(1.5).to.be.near(1, 0.5);
expect(math.pi).to.be.near(3, 0.2);
expect(-10).to.be.closeTo(0, 15);
Example error
Expected '1' to be a number close to '0', but it was too high