]>
Lady’s Gitweb - Pisces/blob - numeric.test.js
1 // ♓🌟 Piscēs ∷ numeric.test.js
2 // ====================================================================
4 // Copyright © 2022 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
15 } from "./dev-deps.js";
33 } from "./numeric.js";
35 describe("NEGATIVE_ZERO", () => {
36 it("[[Get]] is negative zero", () => {
37 assertStrictEquals(NEGATIVE_ZERO
, -0);
41 describe("POSITIVE_ZERO", () => {
42 it("[[Get]] is positive zero", () => {
43 assertStrictEquals(POSITIVE_ZERO
, 0);
47 describe("abs", () => {
48 it("[[Call]] returns the absolute value", () => {
49 assertStrictEquals(abs(-1), 1);
52 it("[[Call]] works with big·ints", () => {
53 const bn
= BigInt(Number
.MAX_SAFE_INTEGER
) + 2n
;
54 assertStrictEquals(abs(-bn
), bn
);
58 describe("atan2", () => {
59 it("[[Call]] returns the atan2", () => {
60 assertStrictEquals(atan2(6, 9), Math
.atan2(6, 9));
63 it("[[Call]] works with big·ints", () => {
64 assertStrictEquals(atan2(6n
, 9n
), Math
.atan2(6, 9));
68 describe("clz32", () => {
69 it("[[Call]] returns the clz32", () => {
70 assertStrictEquals(clz32(1 << 28), 3);
73 it("[[Call]] works with big·ints", () => {
74 assertStrictEquals(clz32(1n
<< 28n
), 3);
78 describe("max", () => {
79 it("[[Call]] returns the largest number", () => {
80 assertStrictEquals(max(1, -6, 92, -Infinity
, 0), 92);
83 it("[[Call]] returns the largest big·int", () => {
84 assertStrictEquals(max(1n
, -6n
, 92n
, 0n
), 92n
);
87 it("[[Call]] returns nan if any argument is nan", () => {
88 assertStrictEquals(max(0, NaN
, 1), NaN
);
91 it("[[Call]] returns -Infinity when called with no arguments", () => {
92 assertStrictEquals(max(), -Infinity
);
95 it("[[Call]] throws if both big·int and number arguments are provided", () => {
96 assertThrows(() => max(-Infinity
, 0n
));
100 describe("min", () => {
101 it("[[Call]] returns the largest number", () => {
102 assertStrictEquals(min(1, -6, 92, Infinity
, 0), -6);
105 it("[[Call]] returns the largest big·int", () => {
106 assertStrictEquals(min(1n
, -6n
, 92n
, 0n
), -6n
);
109 it("[[Call]] returns nan if any argument is nan", () => {
110 assertStrictEquals(min(0, NaN
, 1), NaN
);
113 it("[[Call]] returns Infinity when called with no arguments", () => {
114 assertStrictEquals(min(), Infinity
);
117 it("[[Call]] throws if both big·int and number arguments are provided", () => {
118 assertThrows(() => min(Infinity
, 0n
));
122 describe("sgn", () => {
123 it("[[Call]] returns the sign", () => {
124 assertStrictEquals(sgn(Infinity
), 1);
125 assertStrictEquals(sgn(-Infinity
), -1);
126 assertStrictEquals(sgn(0), 0);
127 assertStrictEquals(sgn(-0), -0);
128 assertStrictEquals(sgn(NaN
), NaN
);
131 it("[[Call]] works with big·ints", () => {
132 assertStrictEquals(sgn(0n
), 0n
);
133 assertStrictEquals(sgn(92n
), 1n
);
134 assertStrictEquals(sgn(-92n
), -1n
);
138 describe("toBigInt", () => {
139 it("[[Call]] converts to a big·int", () => {
140 assertStrictEquals(toBigInt(2), 2n
);
144 describe("toFloat32", () => {
145 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
147 toFloat32(562949953421313),
148 Math
.fround(562949953421313),
152 it("[[Call]] works with big·ints", () => {
154 toFloat32(562949953421313n
),
155 Math
.fround(562949953421313),
160 describe("toIntN", () => {
161 it("[[Call]] converts to an int·n", () => {
162 assertStrictEquals(toIntN(2, 7n
), -1n
);
165 it("[[Call]] works with numbers", () => {
166 assertStrictEquals(toIntN(2, 7), -1);
169 it("[[Call]] works with non‐integers", () => {
170 assertStrictEquals(toIntN(2, 7.21), -1);
171 assertStrictEquals(toIntN(2, Infinity
), 0);
175 describe("toIntegerOrInfinity", () => {
176 it("[[Call]] converts nan to zero", () => {
177 assertStrictEquals(toIntegerOrInfinity(NaN
), 0);
180 it("[[Call]] converts negative zero to positive zero", () => {
181 assertStrictEquals(toIntegerOrInfinity(-0), 0);
184 it("[[Call]] drops the fractional part of negative numbers", () => {
185 assertStrictEquals(toIntegerOrInfinity(-1.79), -1);
188 it("[[Call]] returns infinity for infinity", () => {
189 assertStrictEquals(toIntegerOrInfinity(Infinity
), Infinity
);
192 it("[[Call]] returns negative infinity for negative infinity", () => {
193 assertStrictEquals(toIntegerOrInfinity(-Infinity
), -Infinity
);
196 it("[[Call]] works with big·ints", () => {
197 assertStrictEquals(toIntegerOrInfinity(2n
), 2);
201 describe("toIntegralNumber", () => {
202 it("[[Call]] converts nan to zero", () => {
203 assertStrictEquals(toIntegralNumber(NaN
), 0);
206 it("[[Call]] converts negative zero to positive zero", () => {
207 assertStrictEquals(toIntegralNumber(-0), 0);
210 it("[[Call]] drops the fractional part of negative numbers", () => {
211 assertStrictEquals(toIntegralNumber(-1.79), -1);
214 it("[[Call]] returns zero for infinity", () => {
215 assertStrictEquals(toIntegralNumber(Infinity
), 0);
218 it("[[Call]] returns zero for negative infinity", () => {
219 assertStrictEquals(toIntegralNumber(-Infinity
), 0);
222 it("[[Call]] works with big·ints", () => {
223 assertStrictEquals(toIntegralNumber(2n
), 2);
227 describe("toNumber", () => {
228 it("[[Call]] converts to a number", () => {
229 assertStrictEquals(toNumber(2n
), 2);
233 describe("toNumeric", () => {
234 it("[[Call]] returns a big·int argument", () => {
235 assertStrictEquals(toNumeric(231n
), 231n
);
238 it("[[Call]] converts to a numeric", () => {
239 assertStrictEquals(toNumeric("231"), 231);
242 it("[[Call]] prefers `valueOf`", () => {
257 describe("toUintN", () => {
258 it("[[Call]] converts to an int·n", () => {
259 assertStrictEquals(toUintN(2, 7n
), 3n
);
262 it("[[Call]] works with numbers", () => {
263 assertStrictEquals(toUintN(2, 7), 3);
266 it("[[Call]] works with non‐integers", () => {
267 assertStrictEquals(toUintN(2, 7.21), 3);
268 assertStrictEquals(toUintN(2, Infinity
), 0);
This page took 0.073914 seconds and 5 git commands to generate.