ts-data-forge 4.1.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/impl/array-utils-element-access.mjs +1 -0
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +1 -0
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +2 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +1 -0
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +1 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs +1 -0
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.mjs +1 -0
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/queue.mjs +1 -0
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs +1 -0
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +2 -1
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +2 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/json/json.d.mts +9 -3
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +7 -0
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs +1 -0
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +2 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.mjs +1 -0
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +18 -18
- package/src/array/impl/array-utils-creation.test.mts +187 -74
- package/src/array/impl/array-utils-element-access.test.mts +19 -3
- package/src/array/impl/array-utils-iterators.test.mts +44 -24
- package/src/array/impl/array-utils-modification.test.mts +36 -33
- package/src/array/impl/array-utils-reducing-value.mts +2 -1
- package/src/array/impl/array-utils-reducing-value.test.mts +47 -16
- package/src/array/impl/array-utils-search.test.mts +42 -9
- package/src/array/impl/array-utils-set-op.test.mts +54 -26
- package/src/array/impl/array-utils-size.test.mts +1 -0
- package/src/array/impl/array-utils-slice-clamped.test.mts +20 -11
- package/src/array/impl/array-utils-slicing.test.mts +27 -21
- package/src/array/impl/array-utils-transformation.test.mts +140 -92
- package/src/array/impl/array-utils-validation.test.mts +58 -10
- package/src/array/impl/array.test.mts +5 -5
- package/src/collections/imap-mapped.test.mts +63 -18
- package/src/collections/imap.test.mts +74 -26
- package/src/collections/iset-mapped.test.mts +81 -30
- package/src/collections/iset.test.mts +168 -68
- package/src/collections/queue.test.mts +32 -1
- package/src/collections/stack.test.mts +22 -8
- package/src/functional/match.test.mts +1 -1
- package/src/functional/optional.test.mts +61 -4
- package/src/functional/pipe.test.mts +10 -1
- package/src/functional/result/impl/result-from-throwable.mts +2 -1
- package/src/functional/result.test.mts +127 -4
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +2 -1
- package/src/functional/ternary-result.test.mts +34 -18
- package/src/guard/is-non-empty-string.test.mts +5 -2
- package/src/guard/is-non-null-object.test.mts +3 -5
- package/src/guard/is-primitive.test.mts +5 -3
- package/src/guard/is-record.test.mts +1 -1
- package/src/guard/is-type.test.mts +35 -20
- package/src/guard/key-is-in.test.mts +1 -1
- package/src/iterator/range.test.mts +22 -16
- package/src/json/json.mts +9 -3
- package/src/json/json.test.mts +140 -64
- package/src/number/branded-types/finite-number.test.mts +3 -2
- package/src/number/branded-types/int.test.mts +4 -3
- package/src/number/branded-types/int16.test.mts +9 -3
- package/src/number/branded-types/int32.test.mts +9 -3
- package/src/number/branded-types/non-negative-finite-number.test.mts +6 -4
- package/src/number/branded-types/non-negative-int16.test.mts +8 -3
- package/src/number/branded-types/non-negative-int32.test.mts +8 -3
- package/src/number/branded-types/non-zero-finite-number.test.mts +6 -3
- package/src/number/branded-types/non-zero-int.test.mts +6 -3
- package/src/number/branded-types/non-zero-int16.test.mts +9 -3
- package/src/number/branded-types/non-zero-int32.test.mts +9 -3
- package/src/number/branded-types/non-zero-safe-int.test.mts +10 -3
- package/src/number/branded-types/non-zero-uint16.test.mts +8 -3
- package/src/number/branded-types/non-zero-uint32.test.mts +8 -3
- package/src/number/branded-types/positive-finite-number.test.mts +7 -3
- package/src/number/branded-types/positive-int.test.mts +5 -3
- package/src/number/branded-types/positive-int16.test.mts +8 -3
- package/src/number/branded-types/positive-int32.test.mts +8 -3
- package/src/number/branded-types/positive-safe-int.test.mts +8 -3
- package/src/number/branded-types/positive-uint16.test.mts +8 -3
- package/src/number/branded-types/positive-uint32.test.mts +8 -3
- package/src/number/branded-types/safe-int.test.mts +8 -2
- package/src/number/branded-types/safe-uint.test.mts +8 -3
- package/src/number/branded-types/uint.test.mts +5 -3
- package/src/number/branded-types/uint16.test.mts +8 -3
- package/src/number/branded-types/uint32.test.mts +8 -3
- package/src/number/enum/int8.test.mts +8 -3
- package/src/number/enum/uint8.test.mts +6 -3
- package/src/number/num.test.mts +16 -2
- package/src/object/object.test.mts +26 -13
- package/src/others/cast-mutable.test.mts +10 -8
- package/src/others/cast-readonly.test.mts +9 -5
- package/src/others/if-then.test.mts +4 -1
- package/src/others/map-nullable.test.mts +28 -1
- package/src/others/memoize-function.test.mts +20 -17
- package/src/others/tuple.test.mts +3 -2
- package/src/others/unknown-to-string.mts +2 -1
- package/src/others/unknown-to-string.test.mts +15 -2
- package/src/promise/promise.test.mts +6 -1
|
@@ -2,8 +2,8 @@ import { expectType } from '../../expect-type.mjs';
|
|
|
2
2
|
import { range } from '../../iterator/index.mjs';
|
|
3
3
|
import { asPositiveInt, isPositiveInt, PositiveInt } from './positive-int.mjs';
|
|
4
4
|
|
|
5
|
-
describe('PositiveInt', () => {
|
|
6
|
-
describe(
|
|
5
|
+
describe('PositiveInt test', () => {
|
|
6
|
+
describe(asPositiveInt, () => {
|
|
7
7
|
test('accepts valid positive integers', () => {
|
|
8
8
|
expect(() => asPositiveInt(1)).not.toThrow();
|
|
9
9
|
expect(() => asPositiveInt(2)).not.toThrow();
|
|
@@ -55,7 +55,7 @@ describe('PositiveInt', () => {
|
|
|
55
55
|
);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
describe(
|
|
58
|
+
describe(isPositiveInt, () => {
|
|
59
59
|
test('correctly identifies positive integers', () => {
|
|
60
60
|
expect(isPositiveInt(1)).toBe(true);
|
|
61
61
|
expect(isPositiveInt(2)).toBe(true);
|
|
@@ -146,6 +146,7 @@ describe('PositiveInt', () => {
|
|
|
146
146
|
|
|
147
147
|
for (const _ of range(10)) {
|
|
148
148
|
const result = PositiveInt.random(min, max);
|
|
149
|
+
|
|
149
150
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
150
151
|
expect(result).toBeLessThanOrEqual(max);
|
|
151
152
|
expect(PositiveInt.is(result)).toBe(true);
|
|
@@ -160,6 +161,7 @@ describe('PositiveInt', () => {
|
|
|
160
161
|
|
|
161
162
|
for (const _ of range(10)) {
|
|
162
163
|
const result = PositiveInt.random(min, max);
|
|
164
|
+
|
|
163
165
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
164
166
|
expect(result).toBeLessThanOrEqual(5);
|
|
165
167
|
expect(result).toBeGreaterThan(0);
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
PositiveInt16,
|
|
7
7
|
} from './positive-int16.mjs';
|
|
8
8
|
|
|
9
|
-
describe('PositiveInt16', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('PositiveInt16 test', () => {
|
|
10
|
+
describe(asPositiveInt16, () => {
|
|
11
11
|
test('accepts valid positive int16 values', () => {
|
|
12
12
|
expect(() => asPositiveInt16(1)).not.toThrow();
|
|
13
13
|
expect(() => asPositiveInt16(1000)).not.toThrow();
|
|
@@ -67,7 +67,7 @@ describe('PositiveInt16', () => {
|
|
|
67
67
|
);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
describe(
|
|
70
|
+
describe(isPositiveInt16, () => {
|
|
71
71
|
test('correctly identifies positive int16 values', () => {
|
|
72
72
|
expect(isPositiveInt16(1)).toBe(true);
|
|
73
73
|
expect(isPositiveInt16(1000)).toBe(true);
|
|
@@ -126,6 +126,7 @@ describe('PositiveInt16', () => {
|
|
|
126
126
|
asPositiveInt16(32_000),
|
|
127
127
|
asPositiveInt16(1000),
|
|
128
128
|
);
|
|
129
|
+
|
|
129
130
|
expect(result).toBe(32_767); // clamped to max
|
|
130
131
|
expect(PositiveInt16.add(a, b)).toBe(150);
|
|
131
132
|
});
|
|
@@ -140,6 +141,7 @@ describe('PositiveInt16', () => {
|
|
|
140
141
|
asPositiveInt16(1000),
|
|
141
142
|
asPositiveInt16(100),
|
|
142
143
|
);
|
|
144
|
+
|
|
143
145
|
expect(result).toBe(32_767); // clamped to max
|
|
144
146
|
expect(PositiveInt16.mul(asPositiveInt16(10), asPositiveInt16(5))).toBe(
|
|
145
147
|
50,
|
|
@@ -159,6 +161,7 @@ describe('PositiveInt16', () => {
|
|
|
159
161
|
asPositiveInt16(200),
|
|
160
162
|
asPositiveInt16(3),
|
|
161
163
|
);
|
|
164
|
+
|
|
162
165
|
expect(result).toBe(32_767); // clamped to max
|
|
163
166
|
expect(PositiveInt16.pow(asPositiveInt16(2), asPositiveInt16(3))).toBe(8);
|
|
164
167
|
});
|
|
@@ -171,6 +174,7 @@ describe('PositiveInt16', () => {
|
|
|
171
174
|
|
|
172
175
|
for (const _ of range(10)) {
|
|
173
176
|
const result = PositiveInt16.random(min, max);
|
|
177
|
+
|
|
174
178
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
175
179
|
expect(result).toBeLessThanOrEqual(max);
|
|
176
180
|
expect(PositiveInt16.is(result)).toBe(true);
|
|
@@ -182,6 +186,7 @@ describe('PositiveInt16', () => {
|
|
|
182
186
|
test('generates values within PositiveInt16 range', () => {
|
|
183
187
|
for (const _ of range(10)) {
|
|
184
188
|
const result = PositiveInt16.random(1, 30);
|
|
189
|
+
|
|
185
190
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
186
191
|
expect(result).toBeLessThanOrEqual(32_767);
|
|
187
192
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
PositiveInt32,
|
|
7
7
|
} from './positive-int32.mjs';
|
|
8
8
|
|
|
9
|
-
describe('PositiveInt32', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('PositiveInt32 test', () => {
|
|
10
|
+
describe(asPositiveInt32, () => {
|
|
11
11
|
test('accepts valid positive int32 values', () => {
|
|
12
12
|
expect(() => asPositiveInt32(1)).not.toThrow();
|
|
13
13
|
expect(() => asPositiveInt32(1000)).not.toThrow();
|
|
@@ -67,7 +67,7 @@ describe('PositiveInt32', () => {
|
|
|
67
67
|
);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
describe(
|
|
70
|
+
describe(isPositiveInt32, () => {
|
|
71
71
|
test('correctly identifies positive int32 values', () => {
|
|
72
72
|
expect(isPositiveInt32(1)).toBe(true);
|
|
73
73
|
expect(isPositiveInt32(1000)).toBe(true);
|
|
@@ -126,6 +126,7 @@ describe('PositiveInt32', () => {
|
|
|
126
126
|
asPositiveInt32(2_147_483_000),
|
|
127
127
|
asPositiveInt32(1000),
|
|
128
128
|
);
|
|
129
|
+
|
|
129
130
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
130
131
|
expect(PositiveInt32.add(a, b)).toBe(1_500_000);
|
|
131
132
|
});
|
|
@@ -140,6 +141,7 @@ describe('PositiveInt32', () => {
|
|
|
140
141
|
asPositiveInt32(100_000),
|
|
141
142
|
asPositiveInt32(100_000),
|
|
142
143
|
);
|
|
144
|
+
|
|
143
145
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
144
146
|
expect(PositiveInt32.mul(asPositiveInt32(1000), asPositiveInt32(5))).toBe(
|
|
145
147
|
5000,
|
|
@@ -159,6 +161,7 @@ describe('PositiveInt32', () => {
|
|
|
159
161
|
asPositiveInt32(10_000),
|
|
160
162
|
asPositiveInt32(3),
|
|
161
163
|
);
|
|
164
|
+
|
|
162
165
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
163
166
|
expect(PositiveInt32.pow(asPositiveInt32(2), asPositiveInt32(3))).toBe(8);
|
|
164
167
|
});
|
|
@@ -171,6 +174,7 @@ describe('PositiveInt32', () => {
|
|
|
171
174
|
|
|
172
175
|
for (const _ of range(10)) {
|
|
173
176
|
const result = PositiveInt32.random(min, max);
|
|
177
|
+
|
|
174
178
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
175
179
|
expect(result).toBeLessThanOrEqual(max);
|
|
176
180
|
expect(PositiveInt32.is(result)).toBe(true);
|
|
@@ -182,6 +186,7 @@ describe('PositiveInt32', () => {
|
|
|
182
186
|
test('generates values within PositiveInt32 range', () => {
|
|
183
187
|
for (const _ of range(10)) {
|
|
184
188
|
const result = PositiveInt32.random(1, 30);
|
|
189
|
+
|
|
185
190
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
186
191
|
expect(result).toBeLessThanOrEqual(2_147_483_647);
|
|
187
192
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
PositiveSafeInt,
|
|
7
7
|
} from './positive-safe-int.mjs';
|
|
8
8
|
|
|
9
|
-
describe('PositiveSafeInt', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('PositiveSafeInt test', () => {
|
|
10
|
+
describe(asPositiveSafeInt, () => {
|
|
11
11
|
test('accepts valid positive safe integers', () => {
|
|
12
12
|
expect(() => asPositiveSafeInt(1)).not.toThrow();
|
|
13
13
|
expect(() => asPositiveSafeInt(2)).not.toThrow();
|
|
@@ -72,7 +72,7 @@ describe('PositiveSafeInt', () => {
|
|
|
72
72
|
);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
describe(
|
|
75
|
+
describe(isPositiveSafeInt, () => {
|
|
76
76
|
test('correctly identifies positive safe integers', () => {
|
|
77
77
|
expect(isPositiveSafeInt(1)).toBe(true);
|
|
78
78
|
expect(isPositiveSafeInt(2)).toBe(true);
|
|
@@ -136,6 +136,7 @@ describe('PositiveSafeInt', () => {
|
|
|
136
136
|
test('add (clamped to positive safe int range)', () => {
|
|
137
137
|
const largeValue = asPositiveSafeInt(Number.MAX_SAFE_INTEGER - 1);
|
|
138
138
|
const result = PositiveSafeInt.add(largeValue, asPositiveSafeInt(10));
|
|
139
|
+
|
|
139
140
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
140
141
|
expect(PositiveSafeInt.add(a, b)).toBe(7);
|
|
141
142
|
});
|
|
@@ -151,6 +152,7 @@ describe('PositiveSafeInt', () => {
|
|
|
151
152
|
Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)),
|
|
152
153
|
);
|
|
153
154
|
const result = PositiveSafeInt.mul(largeValue, largeValue);
|
|
155
|
+
|
|
154
156
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
155
157
|
expect(
|
|
156
158
|
PositiveSafeInt.mul(asPositiveSafeInt(10), asPositiveSafeInt(5)),
|
|
@@ -170,6 +172,7 @@ describe('PositiveSafeInt', () => {
|
|
|
170
172
|
asPositiveSafeInt(1000),
|
|
171
173
|
asPositiveSafeInt(10),
|
|
172
174
|
);
|
|
175
|
+
|
|
173
176
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
174
177
|
expect(
|
|
175
178
|
PositiveSafeInt.pow(asPositiveSafeInt(2), asPositiveSafeInt(3)),
|
|
@@ -184,6 +187,7 @@ describe('PositiveSafeInt', () => {
|
|
|
184
187
|
|
|
185
188
|
for (const _ of range(10)) {
|
|
186
189
|
const result = PositiveSafeInt.random(min, max);
|
|
190
|
+
|
|
187
191
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
188
192
|
expect(result).toBeLessThanOrEqual(max);
|
|
189
193
|
expect(PositiveSafeInt.is(result)).toBe(true);
|
|
@@ -195,6 +199,7 @@ describe('PositiveSafeInt', () => {
|
|
|
195
199
|
test('generates values within positive safe int range', () => {
|
|
196
200
|
for (const _ of range(10)) {
|
|
197
201
|
const result = PositiveSafeInt.random(1, 30);
|
|
202
|
+
|
|
198
203
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
199
204
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
200
205
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
PositiveUint16,
|
|
7
7
|
} from './positive-uint16.mjs';
|
|
8
8
|
|
|
9
|
-
describe('PositiveUint16', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('PositiveUint16 test', () => {
|
|
10
|
+
describe(asPositiveUint16, () => {
|
|
11
11
|
test('accepts valid positive uint16 values', () => {
|
|
12
12
|
expect(() => asPositiveUint16(1)).not.toThrow();
|
|
13
13
|
expect(() => asPositiveUint16(1000)).not.toThrow();
|
|
@@ -68,7 +68,7 @@ describe('PositiveUint16', () => {
|
|
|
68
68
|
);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
describe(
|
|
71
|
+
describe(isPositiveUint16, () => {
|
|
72
72
|
test('correctly identifies positive uint16 values', () => {
|
|
73
73
|
expect(isPositiveUint16(1)).toBe(true);
|
|
74
74
|
expect(isPositiveUint16(1000)).toBe(true);
|
|
@@ -128,6 +128,7 @@ describe('PositiveUint16', () => {
|
|
|
128
128
|
asPositiveUint16(65_000),
|
|
129
129
|
asPositiveUint16(1000),
|
|
130
130
|
);
|
|
131
|
+
|
|
131
132
|
expect(result).toBe(65_535); // clamped to max
|
|
132
133
|
expect(PositiveUint16.add(a, b)).toBe(150);
|
|
133
134
|
});
|
|
@@ -142,6 +143,7 @@ describe('PositiveUint16', () => {
|
|
|
142
143
|
asPositiveUint16(1000),
|
|
143
144
|
asPositiveUint16(100),
|
|
144
145
|
);
|
|
146
|
+
|
|
145
147
|
expect(result).toBe(65_535); // clamped to max
|
|
146
148
|
expect(
|
|
147
149
|
PositiveUint16.mul(asPositiveUint16(10), asPositiveUint16(5)),
|
|
@@ -163,6 +165,7 @@ describe('PositiveUint16', () => {
|
|
|
163
165
|
asPositiveUint16(256),
|
|
164
166
|
asPositiveUint16(3),
|
|
165
167
|
);
|
|
168
|
+
|
|
166
169
|
expect(result).toBe(65_535); // clamped to max
|
|
167
170
|
expect(PositiveUint16.pow(asPositiveUint16(2), asPositiveUint16(3))).toBe(
|
|
168
171
|
8,
|
|
@@ -177,6 +180,7 @@ describe('PositiveUint16', () => {
|
|
|
177
180
|
|
|
178
181
|
for (const _ of range(10)) {
|
|
179
182
|
const result = PositiveUint16.random(min, max);
|
|
183
|
+
|
|
180
184
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
181
185
|
expect(result).toBeLessThanOrEqual(max);
|
|
182
186
|
expect(PositiveUint16.is(result)).toBe(true);
|
|
@@ -188,6 +192,7 @@ describe('PositiveUint16', () => {
|
|
|
188
192
|
test('generates values within PositiveUint16 range', () => {
|
|
189
193
|
for (const _ of range(10)) {
|
|
190
194
|
const result = PositiveUint16.random(1, 30);
|
|
195
|
+
|
|
191
196
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
192
197
|
expect(result).toBeLessThanOrEqual(65_535);
|
|
193
198
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
PositiveUint32,
|
|
7
7
|
} from './positive-uint32.mjs';
|
|
8
8
|
|
|
9
|
-
describe('PositiveUint32', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('PositiveUint32 test', () => {
|
|
10
|
+
describe(asPositiveUint32, () => {
|
|
11
11
|
test('accepts valid positive uint32 values', () => {
|
|
12
12
|
expect(() => asPositiveUint32(1)).not.toThrow();
|
|
13
13
|
expect(() => asPositiveUint32(1000)).not.toThrow();
|
|
@@ -68,7 +68,7 @@ describe('PositiveUint32', () => {
|
|
|
68
68
|
);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
describe(
|
|
71
|
+
describe(isPositiveUint32, () => {
|
|
72
72
|
test('correctly identifies positive uint32 values', () => {
|
|
73
73
|
expect(isPositiveUint32(1)).toBe(true);
|
|
74
74
|
expect(isPositiveUint32(1000)).toBe(true);
|
|
@@ -128,6 +128,7 @@ describe('PositiveUint32', () => {
|
|
|
128
128
|
asPositiveUint32(4_294_967_000),
|
|
129
129
|
asPositiveUint32(1000),
|
|
130
130
|
);
|
|
131
|
+
|
|
131
132
|
expect(result).toBe(4_294_967_295); // clamped to max
|
|
132
133
|
expect(PositiveUint32.add(a, b)).toBe(1_500_000);
|
|
133
134
|
});
|
|
@@ -142,6 +143,7 @@ describe('PositiveUint32', () => {
|
|
|
142
143
|
asPositiveUint32(100_000),
|
|
143
144
|
asPositiveUint32(100_000),
|
|
144
145
|
);
|
|
146
|
+
|
|
145
147
|
expect(result).toBe(4_294_967_295); // clamped to max
|
|
146
148
|
expect(
|
|
147
149
|
PositiveUint32.mul(asPositiveUint32(1000), asPositiveUint32(5)),
|
|
@@ -166,6 +168,7 @@ describe('PositiveUint32', () => {
|
|
|
166
168
|
asPositiveUint32(10_000),
|
|
167
169
|
asPositiveUint32(3),
|
|
168
170
|
);
|
|
171
|
+
|
|
169
172
|
expect(result).toBe(4_294_967_295); // clamped to max
|
|
170
173
|
expect(PositiveUint32.pow(asPositiveUint32(2), asPositiveUint32(3))).toBe(
|
|
171
174
|
8,
|
|
@@ -180,6 +183,7 @@ describe('PositiveUint32', () => {
|
|
|
180
183
|
|
|
181
184
|
for (const _ of range(10)) {
|
|
182
185
|
const result = PositiveUint32.random(min, max);
|
|
186
|
+
|
|
183
187
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
184
188
|
expect(result).toBeLessThanOrEqual(max);
|
|
185
189
|
expect(PositiveUint32.is(result)).toBe(true);
|
|
@@ -191,6 +195,7 @@ describe('PositiveUint32', () => {
|
|
|
191
195
|
test('generates values within PositiveUint32 range', () => {
|
|
192
196
|
for (const _ of range(10)) {
|
|
193
197
|
const result = PositiveUint32.random(1, 30);
|
|
198
|
+
|
|
194
199
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
195
200
|
expect(result).toBeLessThanOrEqual(4_294_967_295);
|
|
196
201
|
}
|
|
@@ -2,8 +2,8 @@ import { expectType } from '../../expect-type.mjs';
|
|
|
2
2
|
import { range } from '../../iterator/index.mjs';
|
|
3
3
|
import { asSafeInt, SafeInt } from './safe-int.mjs';
|
|
4
4
|
|
|
5
|
-
describe('SafeInt', () => {
|
|
6
|
-
describe(
|
|
5
|
+
describe('SafeInt test', () => {
|
|
6
|
+
describe(asSafeInt, () => {
|
|
7
7
|
test('accepts valid safe integers', () => {
|
|
8
8
|
expect(() => asSafeInt(0)).not.toThrow();
|
|
9
9
|
expect(() => asSafeInt(1)).not.toThrow();
|
|
@@ -105,6 +105,7 @@ describe('SafeInt', () => {
|
|
|
105
105
|
test('add (with clamping to safe integer range)', () => {
|
|
106
106
|
const largeValue = asSafeInt(Number.MAX_SAFE_INTEGER - 1);
|
|
107
107
|
const result = SafeInt.add(largeValue, asSafeInt(10));
|
|
108
|
+
|
|
108
109
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
109
110
|
expect(SafeInt.add(a, b)).toBe(7);
|
|
110
111
|
});
|
|
@@ -112,6 +113,7 @@ describe('SafeInt', () => {
|
|
|
112
113
|
test('sub (with clamping to safe integer range)', () => {
|
|
113
114
|
const smallValue = asSafeInt(Number.MIN_SAFE_INTEGER + 1);
|
|
114
115
|
const result = SafeInt.sub(smallValue, asSafeInt(10));
|
|
116
|
+
|
|
115
117
|
expect(result).toBe(Number.MIN_SAFE_INTEGER); // clamped to min
|
|
116
118
|
expect(SafeInt.sub(a, b)).toBe(3);
|
|
117
119
|
});
|
|
@@ -121,6 +123,7 @@ describe('SafeInt', () => {
|
|
|
121
123
|
Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)),
|
|
122
124
|
);
|
|
123
125
|
const result = SafeInt.mul(largeValue, largeValue);
|
|
126
|
+
|
|
124
127
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
125
128
|
expect(SafeInt.mul(asSafeInt(10), asSafeInt(5))).toBe(50);
|
|
126
129
|
});
|
|
@@ -133,6 +136,7 @@ describe('SafeInt', () => {
|
|
|
133
136
|
|
|
134
137
|
test('pow (with clamping to safe integer range)', () => {
|
|
135
138
|
const result = SafeInt.pow(asSafeInt(1000), asSafeInt(10));
|
|
139
|
+
|
|
136
140
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
137
141
|
expect(SafeInt.pow(asSafeInt(2), asSafeInt(3))).toBe(8);
|
|
138
142
|
});
|
|
@@ -145,6 +149,7 @@ describe('SafeInt', () => {
|
|
|
145
149
|
|
|
146
150
|
for (const _ of range(10)) {
|
|
147
151
|
const result = SafeInt.random(min, max);
|
|
152
|
+
|
|
148
153
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
149
154
|
expect(result).toBeLessThanOrEqual(max);
|
|
150
155
|
expect(SafeInt.is(result)).toBe(true);
|
|
@@ -155,6 +160,7 @@ describe('SafeInt', () => {
|
|
|
155
160
|
test('generates values within safe integer range', () => {
|
|
156
161
|
for (const _ of range(10)) {
|
|
157
162
|
const result = SafeInt.random(-30, 30);
|
|
163
|
+
|
|
158
164
|
expect(result).toBeGreaterThanOrEqual(Number.MIN_SAFE_INTEGER);
|
|
159
165
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
160
166
|
}
|
|
@@ -2,8 +2,8 @@ import { expectType } from '../../expect-type.mjs';
|
|
|
2
2
|
import { range } from '../../iterator/index.mjs';
|
|
3
3
|
import { asSafeUint, isSafeUint, SafeUint } from './safe-uint.mjs';
|
|
4
4
|
|
|
5
|
-
describe('SafeUint', () => {
|
|
6
|
-
describe(
|
|
5
|
+
describe('SafeUint test', () => {
|
|
6
|
+
describe(asSafeUint, () => {
|
|
7
7
|
test('accepts valid safe unsigned integers', () => {
|
|
8
8
|
expect(() => asSafeUint(0)).not.toThrow();
|
|
9
9
|
expect(() => asSafeUint(1)).not.toThrow();
|
|
@@ -52,7 +52,7 @@ describe('SafeUint', () => {
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
describe(
|
|
55
|
+
describe(isSafeUint, () => {
|
|
56
56
|
test('correctly identifies safe unsigned integers', () => {
|
|
57
57
|
expect(isSafeUint(0)).toBe(true);
|
|
58
58
|
expect(isSafeUint(1)).toBe(true);
|
|
@@ -111,6 +111,7 @@ describe('SafeUint', () => {
|
|
|
111
111
|
test('add (clamped to safe uint range)', () => {
|
|
112
112
|
const largeValue = asSafeUint(Number.MAX_SAFE_INTEGER - 1);
|
|
113
113
|
const result = SafeUint.add(largeValue, asSafeUint(10));
|
|
114
|
+
|
|
114
115
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
115
116
|
expect(SafeUint.add(a, b)).toBe(7);
|
|
116
117
|
});
|
|
@@ -126,6 +127,7 @@ describe('SafeUint', () => {
|
|
|
126
127
|
Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)),
|
|
127
128
|
);
|
|
128
129
|
const result = SafeUint.mul(largeValue, largeValue);
|
|
130
|
+
|
|
129
131
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
130
132
|
expect(SafeUint.mul(asSafeUint(10), asSafeUint(5))).toBe(50);
|
|
131
133
|
});
|
|
@@ -138,6 +140,7 @@ describe('SafeUint', () => {
|
|
|
138
140
|
|
|
139
141
|
test('pow (clamped to safe uint range)', () => {
|
|
140
142
|
const result = SafeUint.pow(asSafeUint(1000), asSafeUint(10));
|
|
143
|
+
|
|
141
144
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
142
145
|
expect(SafeUint.pow(asSafeUint(2), asSafeUint(3))).toBe(8);
|
|
143
146
|
});
|
|
@@ -150,6 +153,7 @@ describe('SafeUint', () => {
|
|
|
150
153
|
|
|
151
154
|
for (const _ of range(10)) {
|
|
152
155
|
const result = SafeUint.random(min, max);
|
|
156
|
+
|
|
153
157
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
154
158
|
expect(result).toBeLessThanOrEqual(max);
|
|
155
159
|
expect(SafeUint.is(result)).toBe(true);
|
|
@@ -161,6 +165,7 @@ describe('SafeUint', () => {
|
|
|
161
165
|
test('generates values within safe uint range', () => {
|
|
162
166
|
for (const _ of range(10)) {
|
|
163
167
|
const result = SafeUint.random(0, 30);
|
|
168
|
+
|
|
164
169
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
165
170
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
166
171
|
}
|
|
@@ -2,8 +2,8 @@ import { expectType } from '../../expect-type.mjs';
|
|
|
2
2
|
import { range } from '../../iterator/index.mjs';
|
|
3
3
|
import { asUint, isUint, Uint } from './uint.mjs';
|
|
4
4
|
|
|
5
|
-
describe('Uint', () => {
|
|
6
|
-
describe(
|
|
5
|
+
describe('Uint test', () => {
|
|
6
|
+
describe(asUint, () => {
|
|
7
7
|
test('accepts valid unsigned integers', () => {
|
|
8
8
|
expect(() => asUint(0)).not.toThrow();
|
|
9
9
|
expect(() => asUint(1)).not.toThrow();
|
|
@@ -46,7 +46,7 @@ describe('Uint', () => {
|
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
describe(
|
|
49
|
+
describe(isUint, () => {
|
|
50
50
|
test('correctly identifies unsigned integers', () => {
|
|
51
51
|
expect(isUint(0)).toBe(true);
|
|
52
52
|
expect(isUint(1)).toBe(true);
|
|
@@ -132,6 +132,7 @@ describe('Uint', () => {
|
|
|
132
132
|
|
|
133
133
|
for (const _ of range(10)) {
|
|
134
134
|
const result = Uint.random(min, max);
|
|
135
|
+
|
|
135
136
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
136
137
|
expect(result).toBeLessThanOrEqual(max);
|
|
137
138
|
expect(Uint.is(result)).toBe(true);
|
|
@@ -143,6 +144,7 @@ describe('Uint', () => {
|
|
|
143
144
|
test('generates values starting from 0', () => {
|
|
144
145
|
for (const _ of range(10)) {
|
|
145
146
|
const result = Uint.random(0, 30);
|
|
147
|
+
|
|
146
148
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
147
149
|
expect(result).toBeLessThanOrEqual(30);
|
|
148
150
|
}
|
|
@@ -3,8 +3,8 @@ import { range } from '../../iterator/index.mjs';
|
|
|
3
3
|
import { asNonZeroUint16 } from './non-zero-uint16.mjs';
|
|
4
4
|
import { asUint16, isUint16, Uint16 } from './uint16.mjs';
|
|
5
5
|
|
|
6
|
-
describe('Uint16', () => {
|
|
7
|
-
describe(
|
|
6
|
+
describe('Uint16 test', () => {
|
|
7
|
+
describe(asUint16, () => {
|
|
8
8
|
test('accepts valid uint16 values', () => {
|
|
9
9
|
expect(() => asUint16(0)).not.toThrow();
|
|
10
10
|
expect(() => asUint16(1)).not.toThrow();
|
|
@@ -52,7 +52,7 @@ describe('Uint16', () => {
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
describe(
|
|
55
|
+
describe(isUint16, () => {
|
|
56
56
|
test('correctly identifies uint16 values', () => {
|
|
57
57
|
expect(isUint16(0)).toBe(true);
|
|
58
58
|
expect(isUint16(1)).toBe(true);
|
|
@@ -108,6 +108,7 @@ describe('Uint16', () => {
|
|
|
108
108
|
|
|
109
109
|
test('add (with clamping to uint16 range)', () => {
|
|
110
110
|
const result = Uint16.add(asUint16(65_000), asUint16(1000));
|
|
111
|
+
|
|
111
112
|
expect(result).toBe(65_535); // clamped to max
|
|
112
113
|
expect(Uint16.add(a, b)).toBe(150);
|
|
113
114
|
});
|
|
@@ -120,6 +121,7 @@ describe('Uint16', () => {
|
|
|
120
121
|
|
|
121
122
|
test('mul (with clamping to uint16 range)', () => {
|
|
122
123
|
const result = Uint16.mul(asUint16(1000), asUint16(100));
|
|
124
|
+
|
|
123
125
|
expect(result).toBe(65_535); // clamped to max
|
|
124
126
|
expect(Uint16.mul(asUint16(10), asUint16(5))).toBe(50);
|
|
125
127
|
});
|
|
@@ -132,6 +134,7 @@ describe('Uint16', () => {
|
|
|
132
134
|
|
|
133
135
|
test('pow (with clamping to uint16 range)', () => {
|
|
134
136
|
const result = Uint16.pow(asUint16(256), asUint16(3));
|
|
137
|
+
|
|
135
138
|
expect(result).toBe(65_535); // clamped to max
|
|
136
139
|
expect(Uint16.pow(asUint16(2), asUint16(3))).toBe(8);
|
|
137
140
|
});
|
|
@@ -144,6 +147,7 @@ describe('Uint16', () => {
|
|
|
144
147
|
|
|
145
148
|
for (const _ of range(10)) {
|
|
146
149
|
const result = Uint16.random(min, max);
|
|
150
|
+
|
|
147
151
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
148
152
|
expect(result).toBeLessThanOrEqual(max);
|
|
149
153
|
expect(Uint16.is(result)).toBe(true);
|
|
@@ -155,6 +159,7 @@ describe('Uint16', () => {
|
|
|
155
159
|
test('generates values within Uint16 range', () => {
|
|
156
160
|
for (const _ of range(10)) {
|
|
157
161
|
const result = Uint16.random(0, 30);
|
|
162
|
+
|
|
158
163
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
159
164
|
expect(result).toBeLessThanOrEqual(65_535);
|
|
160
165
|
}
|
|
@@ -3,8 +3,8 @@ import { range } from '../../iterator/index.mjs';
|
|
|
3
3
|
import { asNonZeroUint32 } from './non-zero-uint32.mjs';
|
|
4
4
|
import { asUint32, isUint32, Uint32 } from './uint32.mjs';
|
|
5
5
|
|
|
6
|
-
describe('Uint32', () => {
|
|
7
|
-
describe(
|
|
6
|
+
describe('Uint32 test', () => {
|
|
7
|
+
describe(asUint32, () => {
|
|
8
8
|
test('accepts valid uint32 values', () => {
|
|
9
9
|
expect(() => asUint32(0)).not.toThrow();
|
|
10
10
|
expect(() => asUint32(1)).not.toThrow();
|
|
@@ -52,7 +52,7 @@ describe('Uint32', () => {
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
describe(
|
|
55
|
+
describe(isUint32, () => {
|
|
56
56
|
test('correctly identifies uint32 values', () => {
|
|
57
57
|
expect(isUint32(0)).toBe(true);
|
|
58
58
|
expect(isUint32(1)).toBe(true);
|
|
@@ -108,6 +108,7 @@ describe('Uint32', () => {
|
|
|
108
108
|
|
|
109
109
|
test('add (with clamping to uint32 range)', () => {
|
|
110
110
|
const result = Uint32.add(asUint32(4_294_967_000), asUint32(1000));
|
|
111
|
+
|
|
111
112
|
expect(result).toBe(4_294_967_295); // clamped to max
|
|
112
113
|
expect(Uint32.add(a, b)).toBe(1_500_000);
|
|
113
114
|
});
|
|
@@ -120,6 +121,7 @@ describe('Uint32', () => {
|
|
|
120
121
|
|
|
121
122
|
test('mul (with clamping to uint32 range)', () => {
|
|
122
123
|
const result = Uint32.mul(asUint32(100_000), asUint32(100_000));
|
|
124
|
+
|
|
123
125
|
expect(result).toBe(4_294_967_295); // clamped to max
|
|
124
126
|
expect(Uint32.mul(asUint32(1000), asUint32(5))).toBe(5000);
|
|
125
127
|
});
|
|
@@ -132,6 +134,7 @@ describe('Uint32', () => {
|
|
|
132
134
|
|
|
133
135
|
test('pow (with clamping to uint32 range)', () => {
|
|
134
136
|
const result = Uint32.pow(asUint32(10_000), asUint32(3));
|
|
137
|
+
|
|
135
138
|
expect(result).toBe(4_294_967_295); // clamped to max
|
|
136
139
|
expect(Uint32.pow(asUint32(2), asUint32(3))).toBe(8);
|
|
137
140
|
});
|
|
@@ -144,6 +147,7 @@ describe('Uint32', () => {
|
|
|
144
147
|
|
|
145
148
|
for (const _ of range(10)) {
|
|
146
149
|
const result = Uint32.random(min, max);
|
|
150
|
+
|
|
147
151
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
148
152
|
expect(result).toBeLessThanOrEqual(max);
|
|
149
153
|
expect(Uint32.is(result)).toBe(true);
|
|
@@ -155,6 +159,7 @@ describe('Uint32', () => {
|
|
|
155
159
|
test('generates values within Uint32 range', () => {
|
|
156
160
|
for (const _ of range(10)) {
|
|
157
161
|
const result = Uint32.random(0, 30);
|
|
162
|
+
|
|
158
163
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
159
164
|
expect(result).toBeLessThanOrEqual(4_294_967_295);
|
|
160
165
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
2
|
import { Int8, asInt8, isInt8 } from './int8.mjs';
|
|
3
3
|
|
|
4
|
-
describe('Int8', () => {
|
|
5
|
-
describe(
|
|
4
|
+
describe('Int8 test', () => {
|
|
5
|
+
describe(isInt8, () => {
|
|
6
6
|
test.each([
|
|
7
7
|
{ value: -128, expected: true },
|
|
8
8
|
{ value: 0, expected: true },
|
|
@@ -18,7 +18,7 @@ describe('Int8', () => {
|
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
describe(
|
|
21
|
+
describe(asInt8, () => {
|
|
22
22
|
test.each([
|
|
23
23
|
{ value: -128, expected: -128 },
|
|
24
24
|
{ value: 0, expected: 0 },
|
|
@@ -48,6 +48,7 @@ describe('Int8', () => {
|
|
|
48
48
|
describe('Int8.MIN_VALUE', () => {
|
|
49
49
|
test('should be -128', () => {
|
|
50
50
|
expect(Int8.MIN_VALUE).toBe(-128);
|
|
51
|
+
|
|
51
52
|
expectType<typeof Int8.MIN_VALUE, -128>('=');
|
|
52
53
|
});
|
|
53
54
|
});
|
|
@@ -55,6 +56,7 @@ describe('Int8', () => {
|
|
|
55
56
|
describe('Int8.MAX_VALUE', () => {
|
|
56
57
|
test('should be 127', () => {
|
|
57
58
|
expect(Int8.MAX_VALUE).toBe(127);
|
|
59
|
+
|
|
58
60
|
expectType<typeof Int8.MAX_VALUE, 127>('=');
|
|
59
61
|
});
|
|
60
62
|
});
|
|
@@ -96,7 +98,9 @@ describe('Int8', () => {
|
|
|
96
98
|
'Int8.abs($value) should return $expected',
|
|
97
99
|
({ expected, value }) => {
|
|
98
100
|
const result = Int8.abs(value);
|
|
101
|
+
|
|
99
102
|
expect(result).toBe(expected);
|
|
103
|
+
|
|
100
104
|
expectType<typeof result, typeof expected>('=');
|
|
101
105
|
},
|
|
102
106
|
);
|
|
@@ -172,6 +176,7 @@ describe('Int8', () => {
|
|
|
172
176
|
const min = -10;
|
|
173
177
|
const max = 10;
|
|
174
178
|
const result = Int8.random(min, max);
|
|
179
|
+
|
|
175
180
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
176
181
|
expect(result).toBeLessThanOrEqual(max);
|
|
177
182
|
expect(Number.isInteger(result)).toBe(true);
|