@nevware21/tripwire - v0.1.8
    Preparing search index...

    Function closeToFunc

    Export assertion functions

    • 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.

      Type Parameters

      • R

      Parameters

      • this: IAssertScope

        The assert scope.

      • expected: number

        The expected number to compare against.

      • delta: number

        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.

      Returns R

      • The assert scope.

      0.1.5

      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