-
Notifications
You must be signed in to change notification settings - Fork 7
/
number.test.ts
75 lines (65 loc) · 2.29 KB
/
number.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import "./augment.ts";
import { deepStrictEqual, ok, strictEqual } from "node:assert";
describe("Number", () => {
it("Number.isFloat", () => {
ok(Number.isFloat(1.2));
ok(Number.isFloat(Infinity));
ok(Number.isFloat(-Infinity));
ok(Number.isFloat(Number.MIN_VALUE));
ok(!Number.isFloat(Number.MAX_VALUE));
ok(!Number.isFloat(1));
ok(!Number.isFloat("1.2"));
ok(!Number.isFloat("abc"));
ok(!Number.isFloat(NaN));
});
it("Number.isNumeric", () => {
ok(Number.isNumeric(123));
ok(Number.isNumeric(123, true));
ok(Number.isNumeric(Infinity));
ok(Number.isNumeric(Infinity, true));
ok(Number.isNumeric(-Infinity));
ok(Number.isNumeric(-Infinity, true));
ok(Number.isNumeric(Number.MIN_VALUE));
ok(Number.isNumeric(Number.MAX_VALUE));
ok(Number.isNumeric(BigInt(Number.MAX_VALUE)));
ok(!Number.isNumeric(BigInt(Number.MAX_VALUE), true));
ok(Number.isNumeric("123"));
ok(!Number.isNumeric("123", true));
ok(Number.isNumeric("1.23"));
ok(!Number.isNumeric("1.23", true));
ok(Number.isNumeric("0b1010"));
ok(Number.isNumeric("0b1010"));
ok(Number.isNumeric("0o123"));
ok(Number.isNumeric("0x123"));
ok(!Number.isNumeric("12n"));
ok(!Number.isNumeric("12a"));
ok(!Number.isNumeric("abc"));
ok(!Number.isNumeric(""));
ok(!Number.isNumeric(NaN));
});
it("Number.isBetween", () => {
ok(Number.isBetween(1, [1, 2]));
ok(Number.isBetween(2, [1, 2]));
ok(Number.isBetween(2, [1, 3]));
ok(!Number.isBetween(0, [1, 2]));
ok(!Number.isBetween(3, [1, 2]));
});
it("Number.random", () => {
strictEqual(Number.random(0, 0), 0);
const num = Number.random(0, 10);
ok(num >= 0 && num <= 10);
});
it("Number.range", () => {
deepStrictEqual([...Number.range(0, 9)], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
});
it("Number.serial", () => {
const ids: number[] = [];
for (const id of Number.serial()) {
ids.push(id);
if (ids.length === 9) {
break;
}
}
deepStrictEqual(ids, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
});
});