]> Lady’s Gitweb - Pisces/blob - numeric.test.js
Add methods for own entries and values to object.js
[Pisces] / numeric.test.js
1 // ♓🌟 Piscēs ∷ numeric.test.js
2 // ====================================================================
3 //
4 // Copyright © 2022–2023 Lady [@ Lady’s Computer].
5 //
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/>.
9
10 import {
11 assert,
12 assertStrictEquals,
13 assertThrows,
14 describe,
15 it,
16 } from "./dev-deps.js";
17 import {
18 abs,
19 arccos,
20 arccosh,
21 arcsin,
22 arcsinh,
23 arctan,
24 arctan2,
25 arctanh,
26 cbrt,
27 ceil,
28 clz32,
29 cos,
30 cosh,
31 exp,
32 expm1,
33 floor,
34 hypot,
35 isFiniteNumber,
36 isIntegralNumber,
37 isNan,
38 isSafeIntegralNumber,
39 ln,
40 ln1p,
41 log10,
42 log2,
43 max,
44 min,
45 rand,
46 round,
47 sgn,
48 sin,
49 sinh,
50 sqrt,
51 tan,
52 tanh,
53 toBigInt,
54 toExponentialNotation,
55 toFixedDecimalNotation,
56 toFloat32,
57 toIntegralNumber,
58 toIntegralNumberOrInfinity,
59 toNumber,
60 toNumeric,
61 toSignedIntegralNumeric,
62 toUnsignedIntegralNumeric,
63 trunc,
64 } from "./numeric.js";
65
66 describe("abs", () => {
67 it("[[Call]] returns the absolute value", () => {
68 assertStrictEquals(abs(-1), 1);
69 });
70
71 it("[[Call]] works with big·ints", () => {
72 const bn = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
73 assertStrictEquals(abs(-bn), bn);
74 });
75
76 it("[[Construct]] throws an error", () => {
77 assertThrows(() => new abs(0));
78 });
79
80 describe(".length", () => {
81 it("[[Get]] returns the correct length", () => {
82 assertStrictEquals(abs.length, 1);
83 });
84 });
85
86 describe(".name", () => {
87 it("[[Get]] returns the correct name", () => {
88 assertStrictEquals(abs.name, "abs");
89 });
90 });
91 });
92
93 describe("arccos", () => {
94 it("[[Call]] returns the arccos", () => {
95 assertStrictEquals(arccos(1), 0);
96 assertStrictEquals(arccos(0), Math.PI / 2);
97 });
98
99 it("[[Call]] throws with big·ints", () => {
100 assertThrows(() => arccos(1n));
101 });
102
103 it("[[Construct]] throws an error", () => {
104 assertThrows(() => new arccos(1));
105 });
106
107 describe(".length", () => {
108 it("[[Get]] returns the correct length", () => {
109 assertStrictEquals(arccos.length, 1);
110 });
111 });
112
113 describe(".name", () => {
114 it("[[Get]] returns the correct name", () => {
115 assertStrictEquals(arccos.name, "arccos");
116 });
117 });
118 });
119
120 describe("arccosh", () => {
121 it("[[Call]] returns the arccosh", () => {
122 assertStrictEquals(arccosh(1), 0);
123 assertStrictEquals(arccosh(0), NaN);
124 });
125
126 it("[[Call]] throws with big·ints", () => {
127 assertThrows(() => arccosh(1n));
128 });
129
130 it("[[Construct]] throws an error", () => {
131 assertThrows(() => new arccosh(1));
132 });
133
134 describe(".length", () => {
135 it("[[Get]] returns the correct length", () => {
136 assertStrictEquals(arccosh.length, 1);
137 });
138 });
139
140 describe(".name", () => {
141 it("[[Get]] returns the correct name", () => {
142 assertStrictEquals(arccosh.name, "arccosh");
143 });
144 });
145 });
146
147 describe("arcsin", () => {
148 it("[[Call]] returns the arcsin", () => {
149 assertStrictEquals(arcsin(1), Math.PI / 2);
150 assertStrictEquals(arcsin(0), 0);
151 });
152
153 it("[[Call]] throws with big·ints", () => {
154 assertThrows(() => arcsin(1n));
155 });
156
157 it("[[Construct]] throws an error", () => {
158 assertThrows(() => new arcsin(1));
159 });
160
161 describe(".length", () => {
162 it("[[Get]] returns the correct length", () => {
163 assertStrictEquals(arcsin.length, 1);
164 });
165 });
166
167 describe(".name", () => {
168 it("[[Get]] returns the correct name", () => {
169 assertStrictEquals(arcsin.name, "arcsin");
170 });
171 });
172 });
173
174 describe("arcsinh", () => {
175 it("[[Call]] returns the arcsinh", () => {
176 assertStrictEquals(arcsinh(1), Math.asinh(1));
177 assertStrictEquals(arcsinh(0), 0);
178 });
179
180 it("[[Call]] throws with big·ints", () => {
181 assertThrows(() => arcsinh(1n));
182 });
183
184 it("[[Construct]] throws an error", () => {
185 assertThrows(() => new arcsinh(1));
186 });
187
188 describe(".length", () => {
189 it("[[Get]] returns the correct length", () => {
190 assertStrictEquals(arcsinh.length, 1);
191 });
192 });
193
194 describe(".name", () => {
195 it("[[Get]] returns the correct name", () => {
196 assertStrictEquals(arcsinh.name, "arcsinh");
197 });
198 });
199 });
200
201 describe("arctan", () => {
202 it("[[Call]] returns the arctan", () => {
203 assertStrictEquals(arctan(1), Math.PI / 4);
204 assertStrictEquals(arctan(0), 0);
205 });
206
207 it("[[Call]] throws with big·ints", () => {
208 assertThrows(() => arctan(1n));
209 });
210
211 it("[[Construct]] throws an error", () => {
212 assertThrows(() => new arctan(1));
213 });
214
215 describe(".length", () => {
216 it("[[Get]] returns the correct length", () => {
217 assertStrictEquals(arctan.length, 1);
218 });
219 });
220
221 describe(".name", () => {
222 it("[[Get]] returns the correct name", () => {
223 assertStrictEquals(arctan.name, "arctan");
224 });
225 });
226 });
227
228 describe("arctan2", () => {
229 it("[[Call]] returns the arctan2", () => {
230 assertStrictEquals(arctan2(6, 9), Math.atan2(6, 9));
231 });
232
233 it("[[Call]] works with big·ints", () => {
234 assertStrictEquals(arctan2(6n, 9n), Math.atan2(6, 9));
235 });
236
237 it("[[Construct]] throws an error", () => {
238 assertThrows(() => new arctan2(1, 0));
239 });
240
241 describe(".length", () => {
242 it("[[Get]] returns the correct length", () => {
243 assertStrictEquals(arctan2.length, 2);
244 });
245 });
246
247 describe(".name", () => {
248 it("[[Get]] returns the correct name", () => {
249 assertStrictEquals(arctan2.name, "arctan2");
250 });
251 });
252 });
253
254 describe("arctanh", () => {
255 it("[[Call]] returns the arctanh", () => {
256 assertStrictEquals(arctanh(1), Infinity);
257 assertStrictEquals(arctanh(0), 0);
258 });
259
260 it("[[Call]] throws with big·ints", () => {
261 assertThrows(() => arctanh(1n));
262 });
263
264 it("[[Construct]] throws an error", () => {
265 assertThrows(() => new arctanh(1));
266 });
267
268 describe(".length", () => {
269 it("[[Get]] returns the correct length", () => {
270 assertStrictEquals(arctanh.length, 1);
271 });
272 });
273
274 describe(".name", () => {
275 it("[[Get]] returns the correct name", () => {
276 assertStrictEquals(arctanh.name, "arctanh");
277 });
278 });
279 });
280
281 describe("cbrt", () => {
282 it("[[Call]] returns the cbrt", () => {
283 assertStrictEquals(cbrt(1), 1);
284 assertStrictEquals(cbrt(2), Math.cbrt(2));
285 });
286
287 it("[[Call]] throws with big·ints", () => {
288 assertThrows(() => cbrt(1n));
289 });
290
291 it("[[Construct]] throws an error", () => {
292 assertThrows(() => new cbrt(1));
293 });
294
295 describe(".length", () => {
296 it("[[Get]] returns the correct length", () => {
297 assertStrictEquals(cbrt.length, 1);
298 });
299 });
300
301 describe(".name", () => {
302 it("[[Get]] returns the correct name", () => {
303 assertStrictEquals(cbrt.name, "cbrt");
304 });
305 });
306 });
307
308 describe("ceil", () => {
309 it("[[Call]] returns the ceil", () => {
310 assertStrictEquals(ceil(1), 1);
311 assertStrictEquals(ceil(1.1), 2);
312 });
313
314 it("[[Call]] throws with big·ints", () => {
315 assertThrows(() => ceil(1n));
316 });
317
318 it("[[Construct]] throws an error", () => {
319 assertThrows(() => new ceil(1));
320 });
321
322 describe(".length", () => {
323 it("[[Get]] returns the correct length", () => {
324 assertStrictEquals(ceil.length, 1);
325 });
326 });
327
328 describe(".name", () => {
329 it("[[Get]] returns the correct name", () => {
330 assertStrictEquals(ceil.name, "ceil");
331 });
332 });
333 });
334
335 describe("clz32", () => {
336 it("[[Call]] returns the clz32", () => {
337 assertStrictEquals(clz32(1 << 28), 3);
338 });
339
340 it("[[Call]] works with big·ints", () => {
341 assertStrictEquals(clz32(1n << 28n), 3);
342 });
343
344 it("[[Construct]] throws an error", () => {
345 assertThrows(() => new clz32(1));
346 });
347
348 describe(".length", () => {
349 it("[[Get]] returns the correct length", () => {
350 assertStrictEquals(clz32.length, 1);
351 });
352 });
353
354 describe(".name", () => {
355 it("[[Get]] returns the correct name", () => {
356 assertStrictEquals(clz32.name, "clz32");
357 });
358 });
359 });
360
361 describe("cos", () => {
362 it("[[Call]] returns the cos", () => {
363 assertStrictEquals(cos(1), Math.cos(1));
364 assertStrictEquals(cos(0), 1);
365 });
366
367 it("[[Call]] throws with big·ints", () => {
368 assertThrows(() => cos(1n));
369 });
370
371 it("[[Construct]] throws an error", () => {
372 assertThrows(() => new cos(1));
373 });
374
375 describe(".length", () => {
376 it("[[Get]] returns the correct length", () => {
377 assertStrictEquals(cos.length, 1);
378 });
379 });
380
381 describe(".name", () => {
382 it("[[Get]] returns the correct name", () => {
383 assertStrictEquals(cos.name, "cos");
384 });
385 });
386 });
387
388 describe("cosh", () => {
389 it("[[Call]] returns the cosh", () => {
390 assertStrictEquals(cosh(1), Math.cosh(1));
391 assertStrictEquals(cosh(0), 1);
392 });
393
394 it("[[Call]] throws with big·ints", () => {
395 assertThrows(() => cosh(1n));
396 });
397
398 it("[[Construct]] throws an error", () => {
399 assertThrows(() => new cosh(1));
400 });
401
402 describe(".length", () => {
403 it("[[Get]] returns the correct length", () => {
404 assertStrictEquals(cosh.length, 1);
405 });
406 });
407
408 describe(".name", () => {
409 it("[[Get]] returns the correct name", () => {
410 assertStrictEquals(cosh.name, "cosh");
411 });
412 });
413 });
414
415 describe("exp", () => {
416 it("[[Call]] returns the exp", () => {
417 assertStrictEquals(exp(1), Math.E);
418 assertStrictEquals(exp(0), 1);
419 });
420
421 it("[[Call]] throws with big·ints", () => {
422 assertThrows(() => exp(1n));
423 });
424
425 it("[[Construct]] throws an error", () => {
426 assertThrows(() => new exp(1));
427 });
428
429 describe(".length", () => {
430 it("[[Get]] returns the correct length", () => {
431 assertStrictEquals(exp.length, 1);
432 });
433 });
434
435 describe(".name", () => {
436 it("[[Get]] returns the correct name", () => {
437 assertStrictEquals(exp.name, "exp");
438 });
439 });
440 });
441
442 describe("expm1", () => {
443 it("[[Call]] returns the expm1", () => {
444 assertStrictEquals(expm1(1), Math.E - 1);
445 assertStrictEquals(expm1(0), 0);
446 });
447
448 it("[[Call]] throws with big·ints", () => {
449 assertThrows(() => expm1(1n));
450 });
451
452 it("[[Construct]] throws an error", () => {
453 assertThrows(() => new expm1(1));
454 });
455
456 describe(".length", () => {
457 it("[[Get]] returns the correct length", () => {
458 assertStrictEquals(expm1.length, 1);
459 });
460 });
461
462 describe(".name", () => {
463 it("[[Get]] returns the correct name", () => {
464 assertStrictEquals(expm1.name, "expm1");
465 });
466 });
467 });
468
469 describe("floor", () => {
470 it("[[Call]] returns the floor", () => {
471 assertStrictEquals(floor(1), 1);
472 assertStrictEquals(floor(0.1), 0);
473 });
474
475 it("[[Call]] throws with big·ints", () => {
476 assertThrows(() => floor(1n));
477 });
478
479 it("[[Construct]] throws an error", () => {
480 assertThrows(() => new floor(1));
481 });
482
483 describe(".length", () => {
484 it("[[Get]] returns the correct length", () => {
485 assertStrictEquals(floor.length, 1);
486 });
487 });
488
489 describe(".name", () => {
490 it("[[Get]] returns the correct name", () => {
491 assertStrictEquals(floor.name, "floor");
492 });
493 });
494 });
495
496 describe("hypot", () => {
497 it("[[Call]] returns the floor", () => {
498 assertStrictEquals(hypot(1, 0), 1);
499 assertStrictEquals(hypot(3, 4), 5);
500 });
501
502 it("[[Call]] throws with big·ints", () => {
503 assertThrows(() => hypot(1n, 0n));
504 });
505
506 it("[[Construct]] throws an error", () => {
507 assertThrows(() => new hypot(1, 0));
508 });
509
510 describe(".length", () => {
511 it("[[Get]] returns the correct length", () => {
512 assertStrictEquals(hypot.length, 2);
513 });
514 });
515
516 describe(".name", () => {
517 it("[[Get]] returns the correct name", () => {
518 assertStrictEquals(hypot.name, "hypot");
519 });
520 });
521 });
522
523 describe("isFiniteNumber", () => {
524 it("[[Call]] returns true for finite numbers", () => {
525 assertStrictEquals(isFiniteNumber(1), true);
526 assertStrictEquals(isFiniteNumber(Number.MAX_VALUE), true);
527 assertStrictEquals(isFiniteNumber(Number.EPSILON), true);
528 });
529
530 it("[[Call]] returns false for nonfinite numbers", () => {
531 assertStrictEquals(isFiniteNumber(NaN), false);
532 assertStrictEquals(isFiniteNumber(Infinity), false);
533 });
534
535 it("[[Call]] returns false for nonnumbers", () => {
536 assertStrictEquals(isFiniteNumber(1n), false);
537 assertStrictEquals(isFiniteNumber("1"), false);
538 });
539
540 it("[[Construct]] throws an error", () => {
541 assertThrows(() => new isFiniteNumber(1));
542 });
543
544 describe(".length", () => {
545 it("[[Get]] returns the correct length", () => {
546 assertStrictEquals(isFiniteNumber.length, 1);
547 });
548 });
549
550 describe(".name", () => {
551 it("[[Get]] returns the correct name", () => {
552 assertStrictEquals(isFiniteNumber.name, "isFiniteNumber");
553 });
554 });
555 });
556
557 describe("isIntegralNumber", () => {
558 it("[[Call]] returns true for integral numbers", () => {
559 assertStrictEquals(isIntegralNumber(1), true);
560 assertStrictEquals(isIntegralNumber(Number.MAX_VALUE), true);
561 });
562
563 it("[[Call]] returns false for nonfinite numbers", () => {
564 assertStrictEquals(isIntegralNumber(NaN), false);
565 assertStrictEquals(isIntegralNumber(Infinity), false);
566 });
567
568 it("[[Call]] returns false for nonintegral numbers", () => {
569 assertStrictEquals(isIntegralNumber(.1), false);
570 assertStrictEquals(isIntegralNumber(Number.EPSILON), false);
571 });
572
573 it("[[Call]] returns false for nonnumbers", () => {
574 assertStrictEquals(isIntegralNumber(1n), false);
575 assertStrictEquals(isIntegralNumber("1"), false);
576 });
577
578 it("[[Construct]] throws an error", () => {
579 assertThrows(() => new isIntegralNumber(1));
580 });
581
582 describe(".length", () => {
583 it("[[Get]] returns the correct length", () => {
584 assertStrictEquals(isIntegralNumber.length, 1);
585 });
586 });
587
588 describe(".name", () => {
589 it("[[Get]] returns the correct name", () => {
590 assertStrictEquals(isIntegralNumber.name, "isIntegralNumber");
591 });
592 });
593 });
594
595 describe("isNan", () => {
596 it("[[Call]] returns true for nan", () => {
597 assertStrictEquals(isNan(NaN), true);
598 });
599
600 it("[[Call]] returns false for infinite numbers", () => {
601 assertStrictEquals(isNan(-Infinity), false);
602 assertStrictEquals(isNan(Infinity), false);
603 });
604
605 it("[[Call]] returns false for finite numbers", () => {
606 assertStrictEquals(isNan(1), false);
607 assertStrictEquals(isNan(Number.MAX_VALUE), false);
608 assertStrictEquals(isNan(.1), false);
609 assertStrictEquals(isNan(Number.EPSILON), false);
610 });
611
612 it("[[Call]] returns false for nonnumbers", () => {
613 assertStrictEquals(isNan(1n), false);
614 assertStrictEquals(isNan("NaN"), false);
615 assertStrictEquals(isNan({}), false);
616 assertStrictEquals(isNan(new Date(NaN)), false);
617 });
618
619 it("[[Construct]] throws an error", () => {
620 assertThrows(() => new isNan(1));
621 });
622
623 describe(".length", () => {
624 it("[[Get]] returns the correct length", () => {
625 assertStrictEquals(isNan.length, 1);
626 });
627 });
628
629 describe(".name", () => {
630 it("[[Get]] returns the correct name", () => {
631 assertStrictEquals(isNan.name, "isNan");
632 });
633 });
634 });
635
636 describe("isSafeIntegralNumber", () => {
637 it("[[Call]] returns true for safe integral numbers", () => {
638 assertStrictEquals(isSafeIntegralNumber(1), true);
639 assertStrictEquals(
640 isSafeIntegralNumber(Number.MAX_SAFE_INTEGER),
641 true,
642 );
643 });
644
645 it("[[Call]] returns false for nonfinite numbers", () => {
646 assertStrictEquals(isSafeIntegralNumber(NaN), false);
647 assertStrictEquals(isSafeIntegralNumber(Infinity), false);
648 });
649
650 it("[[Call]] returns false for nonintegral numbers", () => {
651 assertStrictEquals(isSafeIntegralNumber(.1), false);
652 assertStrictEquals(isSafeIntegralNumber(Number.EPSILON), false);
653 });
654 it("[[Call]] returns true for unsafe integral numbers", () => {
655 assertStrictEquals(isSafeIntegralNumber(Number.MAX_VALUE), false);
656 });
657
658 it("[[Call]] returns false for nonnumbers", () => {
659 assertStrictEquals(isSafeIntegralNumber(1n), false);
660 assertStrictEquals(isSafeIntegralNumber("1"), false);
661 });
662
663 it("[[Construct]] throws an error", () => {
664 assertThrows(() => new isSafeIntegralNumber(1));
665 });
666
667 describe(".length", () => {
668 it("[[Get]] returns the correct length", () => {
669 assertStrictEquals(isSafeIntegralNumber.length, 1);
670 });
671 });
672
673 describe(".name", () => {
674 it("[[Get]] returns the correct name", () => {
675 assertStrictEquals(
676 isSafeIntegralNumber.name,
677 "isSafeIntegralNumber",
678 );
679 });
680 });
681 });
682
683 describe("ln", () => {
684 it("[[Call]] returns the ln", () => {
685 assertStrictEquals(ln(1), 0);
686 assertStrictEquals(ln(Math.E), 1);
687 });
688
689 it("[[Call]] throws with big·ints", () => {
690 assertThrows(() => ln(1n));
691 });
692
693 it("[[Construct]] throws an error", () => {
694 assertThrows(() => new ln(1));
695 });
696
697 describe(".length", () => {
698 it("[[Get]] returns the correct length", () => {
699 assertStrictEquals(ln.length, 1);
700 });
701 });
702
703 describe(".name", () => {
704 it("[[Get]] returns the correct name", () => {
705 assertStrictEquals(ln.name, "ln");
706 });
707 });
708 });
709
710 describe("ln1p", () => {
711 it("[[Call]] returns the ln1p", () => {
712 assertStrictEquals(ln1p(1), Math.log1p(1));
713 assertStrictEquals(ln1p(Math.E - 1), 1);
714 });
715
716 it("[[Call]] throws with big·ints", () => {
717 assertThrows(() => ln1p(1n));
718 });
719
720 it("[[Construct]] throws an error", () => {
721 assertThrows(() => new ln1p(1));
722 });
723
724 describe(".length", () => {
725 it("[[Get]] returns the correct length", () => {
726 assertStrictEquals(ln1p.length, 1);
727 });
728 });
729
730 describe(".name", () => {
731 it("[[Get]] returns the correct name", () => {
732 assertStrictEquals(ln1p.name, "ln1p");
733 });
734 });
735 });
736
737 describe("log10", () => {
738 it("[[Call]] returns the log10", () => {
739 assertStrictEquals(log10(1), 0);
740 assertStrictEquals(log10(10), 1);
741 });
742
743 it("[[Call]] throws with big·ints", () => {
744 assertThrows(() => log10(1n));
745 });
746
747 it("[[Construct]] throws an error", () => {
748 assertThrows(() => new log10(1));
749 });
750
751 describe(".length", () => {
752 it("[[Get]] returns the correct length", () => {
753 assertStrictEquals(log10.length, 1);
754 });
755 });
756
757 describe(".name", () => {
758 it("[[Get]] returns the correct name", () => {
759 assertStrictEquals(log10.name, "log10");
760 });
761 });
762 });
763
764 describe("log2", () => {
765 it("[[Call]] returns the log2", () => {
766 assertStrictEquals(log2(1), 0);
767 assertStrictEquals(log2(2), 1);
768 });
769
770 it("[[Call]] throws with big·ints", () => {
771 assertThrows(() => log2(1n));
772 });
773
774 it("[[Construct]] throws an error", () => {
775 assertThrows(() => new log2(1));
776 });
777
778 describe(".length", () => {
779 it("[[Get]] returns the correct length", () => {
780 assertStrictEquals(log2.length, 1);
781 });
782 });
783
784 describe(".name", () => {
785 it("[[Get]] returns the correct name", () => {
786 assertStrictEquals(log2.name, "log2");
787 });
788 });
789 });
790
791 describe("max", () => {
792 it("[[Call]] returns the largest number", () => {
793 assertStrictEquals(max(1, -6, 92, -Infinity, 0), 92);
794 });
795
796 it("[[Call]] returns the largest big·int", () => {
797 assertStrictEquals(max(1n, -6n, 92n, 0n), 92n);
798 });
799
800 it("[[Call]] returns nan if any argument is nan", () => {
801 assertStrictEquals(max(0, NaN, 1), NaN);
802 });
803
804 it("[[Call]] returns -Infinity when called with no arguments", () => {
805 assertStrictEquals(max(), -Infinity);
806 });
807
808 it("[[Call]] throws if both big·int and number arguments are provided", () => {
809 assertThrows(() => max(-Infinity, 0n));
810 });
811
812 it("[[Construct]] throws an error", () => {
813 assertThrows(() => new max(1, 0));
814 });
815
816 describe(".length", () => {
817 it("[[Get]] returns the correct length", () => {
818 assertStrictEquals(max.length, 2);
819 });
820 });
821
822 describe(".name", () => {
823 it("[[Get]] returns the correct name", () => {
824 assertStrictEquals(max.name, "max");
825 });
826 });
827 });
828
829 describe("min", () => {
830 it("[[Call]] returns the largest number", () => {
831 assertStrictEquals(min(1, -6, 92, Infinity, 0), -6);
832 });
833
834 it("[[Call]] returns the largest big·int", () => {
835 assertStrictEquals(min(1n, -6n, 92n, 0n), -6n);
836 });
837
838 it("[[Call]] returns nan if any argument is nan", () => {
839 assertStrictEquals(min(0, NaN, 1), NaN);
840 });
841
842 it("[[Call]] returns Infinity when called with no arguments", () => {
843 assertStrictEquals(min(), Infinity);
844 });
845
846 it("[[Call]] throws if both big·int and number arguments are provided", () => {
847 assertThrows(() => min(Infinity, 0n));
848 });
849
850 it("[[Construct]] throws an error", () => {
851 assertThrows(() => new min(1, 0));
852 });
853
854 describe(".length", () => {
855 it("[[Get]] returns the correct length", () => {
856 assertStrictEquals(min.length, 2);
857 });
858 });
859
860 describe(".name", () => {
861 it("[[Get]] returns the correct name", () => {
862 assertStrictEquals(min.name, "min");
863 });
864 });
865 });
866
867 describe("rand", () => {
868 it("[[Call]] returns a random number between 0 and 1", () => {
869 // Not possible to fully test, obviously.
870 const r = rand();
871 assert(typeof r === "number");
872 assert(r >= 0 && r < 1);
873 });
874
875 it("[[Construct]] throws an error", () => {
876 assertThrows(() => new rand());
877 });
878
879 describe(".length", () => {
880 it("[[Get]] returns the correct length", () => {
881 assertStrictEquals(rand.length, 0);
882 });
883 });
884
885 describe(".name", () => {
886 it("[[Get]] returns the correct name", () => {
887 assertStrictEquals(rand.name, "rand");
888 });
889 });
890 });
891
892 describe("round", () => {
893 it("[[Call]] returns the round", () => {
894 assertStrictEquals(round(1), 1);
895 assertStrictEquals(round(0.5), 1);
896 assertStrictEquals(round(-0.5), -0);
897 });
898
899 it("[[Call]] throws with big·ints", () => {
900 assertThrows(() => round(1n));
901 });
902
903 it("[[Construct]] throws an error", () => {
904 assertThrows(() => new round(1));
905 });
906
907 describe(".length", () => {
908 it("[[Get]] returns the correct length", () => {
909 assertStrictEquals(round.length, 1);
910 });
911 });
912
913 describe(".name", () => {
914 it("[[Get]] returns the correct name", () => {
915 assertStrictEquals(round.name, "round");
916 });
917 });
918 });
919
920 describe("sgn", () => {
921 it("[[Call]] returns the sign", () => {
922 assertStrictEquals(sgn(Infinity), 1);
923 assertStrictEquals(sgn(-Infinity), -1);
924 assertStrictEquals(sgn(0), 0);
925 assertStrictEquals(sgn(-0), -0);
926 assertStrictEquals(sgn(NaN), NaN);
927 });
928
929 it("[[Call]] works with big·ints", () => {
930 assertStrictEquals(sgn(0n), 0n);
931 assertStrictEquals(sgn(92n), 1n);
932 assertStrictEquals(sgn(-92n), -1n);
933 });
934
935 it("[[Construct]] throws an error", () => {
936 assertThrows(() => new sgn(1));
937 });
938
939 describe(".length", () => {
940 it("[[Get]] returns the correct length", () => {
941 assertStrictEquals(sgn.length, 1);
942 });
943 });
944
945 describe(".name", () => {
946 it("[[Get]] returns the correct name", () => {
947 assertStrictEquals(sgn.name, "sgn");
948 });
949 });
950 });
951
952 describe("sin", () => {
953 it("[[Call]] returns the sin", () => {
954 assertStrictEquals(sin(1), Math.sin(1));
955 assertStrictEquals(sin(0), 0);
956 });
957
958 it("[[Call]] throws with big·ints", () => {
959 assertThrows(() => sin(1n));
960 });
961
962 it("[[Construct]] throws an error", () => {
963 assertThrows(() => new sin(1));
964 });
965
966 describe(".length", () => {
967 it("[[Get]] returns the correct length", () => {
968 assertStrictEquals(sin.length, 1);
969 });
970 });
971
972 describe(".name", () => {
973 it("[[Get]] returns the correct name", () => {
974 assertStrictEquals(sin.name, "sin");
975 });
976 });
977 });
978
979 describe("sinh", () => {
980 it("[[Call]] returns the sinh", () => {
981 assertStrictEquals(sinh(1), Math.sinh(1));
982 assertStrictEquals(sinh(0), 0);
983 });
984
985 it("[[Call]] throws with big·ints", () => {
986 assertThrows(() => sinh(1n));
987 });
988
989 it("[[Construct]] throws an error", () => {
990 assertThrows(() => new sinh(1));
991 });
992
993 describe(".length", () => {
994 it("[[Get]] returns the correct length", () => {
995 assertStrictEquals(sinh.length, 1);
996 });
997 });
998
999 describe(".name", () => {
1000 it("[[Get]] returns the correct name", () => {
1001 assertStrictEquals(sinh.name, "sinh");
1002 });
1003 });
1004 });
1005
1006 describe("sqrt", () => {
1007 it("[[Call]] returns the sqrt", () => {
1008 assertStrictEquals(sqrt(1), 1);
1009 assertStrictEquals(sqrt(2), Math.SQRT2);
1010 });
1011
1012 it("[[Call]] throws with big·ints", () => {
1013 assertThrows(() => sqrt(1n));
1014 });
1015
1016 it("[[Construct]] throws an error", () => {
1017 assertThrows(() => new sqrt(1));
1018 });
1019
1020 describe(".length", () => {
1021 it("[[Get]] returns the correct length", () => {
1022 assertStrictEquals(sqrt.length, 1);
1023 });
1024 });
1025
1026 describe(".name", () => {
1027 it("[[Get]] returns the correct name", () => {
1028 assertStrictEquals(sqrt.name, "sqrt");
1029 });
1030 });
1031 });
1032
1033 describe("tan", () => {
1034 it("[[Call]] returns the tan", () => {
1035 assertStrictEquals(tan(1), Math.tan(1));
1036 assertStrictEquals(tan(0), 0);
1037 });
1038
1039 it("[[Call]] throws with big·ints", () => {
1040 assertThrows(() => tan(1n));
1041 });
1042
1043 it("[[Construct]] throws an error", () => {
1044 assertThrows(() => new tan(1));
1045 });
1046
1047 describe(".length", () => {
1048 it("[[Get]] returns the correct length", () => {
1049 assertStrictEquals(tan.length, 1);
1050 });
1051 });
1052
1053 describe(".name", () => {
1054 it("[[Get]] returns the correct name", () => {
1055 assertStrictEquals(tan.name, "tan");
1056 });
1057 });
1058 });
1059
1060 describe("tanh", () => {
1061 it("[[Call]] returns the tanh", () => {
1062 assertStrictEquals(tanh(1), Math.tanh(1));
1063 assertStrictEquals(tanh(0), 0);
1064 });
1065
1066 it("[[Call]] throws with big·ints", () => {
1067 assertThrows(() => tanh(1n));
1068 });
1069
1070 it("[[Construct]] throws an error", () => {
1071 assertThrows(() => new tanh(1));
1072 });
1073
1074 describe(".length", () => {
1075 it("[[Get]] returns the correct length", () => {
1076 assertStrictEquals(tanh.length, 1);
1077 });
1078 });
1079
1080 describe(".name", () => {
1081 it("[[Get]] returns the correct name", () => {
1082 assertStrictEquals(tanh.name, "tanh");
1083 });
1084 });
1085 });
1086
1087 describe("toBigInt", () => {
1088 it("[[Call]] converts to a big·int", () => {
1089 assertStrictEquals(toBigInt(2), 2n);
1090 });
1091
1092 it("[[Construct]] throws an error", () => {
1093 assertThrows(() => new toBigInt(1));
1094 });
1095
1096 describe(".length", () => {
1097 it("[[Get]] returns the correct length", () => {
1098 assertStrictEquals(toBigInt.length, 1);
1099 });
1100 });
1101
1102 describe(".name", () => {
1103 it("[[Get]] returns the correct name", () => {
1104 assertStrictEquals(toBigInt.name, "toBigInt");
1105 });
1106 });
1107 });
1108
1109 describe("toExponentialNotation", () => {
1110 it("[[Call]] converts to exponential notation", () => {
1111 assertStrictEquals(toExponentialNotation(231), "2.31e+2");
1112 });
1113
1114 it("[[Call]] works with big·ints", () => {
1115 assertStrictEquals(
1116 toExponentialNotation(9007199254740993n),
1117 "9.007199254740993e+15",
1118 );
1119 });
1120
1121 it("[[Call]] respects the specified number of fractional digits", () => {
1122 assertStrictEquals(
1123 toExponentialNotation(.00000000642, 3),
1124 "6.420e-9",
1125 );
1126 assertStrictEquals(toExponentialNotation(.00691, 1), "6.9e-3");
1127 assertStrictEquals(toExponentialNotation(.00685, 1), "6.9e-3");
1128 assertStrictEquals(toExponentialNotation(.004199, 2), "4.20e-3");
1129 assertStrictEquals(
1130 toExponentialNotation(6420000000n, 3),
1131 "6.420e+9",
1132 );
1133 assertStrictEquals(toExponentialNotation(6910n, 1), "6.9e+3");
1134 assertStrictEquals(toExponentialNotation(6850n, 1), "6.9e+3");
1135 assertStrictEquals(toExponentialNotation(4199n, 2), "4.20e+3");
1136 });
1137
1138 it("[[Construct]] throws an error", () => {
1139 assertThrows(() => new toExponentialNotation(1, 1));
1140 });
1141
1142 describe(".length", () => {
1143 it("[[Get]] returns the correct length", () => {
1144 assertStrictEquals(toExponentialNotation.length, 2);
1145 });
1146 });
1147
1148 describe(".name", () => {
1149 it("[[Get]] returns the correct name", () => {
1150 assertStrictEquals(
1151 toExponentialNotation.name,
1152 "toExponentialNotation",
1153 );
1154 });
1155 });
1156 });
1157
1158 describe("toFixedDecimalNotation", () => {
1159 it("[[Call]] converts to fixed decimal notation", () => {
1160 assertStrictEquals(toFixedDecimalNotation(69.4199, 3), "69.420");
1161 });
1162
1163 it("[[Call]] works with big·ints", () => {
1164 assertStrictEquals(
1165 toFixedDecimalNotation(9007199254740993n),
1166 "9007199254740993",
1167 );
1168 assertStrictEquals(
1169 toFixedDecimalNotation(9007199254740993n, 2),
1170 "9007199254740993.00",
1171 );
1172 });
1173
1174 it("[[Construct]] throws an error", () => {
1175 assertThrows(() => new toFixedDecimalNotation(1, 1));
1176 });
1177
1178 describe(".length", () => {
1179 it("[[Get]] returns the correct length", () => {
1180 assertStrictEquals(toFixedDecimalNotation.length, 2);
1181 });
1182 });
1183
1184 describe(".name", () => {
1185 it("[[Get]] returns the correct name", () => {
1186 assertStrictEquals(
1187 toFixedDecimalNotation.name,
1188 "toFixedDecimalNotation",
1189 );
1190 });
1191 });
1192 });
1193
1194 describe("toFloat32", () => {
1195 it("[[Call]] returns the 32‐bit floating‐point representation", () => {
1196 assertStrictEquals(
1197 toFloat32(562949953421313),
1198 Math.fround(562949953421313),
1199 );
1200 });
1201
1202 it("[[Call]] works with big·ints", () => {
1203 assertStrictEquals(
1204 toFloat32(562949953421313n),
1205 Math.fround(562949953421313),
1206 );
1207 });
1208
1209 it("[[Construct]] throws an error", () => {
1210 assertThrows(() => new toFloat32(1));
1211 });
1212
1213 describe(".length", () => {
1214 it("[[Get]] returns the correct length", () => {
1215 assertStrictEquals(toFloat32.length, 1);
1216 });
1217 });
1218
1219 describe(".name", () => {
1220 it("[[Get]] returns the correct name", () => {
1221 assertStrictEquals(toFloat32.name, "toFloat32");
1222 });
1223 });
1224 });
1225
1226 describe("toSignedIntegralNumeric", () => {
1227 it("[[Call]] converts to an int·n", () => {
1228 assertStrictEquals(toSignedIntegralNumeric(2, 7n), -1n);
1229 });
1230
1231 it("[[Call]] works with numbers", () => {
1232 assertStrictEquals(toSignedIntegralNumeric(2, 7), -1);
1233 });
1234
1235 it("[[Call]] works with non‐integers", () => {
1236 assertStrictEquals(toSignedIntegralNumeric(2, 7.21), -1);
1237 assertStrictEquals(toSignedIntegralNumeric(2, Infinity), 0);
1238 });
1239
1240 it("[[Construct]] throws an error", () => {
1241 assertThrows(() => new toSignedIntegralNumeric(1, 1));
1242 });
1243
1244 describe(".length", () => {
1245 it("[[Get]] returns the correct length", () => {
1246 assertStrictEquals(toSignedIntegralNumeric.length, 2);
1247 });
1248 });
1249
1250 describe(".name", () => {
1251 it("[[Get]] returns the correct name", () => {
1252 assertStrictEquals(
1253 toSignedIntegralNumeric.name,
1254 "toSignedIntegralNumeric",
1255 );
1256 });
1257 });
1258 });
1259
1260 describe("toIntegralNumber", () => {
1261 it("[[Call]] converts nan to zero", () => {
1262 assertStrictEquals(toIntegralNumber(NaN), 0);
1263 });
1264
1265 it("[[Call]] converts negative zero to positive zero", () => {
1266 assertStrictEquals(toIntegralNumber(-0), 0);
1267 });
1268
1269 it("[[Call]] drops the fractional part of negative numbers", () => {
1270 assertStrictEquals(toIntegralNumber(-1.79), -1);
1271 });
1272
1273 it("[[Call]] returns zero for infinity", () => {
1274 assertStrictEquals(toIntegralNumber(Infinity), 0);
1275 });
1276
1277 it("[[Call]] returns zero for negative infinity", () => {
1278 assertStrictEquals(toIntegralNumber(-Infinity), 0);
1279 });
1280
1281 it("[[Call]] works with big·ints", () => {
1282 assertStrictEquals(toIntegralNumber(2n), 2);
1283 });
1284
1285 it("[[Construct]] throws an error", () => {
1286 assertThrows(() => new toIntegralNumber(1));
1287 });
1288
1289 describe(".length", () => {
1290 it("[[Get]] returns the correct length", () => {
1291 assertStrictEquals(toIntegralNumber.length, 1);
1292 });
1293 });
1294
1295 describe(".name", () => {
1296 it("[[Get]] returns the correct name", () => {
1297 assertStrictEquals(toIntegralNumber.name, "toIntegralNumber");
1298 });
1299 });
1300 });
1301
1302 describe("toIntegralNumberOrInfinity", () => {
1303 it("[[Call]] converts nan to zero", () => {
1304 assertStrictEquals(toIntegralNumberOrInfinity(NaN), 0);
1305 });
1306
1307 it("[[Call]] converts negative zero to positive zero", () => {
1308 assertStrictEquals(toIntegralNumberOrInfinity(-0), 0);
1309 });
1310
1311 it("[[Call]] drops the fractional part of negative numbers", () => {
1312 assertStrictEquals(toIntegralNumberOrInfinity(-1.79), -1);
1313 });
1314
1315 it("[[Call]] returns infinity for infinity", () => {
1316 assertStrictEquals(toIntegralNumberOrInfinity(Infinity), Infinity);
1317 });
1318
1319 it("[[Call]] returns negative infinity for negative infinity", () => {
1320 assertStrictEquals(
1321 toIntegralNumberOrInfinity(-Infinity),
1322 -Infinity,
1323 );
1324 });
1325
1326 it("[[Call]] works with big·ints", () => {
1327 assertStrictEquals(toIntegralNumberOrInfinity(2n), 2);
1328 });
1329
1330 it("[[Construct]] throws an error", () => {
1331 assertThrows(() => new toIntegralNumberOrInfinity(1));
1332 });
1333
1334 describe(".length", () => {
1335 it("[[Get]] returns the correct length", () => {
1336 assertStrictEquals(toIntegralNumberOrInfinity.length, 1);
1337 });
1338 });
1339
1340 describe(".name", () => {
1341 it("[[Get]] returns the correct name", () => {
1342 assertStrictEquals(
1343 toIntegralNumberOrInfinity.name,
1344 "toIntegralNumberOrInfinity",
1345 );
1346 });
1347 });
1348 });
1349
1350 describe("toNumber", () => {
1351 it("[[Call]] converts to a number", () => {
1352 assertStrictEquals(toNumber(2n), 2);
1353 });
1354 });
1355
1356 describe("toNumeric", () => {
1357 it("[[Call]] returns a big·int argument", () => {
1358 assertStrictEquals(toNumeric(231n), 231n);
1359 });
1360
1361 it("[[Call]] converts to a numeric", () => {
1362 assertStrictEquals(toNumeric("231"), 231);
1363 });
1364
1365 it("[[Call]] prefers `valueOf`", () => {
1366 assertStrictEquals(
1367 toNumeric({
1368 toString() {
1369 return 0;
1370 },
1371 valueOf() {
1372 return 231n;
1373 },
1374 }),
1375 231n,
1376 );
1377 });
1378
1379 it("[[Construct]] throws an error", () => {
1380 assertThrows(() => new toNumeric(1));
1381 });
1382
1383 describe(".length", () => {
1384 it("[[Get]] returns the correct length", () => {
1385 assertStrictEquals(toNumeric.length, 1);
1386 });
1387 });
1388
1389 describe(".name", () => {
1390 it("[[Get]] returns the correct name", () => {
1391 assertStrictEquals(toNumeric.name, "toNumeric");
1392 });
1393 });
1394 });
1395
1396 describe("toUnsignedIntegralNumeric", () => {
1397 it("[[Call]] converts to an int·n", () => {
1398 assertStrictEquals(toUnsignedIntegralNumeric(2, 7n), 3n);
1399 });
1400
1401 it("[[Call]] works with numbers", () => {
1402 assertStrictEquals(toUnsignedIntegralNumeric(2, 7), 3);
1403 });
1404
1405 it("[[Call]] works with non‐integers", () => {
1406 assertStrictEquals(toUnsignedIntegralNumeric(2, 7.21), 3);
1407 assertStrictEquals(toUnsignedIntegralNumeric(2, Infinity), 0);
1408 });
1409
1410 it("[[Construct]] throws an error", () => {
1411 assertThrows(() => new toUnsignedIntegralNumeric(1, 1));
1412 });
1413
1414 describe(".length", () => {
1415 it("[[Get]] returns the correct length", () => {
1416 assertStrictEquals(toUnsignedIntegralNumeric.length, 2);
1417 });
1418 });
1419
1420 describe(".name", () => {
1421 it("[[Get]] returns the correct name", () => {
1422 assertStrictEquals(
1423 toUnsignedIntegralNumeric.name,
1424 "toUnsignedIntegralNumeric",
1425 );
1426 });
1427 });
1428 });
1429
1430 describe("trunc", () => {
1431 it("[[Call]] returns the trunc", () => {
1432 assertStrictEquals(trunc(1), 1);
1433 assertStrictEquals(trunc(0.5), 0);
1434 assertStrictEquals(trunc(-0.5), -0);
1435 });
1436
1437 it("[[Call]] throws with big·ints", () => {
1438 assertThrows(() => trunc(1n));
1439 });
1440
1441 it("[[Construct]] throws an error", () => {
1442 assertThrows(() => new trunc(1));
1443 });
1444
1445 describe(".length", () => {
1446 it("[[Get]] returns the correct length", () => {
1447 assertStrictEquals(trunc.length, 1);
1448 });
1449 });
1450
1451 describe(".name", () => {
1452 it("[[Get]] returns the correct name", () => {
1453 assertStrictEquals(trunc.name, "trunc");
1454 });
1455 });
1456 });
This page took 0.234299 seconds and 5 git commands to generate.