X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/5af99cb7def7f5a9b19db6a8e214920dd233113d..2aaa51c0d16852726d2402bfb7953fab182afc01:/numeric.test.js diff --git a/numeric.test.js b/numeric.test.js index e82e04b..96f51c1 100644 --- a/numeric.test.js +++ b/numeric.test.js @@ -22,6 +22,7 @@ import { sgn, toBigInt, toFloat32, + toIntegerOrInfinity, toIntN, toNumber, toNumeric, @@ -149,6 +150,33 @@ 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); + }); }); describe("toNumber", () => { @@ -189,4 +217,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); + }); });