ts-data-forge 2.1.0 → 2.1.2
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/README.md +13 -15
- package/dist/array/array-utils.mjs +8 -8
- package/dist/array/array-utils.mjs.map +1 -1
- package/dist/collections/imap.d.mts +1 -1
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +1 -1
- package/dist/collections/iset-mapped.mjs +1 -1
- package/dist/collections/iset.d.mts +2 -2
- package/dist/collections/iset.mjs +2 -2
- package/dist/collections/queue.d.mts +1 -1
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +7 -8
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +1 -1
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +6 -7
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.d.mts.map +1 -1
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs +1 -6
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/result.d.mts.map +1 -1
- package/dist/functional/result.mjs +3 -6
- package/dist/functional/result.mjs.map +1 -1
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs.map +1 -1
- package/dist/others/memoize-function.d.mts +1 -1
- package/dist/others/memoize-function.mjs +1 -1
- package/package.json +12 -3
- package/src/array/array-utils-creation.test.mts +9 -8
- package/src/array/array-utils-overload-type-error.test.mts +6 -2
- package/src/array/array-utils-search.test.mts +1 -1
- package/src/array/array-utils-slicing.test.mts +0 -42
- package/src/array/array-utils-transformation.test.mts +11 -186
- package/src/array/array-utils-validation.test.mts +27 -27
- package/src/array/array-utils.mts +7 -7
- package/src/collections/imap-mapped.test.mts +15 -11
- package/src/collections/imap.mts +2 -3
- package/src/collections/imap.test.mts +20 -19
- package/src/collections/iset-mapped.mts +1 -1
- package/src/collections/iset-mapped.test.mts +14 -104
- package/src/collections/iset.mts +3 -3
- package/src/collections/iset.test.mts +43 -34
- package/src/collections/queue.mts +12 -10
- package/src/collections/queue.test.mts +46 -44
- package/src/collections/stack.mts +10 -9
- package/src/collections/stack.test.mts +12 -10
- package/src/entry-point.mts +1 -0
- package/src/functional/match.mts +1 -5
- package/src/functional/optional.test.mts +7 -7
- package/src/functional/result.mts +3 -5
- package/src/guard/is-non-empty-string.test.mts +1 -1
- package/src/guard/is-non-null-object.test.mts +3 -3
- package/src/guard/is-primitive.test.mts +6 -6
- package/src/guard/is-type.test.mts +8 -12
- package/src/iterator/range.test.mts +1 -1
- package/src/json/json.mts +1 -2
- package/src/json/json.test.mts +25 -28
- package/src/number/branded-types/finite-number.test.mts +2 -1
- package/src/number/branded-types/int.test.mts +2 -1
- package/src/number/branded-types/int16.test.mts +3 -2
- package/src/number/branded-types/int32.test.mts +3 -2
- package/src/number/branded-types/non-negative-finite-number.test.mts +3 -2
- package/src/number/branded-types/non-negative-int16.test.mts +3 -2
- package/src/number/branded-types/non-negative-int32.test.mts +3 -2
- package/src/number/branded-types/non-zero-finite-number.test.mts +4 -3
- package/src/number/branded-types/non-zero-int.test.mts +4 -3
- package/src/number/branded-types/non-zero-int16.test.mts +3 -2
- package/src/number/branded-types/non-zero-int32.test.mts +3 -2
- package/src/number/branded-types/non-zero-safe-int.test.mts +4 -3
- package/src/number/branded-types/non-zero-uint16.test.mts +3 -2
- package/src/number/branded-types/non-zero-uint32.test.mts +3 -2
- package/src/number/branded-types/positive-finite-number.test.mts +3 -2
- package/src/number/branded-types/positive-int.test.mts +3 -2
- package/src/number/branded-types/positive-int16.test.mts +3 -2
- package/src/number/branded-types/positive-int32.test.mts +3 -2
- package/src/number/branded-types/positive-safe-int.test.mts +3 -2
- package/src/number/branded-types/positive-uint16.test.mts +3 -2
- package/src/number/branded-types/positive-uint32.test.mts +3 -2
- package/src/number/branded-types/safe-int.test.mts +3 -2
- package/src/number/branded-types/safe-uint.test.mts +3 -2
- package/src/number/branded-types/uint.test.mts +3 -2
- package/src/number/branded-types/uint16.test.mts +3 -2
- package/src/number/branded-types/uint32.test.mts +3 -2
- package/src/object/object.test.mts +10 -10
- package/src/others/cast-readonly.test.mts +8 -8
- package/src/others/memoize-function.mts +1 -1
- package/src/others/memoize-function.test.mts +2 -2
- package/src/others/unknown-to-string.test.mts +3 -3
|
@@ -852,11 +852,9 @@ export namespace Result {
|
|
|
852
852
|
return err(error);
|
|
853
853
|
}
|
|
854
854
|
const msg = unknownToString(error);
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
return err(new Error(msg.value));
|
|
859
|
-
}
|
|
855
|
+
return isErr(msg)
|
|
856
|
+
? err(new Error(String(error)))
|
|
857
|
+
: err(new Error(msg.value));
|
|
860
858
|
}
|
|
861
859
|
};
|
|
862
860
|
|
|
@@ -85,7 +85,7 @@ describe('isNonEmptyString', () => {
|
|
|
85
85
|
|
|
86
86
|
test('should not accept String objects', () => {
|
|
87
87
|
// @ts-expect-error Testing non-string types
|
|
88
|
-
// eslint-disable-next-line no-new-wrappers
|
|
88
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
89
89
|
expect(isNonEmptyString(new String('hello') as unknown)).toBe(false);
|
|
90
90
|
});
|
|
91
91
|
});
|
|
@@ -31,11 +31,11 @@ describe('isNonNullObject', () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test('should return true for boxed primitives', () => {
|
|
34
|
-
// eslint-disable-next-line no-new-wrappers
|
|
34
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
35
35
|
expect(isNonNullObject(new String('hello'))).toBe(true);
|
|
36
|
-
// eslint-disable-next-line no-new-wrappers
|
|
36
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
37
37
|
expect(isNonNullObject(new Number(42))).toBe(true);
|
|
38
|
-
// eslint-disable-next-line no-new-wrappers
|
|
38
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
39
39
|
expect(isNonNullObject(new Boolean(true))).toBe(true);
|
|
40
40
|
});
|
|
41
41
|
|
|
@@ -66,11 +66,11 @@ describe('isPrimitive', () => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test('should return false for boxed primitives', () => {
|
|
69
|
-
// eslint-disable-next-line no-new-wrappers
|
|
69
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
70
70
|
expect(isPrimitive(new String('hello'))).toBe(false);
|
|
71
|
-
// eslint-disable-next-line no-new-wrappers
|
|
71
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
72
72
|
expect(isPrimitive(new Number(42))).toBe(false);
|
|
73
|
-
// eslint-disable-next-line no-new-wrappers
|
|
73
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
74
74
|
expect(isPrimitive(new Boolean(true))).toBe(false);
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -89,12 +89,12 @@ describe('isPrimitive', () => {
|
|
|
89
89
|
const primitives = values.filter(isPrimitive);
|
|
90
90
|
const nonPrimitives = values.filter((v) => !isPrimitive(v));
|
|
91
91
|
|
|
92
|
-
expect(primitives
|
|
92
|
+
expect(primitives).toHaveLength(6); // string, 42, true, null, undefined, symbol
|
|
93
93
|
expect(primitives[0]).toBe('string');
|
|
94
94
|
expect(primitives[1]).toBe(42);
|
|
95
95
|
expect(primitives[2]).toBe(true);
|
|
96
|
-
expect(primitives[3]).
|
|
97
|
-
expect(primitives[4]).
|
|
96
|
+
expect(primitives[3]).toBeNull();
|
|
97
|
+
expect(primitives[4]).toBeUndefined();
|
|
98
98
|
expect(typeof primitives[5]).toBe('symbol');
|
|
99
99
|
|
|
100
100
|
expect(nonPrimitives).toStrictEqual([{}, []]);
|
|
@@ -112,7 +112,7 @@ describe('isString', () => {
|
|
|
112
112
|
expect(isString(true)).toBe(false);
|
|
113
113
|
expect(isString(null)).toBe(false);
|
|
114
114
|
expect(isString(undefined)).toBe(false);
|
|
115
|
-
// eslint-disable-next-line no-new-wrappers
|
|
115
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
116
116
|
expect(isString(new String('hello'))).toBe(false);
|
|
117
117
|
});
|
|
118
118
|
|
|
@@ -120,7 +120,7 @@ describe('isString', () => {
|
|
|
120
120
|
const value: unknown = 'test';
|
|
121
121
|
if (isString(value)) {
|
|
122
122
|
expectType<typeof value, string>('=');
|
|
123
|
-
expect(value
|
|
123
|
+
expect(value).toHaveLength(4);
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
});
|
|
@@ -140,7 +140,7 @@ describe('isNumber', () => {
|
|
|
140
140
|
expect(isNumber(true)).toBe(false);
|
|
141
141
|
expect(isNumber(null)).toBe(false);
|
|
142
142
|
expect(isNumber(BigInt(123))).toBe(false);
|
|
143
|
-
// eslint-disable-next-line no-new-wrappers
|
|
143
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
144
144
|
expect(isNumber(new Number(42))).toBe(false);
|
|
145
145
|
});
|
|
146
146
|
|
|
@@ -187,7 +187,7 @@ describe('isBoolean', () => {
|
|
|
187
187
|
expect(isBoolean(0)).toBe(false);
|
|
188
188
|
expect(isBoolean('true')).toBe(false);
|
|
189
189
|
expect(isBoolean(null)).toBe(false);
|
|
190
|
-
// eslint-disable-next-line no-new-wrappers
|
|
190
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins
|
|
191
191
|
expect(isBoolean(new Boolean(true))).toBe(false);
|
|
192
192
|
});
|
|
193
193
|
|
|
@@ -424,7 +424,7 @@ describe('isNonNullish', () => {
|
|
|
424
424
|
const value: string | null | undefined = 'test';
|
|
425
425
|
if (isNonNullish(value)) {
|
|
426
426
|
expectType<typeof value, string>('<=');
|
|
427
|
-
expect(value
|
|
427
|
+
expect(value).toHaveLength(4);
|
|
428
428
|
}
|
|
429
429
|
});
|
|
430
430
|
|
|
@@ -460,13 +460,9 @@ describe('type guard behavior in complex scenarios', () => {
|
|
|
460
460
|
test('should work with nested conditions', () => {
|
|
461
461
|
const value: string | number | boolean | null | undefined = 'test';
|
|
462
462
|
|
|
463
|
-
if (isNonNullish(value)) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
expectType<typeof value, string>('<=');
|
|
467
|
-
expect(typeof value).toBe('string');
|
|
468
|
-
}
|
|
469
|
-
}
|
|
463
|
+
if (isNonNullish(value) && isNotBoolean(value) && isNotNumber(value)) {
|
|
464
|
+
expectType<typeof value, string>('<=');
|
|
465
|
+
expect(typeof value).toBe('string');
|
|
470
466
|
}
|
|
471
467
|
});
|
|
472
468
|
|
package/src/json/json.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Arr } from '../array/index.mjs';
|
|
2
2
|
import { pipe, Result } from '../functional/index.mjs';
|
|
3
3
|
import { isRecord } from '../guard/index.mjs';
|
|
4
|
-
import { castMutable } from '../others/index.mjs';
|
|
5
|
-
import { unknownToString } from '../others/unknown-to-string.mjs';
|
|
4
|
+
import { castMutable, unknownToString } from '../others/index.mjs';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* A collection of type-safe JSON utility functions that provide safe parsing,
|
package/src/json/json.test.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Arr } from '../array/index.mjs';
|
|
2
|
-
import { Result } from '../functional/
|
|
2
|
+
import { Result } from '../functional/index.mjs';
|
|
3
3
|
import { hasKey, isRecord } from '../guard/index.mjs';
|
|
4
4
|
import { Json } from './json.mjs';
|
|
5
5
|
|
|
@@ -105,15 +105,14 @@ describe('parse', () => {
|
|
|
105
105
|
const result = Json.parse(jsonString, dateReviver);
|
|
106
106
|
|
|
107
107
|
expect(Result.isOk(result)).toBe(true);
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
108
|
+
if (
|
|
109
|
+
Result.isOk(result) &&
|
|
110
|
+
isRecord(result.value) &&
|
|
111
|
+
hasKey(result.value, 'name') &&
|
|
112
|
+
hasKey(result.value, 'created')
|
|
113
|
+
) {
|
|
114
|
+
expect(result.value.name).toBe('test');
|
|
115
|
+
expect(result.value.created).toBeInstanceOf(Date);
|
|
117
116
|
}
|
|
118
117
|
});
|
|
119
118
|
|
|
@@ -193,13 +192,13 @@ describe('stringify', () => {
|
|
|
193
192
|
|
|
194
193
|
test('should handle special string values', () => {
|
|
195
194
|
expect(Json.stringify('with "quotes"')).toStrictEqual(
|
|
196
|
-
Result.ok(
|
|
195
|
+
Result.ok(String.raw`"with \"quotes\""`),
|
|
197
196
|
);
|
|
198
197
|
expect(Json.stringify('with\nnewline')).toStrictEqual(
|
|
199
|
-
Result.ok(
|
|
198
|
+
Result.ok(String.raw`"with\nnewline"`),
|
|
200
199
|
);
|
|
201
200
|
expect(Json.stringify('with\ttab')).toStrictEqual(
|
|
202
|
-
Result.ok(
|
|
201
|
+
Result.ok(String.raw`"with\ttab"`),
|
|
203
202
|
);
|
|
204
203
|
});
|
|
205
204
|
|
|
@@ -222,17 +221,15 @@ describe('stringify', () => {
|
|
|
222
221
|
|
|
223
222
|
test('should handle circular references', () => {
|
|
224
223
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
-
const
|
|
224
|
+
const mut_obj: any = { a: 1 };
|
|
226
225
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
227
|
-
|
|
228
|
-
expect(Result.isErr(Json.stringify(
|
|
226
|
+
mut_obj.circular = mut_obj;
|
|
227
|
+
expect(Result.isErr(Json.stringify(mut_obj))).toBe(true);
|
|
229
228
|
});
|
|
230
229
|
|
|
231
230
|
test('should handle objects with toJSON method', () => {
|
|
232
231
|
const obj = {
|
|
233
|
-
toJSON() {
|
|
234
|
-
return { custom: 'value' };
|
|
235
|
-
},
|
|
232
|
+
toJSON: () => ({ custom: 'value' }),
|
|
236
233
|
};
|
|
237
234
|
expect(Json.stringify(obj)).toStrictEqual(Result.ok('{"custom":"value"}'));
|
|
238
235
|
});
|
|
@@ -246,10 +243,10 @@ describe('stringify', () => {
|
|
|
246
243
|
|
|
247
244
|
test('should not throw errors', () => {
|
|
248
245
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
-
const
|
|
250
|
-
|
|
246
|
+
const mut_circularArray: any[] = [];
|
|
247
|
+
mut_circularArray.push(mut_circularArray);
|
|
251
248
|
|
|
252
|
-
expect(() => Json.stringify(
|
|
249
|
+
expect(() => Json.stringify(mut_circularArray)).not.toThrow();
|
|
253
250
|
expect(() => Json.stringify({ fn: () => {} })).not.toThrow();
|
|
254
251
|
});
|
|
255
252
|
|
|
@@ -411,10 +408,10 @@ describe('stringifySelected', () => {
|
|
|
411
408
|
|
|
412
409
|
test('should handle circular references with error', () => {
|
|
413
410
|
type CircularType = { name: string; self?: CircularType };
|
|
414
|
-
const
|
|
415
|
-
|
|
411
|
+
const mut_circular: CircularType = { name: 'test' };
|
|
412
|
+
mut_circular.self = mut_circular;
|
|
416
413
|
|
|
417
|
-
const result = Json.stringifySelected(
|
|
414
|
+
const result = Json.stringifySelected(mut_circular, ['name', 'self']);
|
|
418
415
|
|
|
419
416
|
// Note: JSON.stringify may handle circular references differently depending on the replacer
|
|
420
417
|
expect(Result.isOk(result) || Result.isErr(result)).toBe(true);
|
|
@@ -561,13 +558,13 @@ describe('stringifySortedKey', () => {
|
|
|
561
558
|
normal: string;
|
|
562
559
|
circular: { self?: CircularObj };
|
|
563
560
|
};
|
|
564
|
-
const
|
|
561
|
+
const mut_problematicObj: CircularObj = {
|
|
565
562
|
normal: 'value',
|
|
566
563
|
circular: {},
|
|
567
564
|
};
|
|
568
|
-
|
|
565
|
+
mut_problematicObj.circular.self = mut_problematicObj;
|
|
569
566
|
|
|
570
|
-
const result = Json.stringifySortedKey(
|
|
567
|
+
const result = Json.stringifySortedKey(mut_problematicObj);
|
|
571
568
|
|
|
572
569
|
// This may throw due to circular reference during key extraction
|
|
573
570
|
expect(Result.isErr(result)).toBe(true);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import { asFiniteNumber, FiniteNumber } from './finite-number.mjs';
|
|
3
4
|
import { asNonZeroFiniteNumber } from './non-zero-finite-number.mjs';
|
|
4
5
|
|
|
@@ -116,7 +117,7 @@ describe('FiniteNumber', () => {
|
|
|
116
117
|
const min = asFiniteNumber(-5.5);
|
|
117
118
|
const max = asFiniteNumber(10.3);
|
|
118
119
|
|
|
119
|
-
for (
|
|
120
|
+
for (const _ of range(10)) {
|
|
120
121
|
const result = FiniteNumber.random(min, max);
|
|
121
122
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
122
123
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import { asInt, Int, isInt } from './int.mjs';
|
|
3
4
|
import { asNonZeroInt } from './non-zero-int.mjs';
|
|
4
5
|
|
|
@@ -120,7 +121,7 @@ describe('Int', () => {
|
|
|
120
121
|
const min = -5;
|
|
121
122
|
const max = 10;
|
|
122
123
|
|
|
123
|
-
for (
|
|
124
|
+
for (const _ of range(10)) {
|
|
124
125
|
const result = Int.random(min, max);
|
|
125
126
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
126
127
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import { asInt16, Int16, isInt16 } from './int16.mjs';
|
|
3
4
|
import { asNonZeroInt16 } from './non-zero-int16.mjs';
|
|
4
5
|
|
|
@@ -142,7 +143,7 @@ describe('Int16', () => {
|
|
|
142
143
|
const min = -10;
|
|
143
144
|
const max = 10;
|
|
144
145
|
|
|
145
|
-
for (
|
|
146
|
+
for (const _ of range(10)) {
|
|
146
147
|
const result = Int16.random(min, max);
|
|
147
148
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
148
149
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -152,7 +153,7 @@ describe('Int16', () => {
|
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
test('generates values within Int16 range', () => {
|
|
155
|
-
for (
|
|
156
|
+
for (const _ of range(10)) {
|
|
156
157
|
const result = Int16.random(-20, 20);
|
|
157
158
|
expect(result).toBeGreaterThanOrEqual(Int16.MIN_VALUE);
|
|
158
159
|
expect(result).toBeLessThanOrEqual(Int16.MAX_VALUE);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import { asInt32, Int32, isInt32 } from './int32.mjs';
|
|
3
4
|
import { asNonZeroInt32 } from './non-zero-int32.mjs';
|
|
4
5
|
|
|
@@ -142,7 +143,7 @@ describe('Int32', () => {
|
|
|
142
143
|
const min = -10;
|
|
143
144
|
const max = 10;
|
|
144
145
|
|
|
145
|
-
for (
|
|
146
|
+
for (const _ of range(10)) {
|
|
146
147
|
const result = Int32.random(min, max);
|
|
147
148
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
148
149
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -152,7 +153,7 @@ describe('Int32', () => {
|
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
test('generates values within Int32 range', () => {
|
|
155
|
-
for (
|
|
156
|
+
for (const _ of range(10)) {
|
|
156
157
|
const result = Int32.random(-20, 20);
|
|
157
158
|
expect(result).toBeGreaterThanOrEqual(Int32.MIN_VALUE);
|
|
158
159
|
expect(result).toBeLessThanOrEqual(Int32.MAX_VALUE);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonNegativeFiniteNumber,
|
|
4
5
|
isNonNegativeFiniteNumber,
|
|
@@ -155,7 +156,7 @@ describe('NonNegativeFiniteNumber', () => {
|
|
|
155
156
|
const min = asNonNegativeFiniteNumber(1.5);
|
|
156
157
|
const max = asNonNegativeFiniteNumber(10.3);
|
|
157
158
|
|
|
158
|
-
for (
|
|
159
|
+
for (const _ of range(10)) {
|
|
159
160
|
const result = NonNegativeFiniteNumber.random(min, max);
|
|
160
161
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
161
162
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -168,7 +169,7 @@ describe('NonNegativeFiniteNumber', () => {
|
|
|
168
169
|
const min = asNonNegativeFiniteNumber(0);
|
|
169
170
|
const max = asNonNegativeFiniteNumber(5);
|
|
170
171
|
|
|
171
|
-
for (
|
|
172
|
+
for (const _ of range(10)) {
|
|
172
173
|
const result = NonNegativeFiniteNumber.random(min, max);
|
|
173
174
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
174
175
|
expect(result).toBeLessThanOrEqual(5);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonNegativeInt16,
|
|
4
5
|
isNonNegativeInt16,
|
|
@@ -172,7 +173,7 @@ describe('NonNegativeInt16', () => {
|
|
|
172
173
|
const min = 0;
|
|
173
174
|
const max = 20;
|
|
174
175
|
|
|
175
|
-
for (
|
|
176
|
+
for (const _ of range(10)) {
|
|
176
177
|
const result = NonNegativeInt16.random(min, max);
|
|
177
178
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
178
179
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -183,7 +184,7 @@ describe('NonNegativeInt16', () => {
|
|
|
183
184
|
});
|
|
184
185
|
|
|
185
186
|
test('generates values within NonNegativeInt16 range', () => {
|
|
186
|
-
for (
|
|
187
|
+
for (const _ of range(10)) {
|
|
187
188
|
const result = NonNegativeInt16.random(0, 30);
|
|
188
189
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
189
190
|
expect(result).toBeLessThanOrEqual(32767);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonNegativeInt32,
|
|
4
5
|
isNonNegativeInt32,
|
|
@@ -175,7 +176,7 @@ describe('NonNegativeInt32', () => {
|
|
|
175
176
|
const min = 0;
|
|
176
177
|
const max = 20;
|
|
177
178
|
|
|
178
|
-
for (
|
|
179
|
+
for (const _ of range(10)) {
|
|
179
180
|
const result = NonNegativeInt32.random(min, max);
|
|
180
181
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
181
182
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -186,7 +187,7 @@ describe('NonNegativeInt32', () => {
|
|
|
186
187
|
});
|
|
187
188
|
|
|
188
189
|
test('generates values within NonNegativeInt32 range', () => {
|
|
189
|
-
for (
|
|
190
|
+
for (const _ of range(10)) {
|
|
190
191
|
const result = NonNegativeInt32.random(0, 30);
|
|
191
192
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
192
193
|
expect(result).toBeLessThanOrEqual(2147483647);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonZeroFiniteNumber,
|
|
4
5
|
isNonZeroFiniteNumber,
|
|
@@ -152,7 +153,7 @@ describe('NonZeroFiniteNumber', () => {
|
|
|
152
153
|
const min = asNonZeroFiniteNumber(1.5);
|
|
153
154
|
const max = asNonZeroFiniteNumber(10.3);
|
|
154
155
|
|
|
155
|
-
for (
|
|
156
|
+
for (const _ of range(10)) {
|
|
156
157
|
const result = NonZeroFiniteNumber.random(min, max);
|
|
157
158
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
158
159
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -165,7 +166,7 @@ describe('NonZeroFiniteNumber', () => {
|
|
|
165
166
|
const min = asNonZeroFiniteNumber(-10.3);
|
|
166
167
|
const max = asNonZeroFiniteNumber(-1.5);
|
|
167
168
|
|
|
168
|
-
for (
|
|
169
|
+
for (const _ of range(10)) {
|
|
169
170
|
const result = NonZeroFiniteNumber.random(min, max);
|
|
170
171
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
171
172
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -178,7 +179,7 @@ describe('NonZeroFiniteNumber', () => {
|
|
|
178
179
|
const min = asNonZeroFiniteNumber(-5.5);
|
|
179
180
|
const max = asNonZeroFiniteNumber(5.5);
|
|
180
181
|
|
|
181
|
-
for (
|
|
182
|
+
for (const _ of range(10)) {
|
|
182
183
|
const result = NonZeroFiniteNumber.random(min, max);
|
|
183
184
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
184
185
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import { asNonZeroInt, isNonZeroInt, NonZeroInt } from './non-zero-int.mjs';
|
|
3
4
|
|
|
4
5
|
describe('NonZeroInt', () => {
|
|
@@ -128,7 +129,7 @@ describe('NonZeroInt', () => {
|
|
|
128
129
|
const min = 1;
|
|
129
130
|
const max = 10;
|
|
130
131
|
|
|
131
|
-
for (
|
|
132
|
+
for (const _ of range(10)) {
|
|
132
133
|
const result = NonZeroInt.random(min, max);
|
|
133
134
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
134
135
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -142,7 +143,7 @@ describe('NonZeroInt', () => {
|
|
|
142
143
|
const min = -10;
|
|
143
144
|
const max = -1;
|
|
144
145
|
|
|
145
|
-
for (
|
|
146
|
+
for (const _ of range(10)) {
|
|
146
147
|
const result = NonZeroInt.random(min, max);
|
|
147
148
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
148
149
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -156,7 +157,7 @@ describe('NonZeroInt', () => {
|
|
|
156
157
|
const min = -5;
|
|
157
158
|
const max = 5;
|
|
158
159
|
|
|
159
|
-
for (
|
|
160
|
+
for (const _ of range(10)) {
|
|
160
161
|
const result = NonZeroInt.random(min, max);
|
|
161
162
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
162
163
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonZeroInt16,
|
|
4
5
|
isNonZeroInt16,
|
|
@@ -166,7 +167,7 @@ describe('NonZeroInt16', () => {
|
|
|
166
167
|
const min = -10;
|
|
167
168
|
const max = 10;
|
|
168
169
|
|
|
169
|
-
for (
|
|
170
|
+
for (const _ of range(10)) {
|
|
170
171
|
const result = NonZeroInt16.random(min, max);
|
|
171
172
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
172
173
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -177,7 +178,7 @@ describe('NonZeroInt16', () => {
|
|
|
177
178
|
});
|
|
178
179
|
|
|
179
180
|
test('generates values within NonZeroInt16 range', () => {
|
|
180
|
-
for (
|
|
181
|
+
for (const _ of range(10)) {
|
|
181
182
|
const result = NonZeroInt16.random(-20, 20);
|
|
182
183
|
expect(result).toBeGreaterThanOrEqual(-32768);
|
|
183
184
|
expect(result).toBeLessThanOrEqual(32767);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonZeroInt32,
|
|
4
5
|
isNonZeroInt32,
|
|
@@ -168,7 +169,7 @@ describe('NonZeroInt32', () => {
|
|
|
168
169
|
const min = -10;
|
|
169
170
|
const max = 10;
|
|
170
171
|
|
|
171
|
-
for (
|
|
172
|
+
for (const _ of range(10)) {
|
|
172
173
|
const result = NonZeroInt32.random(min, max);
|
|
173
174
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
174
175
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -179,7 +180,7 @@ describe('NonZeroInt32', () => {
|
|
|
179
180
|
});
|
|
180
181
|
|
|
181
182
|
test('generates values within NonZeroInt32 range', () => {
|
|
182
|
-
for (
|
|
183
|
+
for (const _ of range(10)) {
|
|
183
184
|
const result = NonZeroInt32.random(-20, 20);
|
|
184
185
|
expect(result).toBeGreaterThanOrEqual(-2147483648);
|
|
185
186
|
expect(result).toBeLessThanOrEqual(2147483647);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonZeroSafeInt,
|
|
4
5
|
isNonZeroSafeInt,
|
|
@@ -183,7 +184,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
183
184
|
const min = 1;
|
|
184
185
|
const max = 20;
|
|
185
186
|
|
|
186
|
-
for (
|
|
187
|
+
for (const _ of range(10)) {
|
|
187
188
|
const result = NonZeroSafeInt.random(min, max);
|
|
188
189
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
189
190
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -197,7 +198,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
197
198
|
const min = -20;
|
|
198
199
|
const max = -1;
|
|
199
200
|
|
|
200
|
-
for (
|
|
201
|
+
for (const _ of range(10)) {
|
|
201
202
|
const result = NonZeroSafeInt.random(min, max);
|
|
202
203
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
203
204
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -211,7 +212,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
211
212
|
const min = -5;
|
|
212
213
|
const max = 5;
|
|
213
214
|
|
|
214
|
-
for (
|
|
215
|
+
for (const _ of range(10)) {
|
|
215
216
|
const result = NonZeroSafeInt.random(min, max);
|
|
216
217
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
217
218
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonZeroUint16,
|
|
4
5
|
isNonZeroUint16,
|
|
@@ -170,7 +171,7 @@ describe('NonZeroUint16', () => {
|
|
|
170
171
|
const min = 1;
|
|
171
172
|
const max = 20;
|
|
172
173
|
|
|
173
|
-
for (
|
|
174
|
+
for (const _ of range(10)) {
|
|
174
175
|
const result = NonZeroUint16.random(min, max);
|
|
175
176
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
176
177
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -181,7 +182,7 @@ describe('NonZeroUint16', () => {
|
|
|
181
182
|
});
|
|
182
183
|
|
|
183
184
|
test('generates values within NonZeroUint16 range', () => {
|
|
184
|
-
for (
|
|
185
|
+
for (const _ of range(10)) {
|
|
185
186
|
const result = NonZeroUint16.random(1, 30);
|
|
186
187
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
187
188
|
expect(result).toBeLessThanOrEqual(65535);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asNonZeroUint32,
|
|
4
5
|
isNonZeroUint32,
|
|
@@ -170,7 +171,7 @@ describe('NonZeroUint32', () => {
|
|
|
170
171
|
const min = 1;
|
|
171
172
|
const max = 20;
|
|
172
173
|
|
|
173
|
-
for (
|
|
174
|
+
for (const _ of range(10)) {
|
|
174
175
|
const result = NonZeroUint32.random(min, max);
|
|
175
176
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
176
177
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -181,7 +182,7 @@ describe('NonZeroUint32', () => {
|
|
|
181
182
|
});
|
|
182
183
|
|
|
183
184
|
test('generates values within NonZeroUint32 range', () => {
|
|
184
|
-
for (
|
|
185
|
+
for (const _ of range(10)) {
|
|
185
186
|
const result = NonZeroUint32.random(1, 30);
|
|
186
187
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
187
188
|
expect(result).toBeLessThanOrEqual(4294967295);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expectType } from '../../expect-type.mjs';
|
|
2
|
+
import { range } from '../../iterator/index.mjs';
|
|
2
3
|
import {
|
|
3
4
|
asPositiveFiniteNumber,
|
|
4
5
|
isPositiveFiniteNumber,
|
|
@@ -170,7 +171,7 @@ describe('PositiveFiniteNumber', () => {
|
|
|
170
171
|
const min = asPositiveFiniteNumber(1.5);
|
|
171
172
|
const max = asPositiveFiniteNumber(10.3);
|
|
172
173
|
|
|
173
|
-
for (
|
|
174
|
+
for (const _ of range(10)) {
|
|
174
175
|
const result = PositiveFiniteNumber.random(min, max);
|
|
175
176
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
176
177
|
expect(result).toBeLessThanOrEqual(max);
|
|
@@ -183,7 +184,7 @@ describe('PositiveFiniteNumber', () => {
|
|
|
183
184
|
const min = asPositiveFiniteNumber(Number.MIN_VALUE);
|
|
184
185
|
const max = asPositiveFiniteNumber(1);
|
|
185
186
|
|
|
186
|
-
for (
|
|
187
|
+
for (const _ of range(10)) {
|
|
187
188
|
const result = PositiveFiniteNumber.random(min, max);
|
|
188
189
|
expect(result).toBeGreaterThanOrEqual(Number.MIN_VALUE);
|
|
189
190
|
expect(result).toBeLessThanOrEqual(1);
|