Asserts that the target is a number close to the given number within a specified delta. This is useful for floating-point comparisons where exact equality is not guaranteed.
The assert scope.
The expected number to compare against.
The maximum allowed difference between actual and expected. Note: A negative delta will never result in a passing assertion since the absolute difference is always non-negative.
OptionalevalMsg: MsgSource
The message to display if the assertion fails.
import { assert } from "@nevware21/tripwire";
assert(1.5).is.closeTo(1.0, 0.5); // Passes - difference is 0.5
assert(10).is.closeTo(20, 20); // Passes - difference is 10
assert(-10).is.closeTo(20, 30); // Passes - difference is 30
assert(2).is.closeTo(1.0, 0.5); // Fails - difference is 1.0
assert([1.5]).is.closeTo(1.0, 0.5); // Fails - not a number
Export assertion functions