]>
Lady’s Gitweb - Pisces/blob - numeric.test.js
6c58d04d7971187b2ca04d5fbabfb97aa29bb92b
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";
32 } from "./numeric.js";
34 describe("NEGATIVE_ZERO", () => {
35 it("[[Get]] is negative zero", () => {
36 assertStrictEquals(NEGATIVE_ZERO
, -0);
40 describe("POSITIVE_ZERO", () => {
41 it("[[Get]] is positive zero", () => {
42 assertStrictEquals(POSITIVE_ZERO
, 0);
46 describe("abs", () => {
47 it("[[Call]] returns the absolute value", () => {
48 assertStrictEquals(abs(-1), 1);
51 it("[[Call]] works with big·ints", () => {
52 const bn
= BigInt(Number
.MAX_SAFE_INTEGER
) + 2n
;
53 assertStrictEquals(abs(-bn
), bn
);
57 describe("atan2", () => {
58 it("[[Call]] returns the atan2", () => {
59 assertStrictEquals(atan2(6, 9), Math
.atan2(6, 9));
62 it("[[Call]] works with big·ints", () => {
63 assertStrictEquals(atan2(6n
, 9n
), Math
.atan2(6, 9));
67 describe("clz32", () => {
68 it("[[Call]] returns the clz32", () => {
69 assertStrictEquals(clz32(1 << 28), 3);
72 it("[[Call]] works with big·ints", () => {
73 assertStrictEquals(clz32(1n
<< 28n
), 3);
77 describe("max", () => {
78 it("[[Call]] returns the largest number", () => {
79 assertStrictEquals(max(1, -6, 92, -Infinity
, 0), 92);
82 it("[[Call]] returns the largest big·int", () => {
83 assertStrictEquals(max(1n
, -6n
, 92n
, 0n
), 92n
);
86 it("[[Call]] returns nan if any argument is nan", () => {
87 assertStrictEquals(max(0, NaN
, 1), NaN
);
90 it("[[Call]] returns -Infinity when called with no arguments", () => {
91 assertStrictEquals(max(), -Infinity
);
94 it("[[Call]] throws if both big·int and number arguments are provided", () => {
95 assertThrows(() => max(-Infinity
, 0n
));
99 describe("min", () => {
100 it("[[Call]] returns the largest number", () => {
101 assertStrictEquals(min(1, -6, 92, Infinity
, 0), -6);
104 it("[[Call]] returns the largest big·int", () => {
105 assertStrictEquals(min(1n
, -6n
, 92n
, 0n
), -6n
);
108 it("[[Call]] returns nan if any argument is nan", () => {
109 assertStrictEquals(min(0, NaN
, 1), NaN
);
112 it("[[Call]] returns Infinity when called with no arguments", () => {
113 assertStrictEquals(min(), Infinity
);
116 it("[[Call]] throws if both big·int and number arguments are provided", () => {
117 assertThrows(() => min(Infinity
, 0n
));
121 describe("sgn", () => {
122 it("[[Call]] returns the sign", () => {
123 assertStrictEquals(sgn(Infinity
), 1);
124 assertStrictEquals(sgn(-Infinity
), -1);
125 assertStrictEquals(sgn(0), 0);
126 assertStrictEquals(sgn(-0), -0);
127 assertStrictEquals(sgn(NaN
), NaN
);
130 it("[[Call]] works with big·ints", () => {
131 assertStrictEquals(sgn(0n
), 0n
);
132 assertStrictEquals(sgn(92n
), 1n
);
133 assertStrictEquals(sgn(-92n
), -1n
);
137 describe("toBigInt", () => {
138 it("[[Call]] converts to a big·int", () => {
139 assertStrictEquals(toBigInt(2), 2n
);
143 describe("toFloat32", () => {
144 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
146 toFloat32(562949953421313),
147 Math
.fround(562949953421313),
151 it("[[Call]] works with big·ints", () => {
153 toFloat32(562949953421313n
),
154 Math
.fround(562949953421313),
159 describe("toIntN", () => {
160 it("[[Call]] converts to an int·n", () => {
161 assertStrictEquals(toIntN(2, 7n
), -1n
);
164 it("[[Call]] works with numbers", () => {
165 assertStrictEquals(toIntN(2, 7), -1);
168 it("[[Call]] works with non‐integers", () => {
169 assertStrictEquals(toIntN(2, 7.21), -1);
170 assertStrictEquals(toIntN(2, Infinity
), 0);
174 describe("toIntegerOrInfinity", () => {
175 it("[[Call]] converts nan to zero", () => {
176 assertStrictEquals(toIntegerOrInfinity(NaN
), 0);
179 it("[[Call]] converts negative zero to positive zero", () => {
180 assertStrictEquals(toIntegerOrInfinity(-0), 0);
183 it("[[Call]] drops the fractional part of negative numbers", () => {
184 assertStrictEquals(toIntegerOrInfinity(-1.79), -1);
187 it("[[Call]] returns infinity for infinity", () => {
188 assertStrictEquals(toIntegerOrInfinity(Infinity
), Infinity
);
191 it("[[Call]] returns negative infinity for negative infinity", () => {
192 assertStrictEquals(toIntegerOrInfinity(Infinity
), Infinity
);
196 describe("toNumber", () => {
197 it("[[Call]] converts to a number", () => {
198 assertStrictEquals(toNumber(2n
), 2);
202 describe("toNumeric", () => {
203 it("[[Call]] returns a big·int argument", () => {
204 assertStrictEquals(toNumeric(231n
), 231n
);
207 it("[[Call]] converts to a numeric", () => {
208 assertStrictEquals(toNumeric("231"), 231);
211 it("[[Call]] prefers `valueOf`", () => {
226 describe("toUintN", () => {
227 it("[[Call]] converts to an int·n", () => {
228 assertStrictEquals(toUintN(2, 7n
), 3n
);
231 it("[[Call]] works with numbers", () => {
232 assertStrictEquals(toUintN(2, 7), 3);
235 it("[[Call]] works with non‐integers", () => {
236 assertStrictEquals(toUintN(2, 7.21), 3);
237 assertStrictEquals(toUintN(2, Infinity
), 0);
This page took 0.067198 seconds and 3 git commands to generate.