X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/5af99cb7def7f5a9b19db6a8e214920dd233113d..fb3e0d562e2dbe9e3ea911a80bfdabc8851f92b2:/numeric.test.js?ds=sidebyside diff --git a/numeric.test.js b/numeric.test.js index e82e04b..dfb8063 100644 --- a/numeric.test.js +++ b/numeric.test.js @@ -19,15 +19,31 @@ import { clz32, max, min, + NEGATIVE_ZERO, + POSITIVE_ZERO, sgn, toBigInt, toFloat32, + toIntegerOrInfinity, + toIntegralNumber, toIntN, toNumber, toNumeric, toUintN, } from "./numeric.js"; +describe("NEGATIVE_ZERO", () => { + it("[[Get]] is negative zero", () => { + assertStrictEquals(NEGATIVE_ZERO, -0); + }); +}); + +describe("POSITIVE_ZERO", () => { + it("[[Get]] is positive zero", () => { + assertStrictEquals(POSITIVE_ZERO, 0); + }); +}); + describe("abs", () => { it("[[Call]] returns the absolute value", () => { assertStrictEquals(abs(-1), 1); @@ -149,6 +165,63 @@ describe("toIntN", () => { it("[[Call]] works with numbers", () => { assertStrictEquals(toIntN(2, 7), -1); }); + + it("[[Call]] works with non‐integers", () => { + assertStrictEquals(toIntN(2, 7.21), -1); + assertStrictEquals(toIntN(2, Infinity), 0); + }); +}); + +describe("toIntegerOrInfinity", () => { + it("[[Call]] converts nan to zero", () => { + assertStrictEquals(toIntegerOrInfinity(NaN), 0); + }); + + it("[[Call]] converts negative zero to positive zero", () => { + assertStrictEquals(toIntegerOrInfinity(-0), 0); + }); + + it("[[Call]] drops the fractional part of negative numbers", () => { + assertStrictEquals(toIntegerOrInfinity(-1.79), -1); + }); + + it("[[Call]] returns infinity for infinity", () => { + assertStrictEquals(toIntegerOrInfinity(Infinity), Infinity); + }); + + it("[[Call]] returns negative infinity for negative infinity", () => { + assertStrictEquals(toIntegerOrInfinity(-Infinity), -Infinity); + }); + + it("[[Call]] works with big·ints", () => { + assertStrictEquals(toIntegerOrInfinity(2n), 2); + }); +}); + +describe("toIntegralNumber", () => { + it("[[Call]] converts nan to zero", () => { + assertStrictEquals(toIntegralNumber(NaN), 0); + }); + + it("[[Call]] converts negative zero to positive zero", () => { + assertStrictEquals(toIntegralNumber(-0), 0); + }); + + it("[[Call]] drops the fractional part of negative numbers", () => { + assertStrictEquals(toIntegralNumber(-1.79), -1); + }); + + it("[[Call]] returns zero for infinity", () => { + assertStrictEquals(toIntegralNumber(Infinity), 0); + }); + + it("[[Call]] returns zero for negative infinity", () => { + assertStrictEquals(toIntegralNumber(-Infinity), 0); + }); + + it("[[Call]] works with big·ints", () => { + assertStrictEquals(toIntegralNumber(2n), 2); + }); }); describe("toNumber", () => { @@ -189,4 +262,9 @@ describe("toUintN", () => { it("[[Call]] works with numbers", () => { assertStrictEquals(toUintN(2, 7), 3); }); + + it("[[Call]] works with non‐integers", () => { + assertStrictEquals(toUintN(2, 7.21), 3); + assertStrictEquals(toUintN(2, Infinity), 0); + }); });