]>
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";
29 } from "./numeric.js";
31 describe("abs", () => {
32 it("[[Call]] returns the absolute value", () => {
33 assertStrictEquals(abs(-1), 1);
36 it("[[Call]] works with big·ints", () => {
37 const bn
= BigInt(Number
.MAX_SAFE_INTEGER
) + 2n
;
38 assertStrictEquals(abs(-bn
), bn
);
42 describe("atan2", () => {
43 it("[[Call]] returns the atan2", () => {
44 assertStrictEquals(atan2(6, 9), Math
.atan2(6, 9));
47 it("[[Call]] works with big·ints", () => {
48 assertStrictEquals(atan2(6n
, 9n
), Math
.atan2(6, 9));
52 describe("clz32", () => {
53 it("[[Call]] returns the clz32", () => {
54 assertStrictEquals(clz32(1 << 28), 3);
57 it("[[Call]] works with big·ints", () => {
58 assertStrictEquals(clz32(1n
<< 28n
), 3);
62 describe("max", () => {
63 it("[[Call]] returns the largest number", () => {
64 assertStrictEquals(max(1, -6, 92, -Infinity
, 0), 92);
67 it("[[Call]] returns the largest big·int", () => {
68 assertStrictEquals(max(1n
, -6n
, 92n
, 0n
), 92n
);
71 it("[[Call]] returns nan if any argument is nan", () => {
72 assertStrictEquals(max(0, NaN
, 1), NaN
);
75 it("[[Call]] returns -Infinity when called with no arguments", () => {
76 assertStrictEquals(max(), -Infinity
);
79 it("[[Call]] throws if both big·int and number arguments are provided", () => {
80 assertThrows(() => max(-Infinity
, 0n
));
84 describe("min", () => {
85 it("[[Call]] returns the largest number", () => {
86 assertStrictEquals(min(1, -6, 92, Infinity
, 0), -6);
89 it("[[Call]] returns the largest big·int", () => {
90 assertStrictEquals(min(1n
, -6n
, 92n
, 0n
), -6n
);
93 it("[[Call]] returns nan if any argument is nan", () => {
94 assertStrictEquals(min(0, NaN
, 1), NaN
);
97 it("[[Call]] returns Infinity when called with no arguments", () => {
98 assertStrictEquals(min(), Infinity
);
101 it("[[Call]] throws if both big·int and number arguments are provided", () => {
102 assertThrows(() => min(Infinity
, 0n
));
106 describe("sgn", () => {
107 it("[[Call]] returns the sign", () => {
108 assertStrictEquals(sgn(Infinity
), 1);
109 assertStrictEquals(sgn(-Infinity
), -1);
110 assertStrictEquals(sgn(0), 0);
111 assertStrictEquals(sgn(-0), -0);
112 assertStrictEquals(sgn(NaN
), NaN
);
115 it("[[Call]] works with big·ints", () => {
116 assertStrictEquals(sgn(0n
), 0n
);
117 assertStrictEquals(sgn(92n
), 1n
);
118 assertStrictEquals(sgn(-92n
), -1n
);
122 describe("toBigInt", () => {
123 it("[[Call]] converts to a big·int", () => {
124 assertStrictEquals(toBigInt(2), 2n
);
128 describe("toFloat32", () => {
129 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
131 toFloat32(562949953421313),
132 Math
.fround(562949953421313),
136 it("[[Call]] works with big·ints", () => {
138 toFloat32(562949953421313n
),
139 Math
.fround(562949953421313),
144 describe("toIntN", () => {
145 it("[[Call]] converts to an int·n", () => {
146 assertStrictEquals(toIntN(2, 7n
), -1n
);
149 it("[[Call]] works with numbers", () => {
150 assertStrictEquals(toIntN(2, 7), -1);
154 describe("toNumber", () => {
155 it("[[Call]] converts to a number", () => {
156 assertStrictEquals(toNumber(2n
), 2);
160 describe("toNumeric", () => {
161 it("[[Call]] returns a big·int argument", () => {
162 assertStrictEquals(toNumeric(231n
), 231n
);
165 it("[[Call]] converts to a numeric", () => {
166 assertStrictEquals(toNumeric("231"), 231);
169 it("[[Call]] prefers `valueOf`", () => {
184 describe("toUintN", () => {
185 it("[[Call]] converts to an int·n", () => {
186 assertStrictEquals(toUintN(2, 7n
), 3n
);
189 it("[[Call]] works with numbers", () => {
190 assertStrictEquals(toUintN(2, 7), 3);
This page took 0.077234 seconds and 5 git commands to generate.