]>
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);
155 describe("toIntegerOrInfinity", () => {
156 it("[[Call]] converts nan to zero", () => {
157 assertStrictEquals(toIntegerOrInfinity(NaN
), 0);
160 it("[[Call]] converts negative zero to positive zero", () => {
161 assertStrictEquals(toIntegerOrInfinity(-0), 0);
164 it("[[Call]] drops the fractional part of negative numbers", () => {
165 assertStrictEquals(toIntegerOrInfinity(-1.79), -1);
168 it("[[Call]] returns infinity for infinity", () => {
169 assertStrictEquals(toIntegerOrInfinity(Infinity
), Infinity
);
172 it("[[Call]] returns negative infinity for negative infinity", () => {
173 assertStrictEquals(toIntegerOrInfinity(Infinity
), Infinity
);
177 describe("toNumber", () => {
178 it("[[Call]] converts to a number", () => {
179 assertStrictEquals(toNumber(2n
), 2);
183 describe("toNumeric", () => {
184 it("[[Call]] returns a big·int argument", () => {
185 assertStrictEquals(toNumeric(231n
), 231n
);
188 it("[[Call]] converts to a numeric", () => {
189 assertStrictEquals(toNumeric("231"), 231);
192 it("[[Call]] prefers `valueOf`", () => {
207 describe("toUintN", () => {
208 it("[[Call]] converts to an int·n", () => {
209 assertStrictEquals(toUintN(2, 7n
), 3n
);
212 it("[[Call]] works with numbers", () => {
213 assertStrictEquals(toUintN(2, 7), 3);
This page took 0.12045 seconds and 5 git commands to generate.