UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

36 lines (31 loc) 1.05 kB
import { mathBound } from "./math-bound.js"; import { itShouldCallAssert, itShouldNotRunDebugWhenDebugIsFalse } from "../../test-util/test-utils.js"; import { Test_setDefaultFlags } from "../../test-util/test_set-default-flags.js"; describe("=> mathBound", () => { beforeEach(() => { Test_setDefaultFlags(); }); it("| bounds the value", () => { expect(mathBound(1, 0, 2)).toBe(1); expect(mathBound(-1, 0, 2)).toBe(0); expect(mathBound(3, 0, 2)).toBe(2); }); describe("=> in production", () => { itShouldNotRunDebugWhenDebugIsFalse(() => mathBound(1, 0, 2)); }); describe("=> in debug", () => { itShouldCallAssert(4, () => mathBound(1, 0, 2)); it("| errors with NaN input", () => { expect(() => mathBound(NaN, 0, 1)).toThrow(); expect(() => mathBound(1, NaN, 1)).toThrow(); expect(() => mathBound(1, 0, NaN)).toThrow(); expect(() => mathBound(1, 1, 0)).toThrow(); }); }); });