]>
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";
30 } from "./numeric.js";
32 describe("abs", () => {
33 it("[[Call]] returns the absolute value", () => {
34 assertStrictEquals(abs(-1), 1);
37 it("[[Call]] works with big·ints", () => {
38 const bn
= BigInt(Number
.MAX_SAFE_INTEGER
) + 2n
;
39 assertStrictEquals(abs(-bn
), bn
);
43 describe("atan2", () => {
44 it("[[Call]] returns the atan2", () => {
45 assertStrictEquals(atan2(6, 9), Math
.atan2(6, 9));
48 it("[[Call]] works with big·ints", () => {
49 assertStrictEquals(atan2(6n
, 9n
), Math
.atan2(6, 9));
53 describe("clz32", () => {
54 it("[[Call]] returns the clz32", () => {
55 assertStrictEquals(clz32(1 << 28), 3);
58 it("[[Call]] works with big·ints", () => {
59 assertStrictEquals(clz32(1n
<< 28n
), 3);
63 describe("max", () => {
64 it("[[Call]] returns the largest number", () => {
65 assertStrictEquals(max(1, -6, 92, -Infinity
, 0), 92);
68 it("[[Call]] returns the largest big·int", () => {
69 assertStrictEquals(max(1n
, -6n
, 92n
, 0n
), 92n
);
72 it("[[Call]] returns nan if any argument is nan", () => {
73 assertStrictEquals(max(0, NaN
, 1), NaN
);
76 it("[[Call]] returns -Infinity when called with no arguments", () => {
77 assertStrictEquals(max(), -Infinity
);
80 it("[[Call]] throws if both big·int and number arguments are provided", () => {
81 assertThrows(() => max(-Infinity
, 0n
));
85 describe("min", () => {
86 it("[[Call]] returns the largest number", () => {
87 assertStrictEquals(min(1, -6, 92, Infinity
, 0), -6);
90 it("[[Call]] returns the largest big·int", () => {
91 assertStrictEquals(min(1n
, -6n
, 92n
, 0n
), -6n
);
94 it("[[Call]] returns nan if any argument is nan", () => {
95 assertStrictEquals(min(0, NaN
, 1), NaN
);
98 it("[[Call]] returns Infinity when called with no arguments", () => {
99 assertStrictEquals(min(), Infinity
);
102 it("[[Call]] throws if both big·int and number arguments are provided", () => {
103 assertThrows(() => min(Infinity
, 0n
));
107 describe("sgn", () => {
108 it("[[Call]] returns the sign", () => {
109 assertStrictEquals(sgn(Infinity
), 1);
110 assertStrictEquals(sgn(-Infinity
), -1);
111 assertStrictEquals(sgn(0), 0);
112 assertStrictEquals(sgn(-0), -0);
113 assertStrictEquals(sgn(NaN
), NaN
);
116 it("[[Call]] works with big·ints", () => {
117 assertStrictEquals(sgn(0n
), 0n
);
118 assertStrictEquals(sgn(92n
), 1n
);
119 assertStrictEquals(sgn(-92n
), -1n
);
123 describe("toBigInt", () => {
124 it("[[Call]] converts to a big·int", () => {
125 assertStrictEquals(toBigInt(2), 2n
);
129 describe("toFloat32", () => {
130 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
132 toFloat32(562949953421313),
133 Math
.fround(562949953421313),
137 it("[[Call]] works with big·ints", () => {
139 toFloat32(562949953421313n
),
140 Math
.fround(562949953421313),
145 describe("toIntN", () => {
146 it("[[Call]] converts to an int·n", () => {
147 assertStrictEquals(toIntN(2, 7n
), -1n
);
150 it("[[Call]] works with numbers", () => {
151 assertStrictEquals(toIntN(2, 7), -1);
154 it("[[Call]] works with non‐integers", () => {
155 assertStrictEquals(toIntN(2, 7.21), -1);
156 assertStrictEquals(toIntN(2, Infinity
), 0);
160 describe("toIntegerOrInfinity", () => {
161 it("[[Call]] converts nan to zero", () => {
162 assertStrictEquals(toIntegerOrInfinity(NaN
), 0);
165 it("[[Call]] converts negative zero to positive zero", () => {
166 assertStrictEquals(toIntegerOrInfinity(-0), 0);
169 it("[[Call]] drops the fractional part of negative numbers", () => {
170 assertStrictEquals(toIntegerOrInfinity(-1.79), -1);
173 it("[[Call]] returns infinity for infinity", () => {
174 assertStrictEquals(toIntegerOrInfinity(Infinity
), Infinity
);
177 it("[[Call]] returns negative infinity for negative infinity", () => {
178 assertStrictEquals(toIntegerOrInfinity(Infinity
), Infinity
);
182 describe("toNumber", () => {
183 it("[[Call]] converts to a number", () => {
184 assertStrictEquals(toNumber(2n
), 2);
188 describe("toNumeric", () => {
189 it("[[Call]] returns a big·int argument", () => {
190 assertStrictEquals(toNumeric(231n
), 231n
);
193 it("[[Call]] converts to a numeric", () => {
194 assertStrictEquals(toNumeric("231"), 231);
197 it("[[Call]] prefers `valueOf`", () => {
212 describe("toUintN", () => {
213 it("[[Call]] converts to an int·n", () => {
214 assertStrictEquals(toUintN(2, 7n
), 3n
);
217 it("[[Call]] works with numbers", () => {
218 assertStrictEquals(toUintN(2, 7), 3);
221 it("[[Call]] works with non‐integers", () => {
222 assertStrictEquals(toUintN(2, 7.21), 3);
223 assertStrictEquals(toUintN(2, Infinity
), 0);
This page took 0.067697 seconds and 5 git commands to generate.