ts-data-forge 4.0.0 → 5.0.0
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/entry-point.mjs +2 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functional/index.d.mts +1 -0
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +2 -0
- package/dist/functional/index.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/index.d.mts +29 -0
- package/dist/functional/ternary-result/impl/index.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/index.mjs +28 -0
- package/dist/functional/ternary-result/impl/index.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/tag.d.mts +7 -0
- package/dist/functional/ternary-result/impl/tag.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/tag.mjs +9 -0
- package/dist/functional/ternary-result/impl/tag.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +14 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +41 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +27 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +20 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +33 -0
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +20 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +28 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +24 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +21 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +29 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +35 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +16 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +23 -0
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +19 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +16 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +25 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +13 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +36 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +19 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +32 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +17 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +22 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +18 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +26 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +48 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/types.d.mts +25 -0
- package/dist/functional/ternary-result/impl/types.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/types.mjs +2 -0
- package/dist/functional/ternary-result/impl/types.mjs.map +1 -0
- package/dist/functional/ternary-result/impl/variant-name.d.mts +3 -0
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +1 -0
- package/dist/functional/ternary-result/impl/variant-name.mjs +16 -0
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -0
- package/dist/functional/ternary-result/index.d.mts +2 -0
- package/dist/functional/ternary-result/index.d.mts.map +1 -0
- package/dist/functional/ternary-result/index.mjs +3 -0
- package/dist/functional/ternary-result/index.mjs.map +1 -0
- package/dist/globals.d.mts +55 -2
- package/dist/json/json.d.mts +9 -3
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +6 -0
- package/dist/json/json.mjs.map +1 -1
- package/package.json +13 -13
- 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.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/index.mts +1 -0
- 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.test.mts +127 -4
- package/src/functional/ternary-result/impl/index.mts +28 -0
- package/src/functional/ternary-result/impl/tag.mts +11 -0
- package/src/functional/ternary-result/impl/ternary-result-err.mts +18 -0
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +53 -0
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +95 -0
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +93 -0
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +27 -0
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +31 -0
- package/src/functional/ternary-result/impl/ternary-result-is-err.mts +23 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +24 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +27 -0
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +24 -0
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +64 -0
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +66 -0
- package/src/functional/ternary-result/impl/ternary-result-map.mts +81 -0
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +20 -0
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +66 -0
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +25 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +40 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +22 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +32 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +45 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +42 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +38 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +22 -0
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +23 -0
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +53 -0
- package/src/functional/ternary-result/impl/types.mts +39 -0
- package/src/functional/ternary-result/impl/variant-name.mts +17 -0
- package/src/functional/ternary-result/index.mts +1 -0
- package/src/functional/ternary-result.test.mts +214 -0
- package/src/globals.d.mts +55 -2
- 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.test.mts +15 -2
- package/src/promise/promise.test.mts +6 -1
|
@@ -3,8 +3,8 @@ import { range } from '../../iterator/index.mjs';
|
|
|
3
3
|
import { asInt16, Int16, isInt16 } from './int16.mjs';
|
|
4
4
|
import { asNonZeroInt16 } from './non-zero-int16.mjs';
|
|
5
5
|
|
|
6
|
-
describe('Int16', () => {
|
|
7
|
-
describe(
|
|
6
|
+
describe('Int16 test', () => {
|
|
7
|
+
describe(asInt16, () => {
|
|
8
8
|
test('accepts valid int16 values', () => {
|
|
9
9
|
expect(() => asInt16(0)).not.toThrow();
|
|
10
10
|
expect(() => asInt16(1)).not.toThrow();
|
|
@@ -49,7 +49,7 @@ describe('Int16', () => {
|
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
describe(
|
|
52
|
+
describe(isInt16, () => {
|
|
53
53
|
test('correctly identifies int16 values', () => {
|
|
54
54
|
expect(isInt16(0)).toBe(true);
|
|
55
55
|
expect(isInt16(1)).toBe(true);
|
|
@@ -109,18 +109,21 @@ describe('Int16', () => {
|
|
|
109
109
|
|
|
110
110
|
test('add (with clamping)', () => {
|
|
111
111
|
const result = Int16.add(asInt16(32_000), asInt16(1000));
|
|
112
|
+
|
|
112
113
|
expect(result).toBe(32_767); // clamped to max
|
|
113
114
|
expect(Int16.add(a, b)).toBe(150);
|
|
114
115
|
});
|
|
115
116
|
|
|
116
117
|
test('sub (with clamping)', () => {
|
|
117
118
|
const result = Int16.sub(asInt16(-32_000), asInt16(1000));
|
|
119
|
+
|
|
118
120
|
expect(result).toBe(-32_768); // clamped to min
|
|
119
121
|
expect(Int16.sub(a, b)).toBe(50);
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
test('mul (with clamping)', () => {
|
|
123
125
|
const result = Int16.mul(asInt16(1000), asInt16(100));
|
|
126
|
+
|
|
124
127
|
expect(result).toBe(32_767); // clamped to max
|
|
125
128
|
expect(Int16.mul(asInt16(10), asInt16(5))).toBe(50);
|
|
126
129
|
});
|
|
@@ -133,6 +136,7 @@ describe('Int16', () => {
|
|
|
133
136
|
|
|
134
137
|
test('pow (with clamping)', () => {
|
|
135
138
|
const result = Int16.pow(asInt16(200), asInt16(3));
|
|
139
|
+
|
|
136
140
|
expect(result).toBe(32_767); // clamped to max
|
|
137
141
|
expect(Int16.pow(asInt16(2), asInt16(3))).toBe(8);
|
|
138
142
|
});
|
|
@@ -145,6 +149,7 @@ describe('Int16', () => {
|
|
|
145
149
|
|
|
146
150
|
for (const _ of range(10)) {
|
|
147
151
|
const result = Int16.random(min, max);
|
|
152
|
+
|
|
148
153
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
149
154
|
expect(result).toBeLessThanOrEqual(max);
|
|
150
155
|
expect(Int16.is(result)).toBe(true);
|
|
@@ -155,6 +160,7 @@ describe('Int16', () => {
|
|
|
155
160
|
test('generates values within Int16 range', () => {
|
|
156
161
|
for (const _ of range(10)) {
|
|
157
162
|
const result = Int16.random(-20, 20);
|
|
163
|
+
|
|
158
164
|
expect(result).toBeGreaterThanOrEqual(Int16.MIN_VALUE);
|
|
159
165
|
expect(result).toBeLessThanOrEqual(Int16.MAX_VALUE);
|
|
160
166
|
}
|
|
@@ -3,8 +3,8 @@ import { range } from '../../iterator/index.mjs';
|
|
|
3
3
|
import { asInt32, Int32, isInt32 } from './int32.mjs';
|
|
4
4
|
import { asNonZeroInt32 } from './non-zero-int32.mjs';
|
|
5
5
|
|
|
6
|
-
describe('Int32', () => {
|
|
7
|
-
describe(
|
|
6
|
+
describe('Int32 test', () => {
|
|
7
|
+
describe(asInt32, () => {
|
|
8
8
|
test('accepts valid int32 values', () => {
|
|
9
9
|
expect(() => asInt32(0)).not.toThrow();
|
|
10
10
|
expect(() => asInt32(1)).not.toThrow();
|
|
@@ -49,7 +49,7 @@ describe('Int32', () => {
|
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
describe(
|
|
52
|
+
describe(isInt32, () => {
|
|
53
53
|
test('correctly identifies int32 values', () => {
|
|
54
54
|
expect(isInt32(0)).toBe(true);
|
|
55
55
|
expect(isInt32(1)).toBe(true);
|
|
@@ -109,18 +109,21 @@ describe('Int32', () => {
|
|
|
109
109
|
|
|
110
110
|
test('add (with clamping)', () => {
|
|
111
111
|
const result = Int32.add(asInt32(2_147_483_000), asInt32(1000));
|
|
112
|
+
|
|
112
113
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
113
114
|
expect(Int32.add(a, b)).toBe(1_500_000);
|
|
114
115
|
});
|
|
115
116
|
|
|
116
117
|
test('sub (with clamping)', () => {
|
|
117
118
|
const result = Int32.sub(asInt32(-2_147_483_000), asInt32(1000));
|
|
119
|
+
|
|
118
120
|
expect(result).toBe(-2_147_483_648); // clamped to min
|
|
119
121
|
expect(Int32.sub(a, b)).toBe(500_000);
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
test('mul (with clamping)', () => {
|
|
123
125
|
const result = Int32.mul(asInt32(100_000), asInt32(100_000));
|
|
126
|
+
|
|
124
127
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
125
128
|
expect(Int32.mul(asInt32(1000), asInt32(5))).toBe(5000);
|
|
126
129
|
});
|
|
@@ -133,6 +136,7 @@ describe('Int32', () => {
|
|
|
133
136
|
|
|
134
137
|
test('pow (with clamping)', () => {
|
|
135
138
|
const result = Int32.pow(asInt32(10_000), asInt32(3));
|
|
139
|
+
|
|
136
140
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
137
141
|
expect(Int32.pow(asInt32(2), asInt32(3))).toBe(8);
|
|
138
142
|
});
|
|
@@ -145,6 +149,7 @@ describe('Int32', () => {
|
|
|
145
149
|
|
|
146
150
|
for (const _ of range(10)) {
|
|
147
151
|
const result = Int32.random(min, max);
|
|
152
|
+
|
|
148
153
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
149
154
|
expect(result).toBeLessThanOrEqual(max);
|
|
150
155
|
expect(Int32.is(result)).toBe(true);
|
|
@@ -155,6 +160,7 @@ describe('Int32', () => {
|
|
|
155
160
|
test('generates values within Int32 range', () => {
|
|
156
161
|
for (const _ of range(10)) {
|
|
157
162
|
const result = Int32.random(-20, 20);
|
|
163
|
+
|
|
158
164
|
expect(result).toBeGreaterThanOrEqual(Int32.MIN_VALUE);
|
|
159
165
|
expect(result).toBeLessThanOrEqual(Int32.MAX_VALUE);
|
|
160
166
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
NonNegativeFiniteNumber,
|
|
7
7
|
} from './non-negative-finite-number.mjs';
|
|
8
8
|
|
|
9
|
-
describe('NonNegativeFiniteNumber', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('NonNegativeFiniteNumber test', () => {
|
|
10
|
+
describe(asNonNegativeFiniteNumber, () => {
|
|
11
11
|
test('accepts valid non-negative finite numbers', () => {
|
|
12
12
|
expect(() => asNonNegativeFiniteNumber(0)).not.toThrow();
|
|
13
13
|
expect(() => asNonNegativeFiniteNumber(1)).not.toThrow();
|
|
@@ -55,7 +55,7 @@ describe('NonNegativeFiniteNumber', () => {
|
|
|
55
55
|
);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
describe(
|
|
58
|
+
describe(isNonNegativeFiniteNumber, () => {
|
|
59
59
|
test('correctly identifies non-negative finite numbers', () => {
|
|
60
60
|
expect(isNonNegativeFiniteNumber(0)).toBe(true);
|
|
61
61
|
expect(isNonNegativeFiniteNumber(1)).toBe(true);
|
|
@@ -131,7 +131,7 @@ describe('NonNegativeFiniteNumber', () => {
|
|
|
131
131
|
|
|
132
132
|
test('div method exists', () => {
|
|
133
133
|
// Test that the div function exists and is of the right type
|
|
134
|
-
|
|
134
|
+
expectTypeOf(NonNegativeFiniteNumber.div).toBeFunction();
|
|
135
135
|
// Note: Cannot test division without type assertions due to strict type requirements
|
|
136
136
|
});
|
|
137
137
|
|
|
@@ -158,6 +158,7 @@ describe('NonNegativeFiniteNumber', () => {
|
|
|
158
158
|
|
|
159
159
|
for (const _ of range(10)) {
|
|
160
160
|
const result = NonNegativeFiniteNumber.random(min, max);
|
|
161
|
+
|
|
161
162
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
162
163
|
expect(result).toBeLessThanOrEqual(max);
|
|
163
164
|
expect(NonNegativeFiniteNumber.is(result)).toBe(true);
|
|
@@ -171,6 +172,7 @@ describe('NonNegativeFiniteNumber', () => {
|
|
|
171
172
|
|
|
172
173
|
for (const _ of range(10)) {
|
|
173
174
|
const result = NonNegativeFiniteNumber.random(min, max);
|
|
175
|
+
|
|
174
176
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
175
177
|
expect(result).toBeLessThanOrEqual(5);
|
|
176
178
|
}
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
} from './non-negative-int16.mjs';
|
|
8
8
|
import { asPositiveInt16 } from './positive-int16.mjs';
|
|
9
9
|
|
|
10
|
-
describe('NonNegativeInt16', () => {
|
|
11
|
-
describe(
|
|
10
|
+
describe('NonNegativeInt16 test', () => {
|
|
11
|
+
describe(asNonNegativeInt16, () => {
|
|
12
12
|
test('accepts valid non-negative int16 values', () => {
|
|
13
13
|
expect(() => asNonNegativeInt16(0)).not.toThrow();
|
|
14
14
|
expect(() => asNonNegativeInt16(1)).not.toThrow();
|
|
@@ -65,7 +65,7 @@ describe('NonNegativeInt16', () => {
|
|
|
65
65
|
);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
describe(
|
|
68
|
+
describe(isNonNegativeInt16, () => {
|
|
69
69
|
test('correctly identifies non-negative int16 values', () => {
|
|
70
70
|
expect(isNonNegativeInt16(0)).toBe(true);
|
|
71
71
|
expect(isNonNegativeInt16(1)).toBe(true);
|
|
@@ -125,6 +125,7 @@ describe('NonNegativeInt16', () => {
|
|
|
125
125
|
asNonNegativeInt16(32_000),
|
|
126
126
|
asNonNegativeInt16(1000),
|
|
127
127
|
);
|
|
128
|
+
|
|
128
129
|
expect(result).toBe(32_767); // clamped to max
|
|
129
130
|
expect(NonNegativeInt16.add(a, b)).toBe(150);
|
|
130
131
|
});
|
|
@@ -140,6 +141,7 @@ describe('NonNegativeInt16', () => {
|
|
|
140
141
|
asNonNegativeInt16(1000),
|
|
141
142
|
asNonNegativeInt16(100),
|
|
142
143
|
);
|
|
144
|
+
|
|
143
145
|
expect(result).toBe(32_767); // clamped to max
|
|
144
146
|
expect(
|
|
145
147
|
NonNegativeInt16.mul(asNonNegativeInt16(10), asNonNegativeInt16(5)),
|
|
@@ -161,6 +163,7 @@ describe('NonNegativeInt16', () => {
|
|
|
161
163
|
asNonNegativeInt16(200),
|
|
162
164
|
asNonNegativeInt16(3),
|
|
163
165
|
);
|
|
166
|
+
|
|
164
167
|
expect(result).toBe(32_767); // clamped to max
|
|
165
168
|
expect(
|
|
166
169
|
NonNegativeInt16.pow(asNonNegativeInt16(2), asNonNegativeInt16(3)),
|
|
@@ -175,6 +178,7 @@ describe('NonNegativeInt16', () => {
|
|
|
175
178
|
|
|
176
179
|
for (const _ of range(10)) {
|
|
177
180
|
const result = NonNegativeInt16.random(min, max);
|
|
181
|
+
|
|
178
182
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
179
183
|
expect(result).toBeLessThanOrEqual(max);
|
|
180
184
|
expect(NonNegativeInt16.is(result)).toBe(true);
|
|
@@ -186,6 +190,7 @@ describe('NonNegativeInt16', () => {
|
|
|
186
190
|
test('generates values within NonNegativeInt16 range', () => {
|
|
187
191
|
for (const _ of range(10)) {
|
|
188
192
|
const result = NonNegativeInt16.random(0, 30);
|
|
193
|
+
|
|
189
194
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
190
195
|
expect(result).toBeLessThanOrEqual(32_767);
|
|
191
196
|
}
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
} from './non-negative-int32.mjs';
|
|
8
8
|
import { asPositiveInt32 } from './positive-int32.mjs';
|
|
9
9
|
|
|
10
|
-
describe('NonNegativeInt32', () => {
|
|
11
|
-
describe(
|
|
10
|
+
describe('NonNegativeInt32 test', () => {
|
|
11
|
+
describe(asNonNegativeInt32, () => {
|
|
12
12
|
test('accepts valid non-negative int32 values', () => {
|
|
13
13
|
expect(() => asNonNegativeInt32(0)).not.toThrow();
|
|
14
14
|
expect(() => asNonNegativeInt32(1)).not.toThrow();
|
|
@@ -65,7 +65,7 @@ describe('NonNegativeInt32', () => {
|
|
|
65
65
|
);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
describe(
|
|
68
|
+
describe(isNonNegativeInt32, () => {
|
|
69
69
|
test('correctly identifies non-negative int32 values', () => {
|
|
70
70
|
expect(isNonNegativeInt32(0)).toBe(true);
|
|
71
71
|
expect(isNonNegativeInt32(1)).toBe(true);
|
|
@@ -125,6 +125,7 @@ describe('NonNegativeInt32', () => {
|
|
|
125
125
|
asNonNegativeInt32(2_147_483_000),
|
|
126
126
|
asNonNegativeInt32(1000),
|
|
127
127
|
);
|
|
128
|
+
|
|
128
129
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
129
130
|
expect(NonNegativeInt32.add(a, b)).toBe(1_500_000);
|
|
130
131
|
});
|
|
@@ -140,6 +141,7 @@ describe('NonNegativeInt32', () => {
|
|
|
140
141
|
asNonNegativeInt32(100_000),
|
|
141
142
|
asNonNegativeInt32(100_000),
|
|
142
143
|
);
|
|
144
|
+
|
|
143
145
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
144
146
|
expect(
|
|
145
147
|
NonNegativeInt32.mul(asNonNegativeInt32(1000), asNonNegativeInt32(5)),
|
|
@@ -164,6 +166,7 @@ describe('NonNegativeInt32', () => {
|
|
|
164
166
|
asNonNegativeInt32(10_000),
|
|
165
167
|
asNonNegativeInt32(3),
|
|
166
168
|
);
|
|
169
|
+
|
|
167
170
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
168
171
|
expect(
|
|
169
172
|
NonNegativeInt32.pow(asNonNegativeInt32(2), asNonNegativeInt32(3)),
|
|
@@ -178,6 +181,7 @@ describe('NonNegativeInt32', () => {
|
|
|
178
181
|
|
|
179
182
|
for (const _ of range(10)) {
|
|
180
183
|
const result = NonNegativeInt32.random(min, max);
|
|
184
|
+
|
|
181
185
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
182
186
|
expect(result).toBeLessThanOrEqual(max);
|
|
183
187
|
expect(NonNegativeInt32.is(result)).toBe(true);
|
|
@@ -189,6 +193,7 @@ describe('NonNegativeInt32', () => {
|
|
|
189
193
|
test('generates values within NonNegativeInt32 range', () => {
|
|
190
194
|
for (const _ of range(10)) {
|
|
191
195
|
const result = NonNegativeInt32.random(0, 30);
|
|
196
|
+
|
|
192
197
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
193
198
|
expect(result).toBeLessThanOrEqual(2_147_483_647);
|
|
194
199
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
NonZeroFiniteNumber,
|
|
7
7
|
} from './non-zero-finite-number.mjs';
|
|
8
8
|
|
|
9
|
-
describe('NonZeroFiniteNumber', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('NonZeroFiniteNumber test', () => {
|
|
10
|
+
describe(asNonZeroFiniteNumber, () => {
|
|
11
11
|
test('accepts valid non-zero finite numbers', () => {
|
|
12
12
|
expect(() => asNonZeroFiniteNumber(1)).not.toThrow();
|
|
13
13
|
expect(() => asNonZeroFiniteNumber(-1)).not.toThrow();
|
|
@@ -55,7 +55,7 @@ describe('NonZeroFiniteNumber', () => {
|
|
|
55
55
|
);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
describe(
|
|
58
|
+
describe(isNonZeroFiniteNumber, () => {
|
|
59
59
|
test('correctly identifies non-zero finite numbers', () => {
|
|
60
60
|
expect(isNonZeroFiniteNumber(1)).toBe(true);
|
|
61
61
|
expect(isNonZeroFiniteNumber(-1)).toBe(true);
|
|
@@ -155,6 +155,7 @@ describe('NonZeroFiniteNumber', () => {
|
|
|
155
155
|
|
|
156
156
|
for (const _ of range(10)) {
|
|
157
157
|
const result = NonZeroFiniteNumber.random(min, max);
|
|
158
|
+
|
|
158
159
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
159
160
|
expect(result).toBeLessThanOrEqual(max);
|
|
160
161
|
expect(NonZeroFiniteNumber.is(result)).toBe(true);
|
|
@@ -168,6 +169,7 @@ describe('NonZeroFiniteNumber', () => {
|
|
|
168
169
|
|
|
169
170
|
for (const _ of range(10)) {
|
|
170
171
|
const result = NonZeroFiniteNumber.random(min, max);
|
|
172
|
+
|
|
171
173
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
172
174
|
expect(result).toBeLessThanOrEqual(max);
|
|
173
175
|
expect(NonZeroFiniteNumber.is(result)).toBe(true);
|
|
@@ -181,6 +183,7 @@ describe('NonZeroFiniteNumber', () => {
|
|
|
181
183
|
|
|
182
184
|
for (const _ of range(10)) {
|
|
183
185
|
const result = NonZeroFiniteNumber.random(min, max);
|
|
186
|
+
|
|
184
187
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
185
188
|
expect(result).toBeLessThanOrEqual(max);
|
|
186
189
|
expect(NonZeroFiniteNumber.is(result)).toBe(true);
|
|
@@ -2,8 +2,8 @@ import { expectType } from '../../expect-type.mjs';
|
|
|
2
2
|
import { range } from '../../iterator/index.mjs';
|
|
3
3
|
import { asNonZeroInt, isNonZeroInt, NonZeroInt } from './non-zero-int.mjs';
|
|
4
4
|
|
|
5
|
-
describe('NonZeroInt', () => {
|
|
6
|
-
describe(
|
|
5
|
+
describe('NonZeroInt test', () => {
|
|
6
|
+
describe(asNonZeroInt, () => {
|
|
7
7
|
test('accepts valid non-zero integers', () => {
|
|
8
8
|
expect(() => asNonZeroInt(1)).not.toThrow();
|
|
9
9
|
expect(() => asNonZeroInt(-1)).not.toThrow();
|
|
@@ -46,7 +46,7 @@ describe('NonZeroInt', () => {
|
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
describe(
|
|
49
|
+
describe(isNonZeroInt, () => {
|
|
50
50
|
test('correctly identifies non-zero integers', () => {
|
|
51
51
|
expect(isNonZeroInt(1)).toBe(true);
|
|
52
52
|
expect(isNonZeroInt(-1)).toBe(true);
|
|
@@ -131,6 +131,7 @@ describe('NonZeroInt', () => {
|
|
|
131
131
|
|
|
132
132
|
for (const _ of range(10)) {
|
|
133
133
|
const result = NonZeroInt.random(min, max);
|
|
134
|
+
|
|
134
135
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
135
136
|
expect(result).toBeLessThanOrEqual(max);
|
|
136
137
|
expect(NonZeroInt.is(result)).toBe(true);
|
|
@@ -145,6 +146,7 @@ describe('NonZeroInt', () => {
|
|
|
145
146
|
|
|
146
147
|
for (const _ of range(10)) {
|
|
147
148
|
const result = NonZeroInt.random(min, max);
|
|
149
|
+
|
|
148
150
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
149
151
|
expect(result).toBeLessThanOrEqual(max);
|
|
150
152
|
expect(NonZeroInt.is(result)).toBe(true);
|
|
@@ -159,6 +161,7 @@ describe('NonZeroInt', () => {
|
|
|
159
161
|
|
|
160
162
|
for (const _ of range(10)) {
|
|
161
163
|
const result = NonZeroInt.random(min, max);
|
|
164
|
+
|
|
162
165
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
163
166
|
expect(result).toBeLessThanOrEqual(max);
|
|
164
167
|
expect(NonZeroInt.is(result)).toBe(true);
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
NonZeroInt16,
|
|
7
7
|
} from './non-zero-int16.mjs';
|
|
8
8
|
|
|
9
|
-
describe('NonZeroInt16', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('NonZeroInt16 test', () => {
|
|
10
|
+
describe(asNonZeroInt16, () => {
|
|
11
11
|
test('accepts valid non-zero int16 values', () => {
|
|
12
12
|
expect(() => asNonZeroInt16(1)).not.toThrow();
|
|
13
13
|
expect(() => asNonZeroInt16(-1)).not.toThrow();
|
|
@@ -62,7 +62,7 @@ describe('NonZeroInt16', () => {
|
|
|
62
62
|
);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
describe(
|
|
65
|
+
describe(isNonZeroInt16, () => {
|
|
66
66
|
test('correctly identifies non-zero int16 values', () => {
|
|
67
67
|
expect(isNonZeroInt16(1)).toBe(true);
|
|
68
68
|
expect(isNonZeroInt16(-1)).toBe(true);
|
|
@@ -127,6 +127,7 @@ describe('NonZeroInt16', () => {
|
|
|
127
127
|
asNonZeroInt16(32_000),
|
|
128
128
|
asNonZeroInt16(1000),
|
|
129
129
|
);
|
|
130
|
+
|
|
130
131
|
expect(result).toBe(32_767); // clamped to max
|
|
131
132
|
expect(NonZeroInt16.add(a, b)).toBe(150);
|
|
132
133
|
});
|
|
@@ -136,6 +137,7 @@ describe('NonZeroInt16', () => {
|
|
|
136
137
|
asNonZeroInt16(-32_000),
|
|
137
138
|
asNonZeroInt16(1000),
|
|
138
139
|
);
|
|
140
|
+
|
|
139
141
|
expect(result).toBe(-32_768); // clamped to min
|
|
140
142
|
expect(NonZeroInt16.sub(a, b)).toBe(50);
|
|
141
143
|
});
|
|
@@ -145,6 +147,7 @@ describe('NonZeroInt16', () => {
|
|
|
145
147
|
asNonZeroInt16(1000),
|
|
146
148
|
asNonZeroInt16(100),
|
|
147
149
|
);
|
|
150
|
+
|
|
148
151
|
expect(result).toBe(32_767); // clamped to max
|
|
149
152
|
expect(NonZeroInt16.mul(asNonZeroInt16(10), asNonZeroInt16(5))).toBe(50);
|
|
150
153
|
});
|
|
@@ -157,6 +160,7 @@ describe('NonZeroInt16', () => {
|
|
|
157
160
|
|
|
158
161
|
test('pow (with clamping)', () => {
|
|
159
162
|
const result = NonZeroInt16.pow(asNonZeroInt16(200), asNonZeroInt16(3));
|
|
163
|
+
|
|
160
164
|
expect(result).toBe(32_767); // clamped to max
|
|
161
165
|
expect(NonZeroInt16.pow(asNonZeroInt16(2), asNonZeroInt16(3))).toBe(8);
|
|
162
166
|
});
|
|
@@ -169,6 +173,7 @@ describe('NonZeroInt16', () => {
|
|
|
169
173
|
|
|
170
174
|
for (const _ of range(10)) {
|
|
171
175
|
const result = NonZeroInt16.random(min, max);
|
|
176
|
+
|
|
172
177
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
173
178
|
expect(result).toBeLessThanOrEqual(max);
|
|
174
179
|
expect(NonZeroInt16.is(result)).toBe(true);
|
|
@@ -180,6 +185,7 @@ describe('NonZeroInt16', () => {
|
|
|
180
185
|
test('generates values within NonZeroInt16 range', () => {
|
|
181
186
|
for (const _ of range(10)) {
|
|
182
187
|
const result = NonZeroInt16.random(-20, 20);
|
|
188
|
+
|
|
183
189
|
expect(result).toBeGreaterThanOrEqual(-32_768);
|
|
184
190
|
expect(result).toBeLessThanOrEqual(32_767);
|
|
185
191
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
NonZeroInt32,
|
|
7
7
|
} from './non-zero-int32.mjs';
|
|
8
8
|
|
|
9
|
-
describe('NonZeroInt32', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('NonZeroInt32 test', () => {
|
|
10
|
+
describe(asNonZeroInt32, () => {
|
|
11
11
|
test('accepts valid non-zero int32 values', () => {
|
|
12
12
|
expect(() => asNonZeroInt32(1)).not.toThrow();
|
|
13
13
|
expect(() => asNonZeroInt32(-1)).not.toThrow();
|
|
@@ -62,7 +62,7 @@ describe('NonZeroInt32', () => {
|
|
|
62
62
|
);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
describe(
|
|
65
|
+
describe(isNonZeroInt32, () => {
|
|
66
66
|
test('correctly identifies non-zero int32 values', () => {
|
|
67
67
|
expect(isNonZeroInt32(1)).toBe(true);
|
|
68
68
|
expect(isNonZeroInt32(-1)).toBe(true);
|
|
@@ -127,6 +127,7 @@ describe('NonZeroInt32', () => {
|
|
|
127
127
|
asNonZeroInt32(2_147_483_000),
|
|
128
128
|
asNonZeroInt32(1000),
|
|
129
129
|
);
|
|
130
|
+
|
|
130
131
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
131
132
|
expect(NonZeroInt32.add(a, b)).toBe(1_500_000);
|
|
132
133
|
});
|
|
@@ -136,6 +137,7 @@ describe('NonZeroInt32', () => {
|
|
|
136
137
|
asNonZeroInt32(-2_147_483_000),
|
|
137
138
|
asNonZeroInt32(1000),
|
|
138
139
|
);
|
|
140
|
+
|
|
139
141
|
expect(result).toBe(-2_147_483_648); // clamped to min
|
|
140
142
|
expect(NonZeroInt32.sub(a, b)).toBe(500_000);
|
|
141
143
|
});
|
|
@@ -145,6 +147,7 @@ describe('NonZeroInt32', () => {
|
|
|
145
147
|
asNonZeroInt32(100_000),
|
|
146
148
|
asNonZeroInt32(100_000),
|
|
147
149
|
);
|
|
150
|
+
|
|
148
151
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
149
152
|
expect(NonZeroInt32.mul(asNonZeroInt32(1000), asNonZeroInt32(5))).toBe(
|
|
150
153
|
5000,
|
|
@@ -162,6 +165,7 @@ describe('NonZeroInt32', () => {
|
|
|
162
165
|
asNonZeroInt32(10_000),
|
|
163
166
|
asNonZeroInt32(3),
|
|
164
167
|
);
|
|
168
|
+
|
|
165
169
|
expect(result).toBe(2_147_483_647); // clamped to max
|
|
166
170
|
expect(NonZeroInt32.pow(asNonZeroInt32(2), asNonZeroInt32(3))).toBe(8);
|
|
167
171
|
});
|
|
@@ -174,6 +178,7 @@ describe('NonZeroInt32', () => {
|
|
|
174
178
|
|
|
175
179
|
for (const _ of range(10)) {
|
|
176
180
|
const result = NonZeroInt32.random(min, max);
|
|
181
|
+
|
|
177
182
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
178
183
|
expect(result).toBeLessThanOrEqual(max);
|
|
179
184
|
expect(NonZeroInt32.is(result)).toBe(true);
|
|
@@ -185,6 +190,7 @@ describe('NonZeroInt32', () => {
|
|
|
185
190
|
test('generates values within NonZeroInt32 range', () => {
|
|
186
191
|
for (const _ of range(10)) {
|
|
187
192
|
const result = NonZeroInt32.random(-20, 20);
|
|
193
|
+
|
|
188
194
|
expect(result).toBeGreaterThanOrEqual(-2_147_483_648);
|
|
189
195
|
expect(result).toBeLessThanOrEqual(2_147_483_647);
|
|
190
196
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
NonZeroSafeInt,
|
|
7
7
|
} from './non-zero-safe-int.mjs';
|
|
8
8
|
|
|
9
|
-
describe('NonZeroSafeInt', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('NonZeroSafeInt test', () => {
|
|
10
|
+
describe(asNonZeroSafeInt, () => {
|
|
11
11
|
test('accepts valid non-zero safe integers', () => {
|
|
12
12
|
expect(() => asNonZeroSafeInt(1)).not.toThrow();
|
|
13
13
|
expect(() => asNonZeroSafeInt(-1)).not.toThrow();
|
|
@@ -68,7 +68,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
68
68
|
);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
describe(
|
|
71
|
+
describe(isNonZeroSafeInt, () => {
|
|
72
72
|
test('correctly identifies non-zero safe integers', () => {
|
|
73
73
|
expect(isNonZeroSafeInt(1)).toBe(true);
|
|
74
74
|
expect(isNonZeroSafeInt(-1)).toBe(true);
|
|
@@ -135,6 +135,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
135
135
|
test('add (with clamping to safe integer range)', () => {
|
|
136
136
|
const largeValue = asNonZeroSafeInt(Number.MAX_SAFE_INTEGER - 1);
|
|
137
137
|
const result = NonZeroSafeInt.add(largeValue, asNonZeroSafeInt(10));
|
|
138
|
+
|
|
138
139
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
139
140
|
expect(NonZeroSafeInt.add(a, b)).toBe(7);
|
|
140
141
|
});
|
|
@@ -142,6 +143,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
142
143
|
test('sub (with clamping to safe integer range)', () => {
|
|
143
144
|
const smallValue = asNonZeroSafeInt(Number.MIN_SAFE_INTEGER + 1);
|
|
144
145
|
const result = NonZeroSafeInt.sub(smallValue, asNonZeroSafeInt(10));
|
|
146
|
+
|
|
145
147
|
expect(result).toBe(Number.MIN_SAFE_INTEGER); // clamped to min
|
|
146
148
|
expect(NonZeroSafeInt.sub(a, b)).toBe(3);
|
|
147
149
|
});
|
|
@@ -151,6 +153,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
151
153
|
Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)),
|
|
152
154
|
);
|
|
153
155
|
const result = NonZeroSafeInt.mul(largeValue, largeValue);
|
|
156
|
+
|
|
154
157
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
155
158
|
expect(
|
|
156
159
|
NonZeroSafeInt.mul(asNonZeroSafeInt(10), asNonZeroSafeInt(5)),
|
|
@@ -172,6 +175,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
172
175
|
asNonZeroSafeInt(1000),
|
|
173
176
|
asNonZeroSafeInt(10),
|
|
174
177
|
);
|
|
178
|
+
|
|
175
179
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
176
180
|
expect(NonZeroSafeInt.pow(asNonZeroSafeInt(2), asNonZeroSafeInt(3))).toBe(
|
|
177
181
|
8,
|
|
@@ -186,6 +190,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
186
190
|
|
|
187
191
|
for (const _ of range(10)) {
|
|
188
192
|
const result = NonZeroSafeInt.random(min, max);
|
|
193
|
+
|
|
189
194
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
190
195
|
expect(result).toBeLessThanOrEqual(max);
|
|
191
196
|
expect(NonZeroSafeInt.is(result)).toBe(true);
|
|
@@ -200,6 +205,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
200
205
|
|
|
201
206
|
for (const _ of range(10)) {
|
|
202
207
|
const result = NonZeroSafeInt.random(min, max);
|
|
208
|
+
|
|
203
209
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
204
210
|
expect(result).toBeLessThanOrEqual(max);
|
|
205
211
|
expect(NonZeroSafeInt.is(result)).toBe(true);
|
|
@@ -214,6 +220,7 @@ describe('NonZeroSafeInt', () => {
|
|
|
214
220
|
|
|
215
221
|
for (const _ of range(10)) {
|
|
216
222
|
const result = NonZeroSafeInt.random(min, max);
|
|
223
|
+
|
|
217
224
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
218
225
|
expect(result).toBeLessThanOrEqual(max);
|
|
219
226
|
expect(NonZeroSafeInt.is(result)).toBe(true);
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
NonZeroUint16,
|
|
7
7
|
} from './non-zero-uint16.mjs';
|
|
8
8
|
|
|
9
|
-
describe('NonZeroUint16', () => {
|
|
10
|
-
describe(
|
|
9
|
+
describe('NonZeroUint16 test', () => {
|
|
10
|
+
describe(asNonZeroUint16, () => {
|
|
11
11
|
test('accepts valid non-zero uint16 values', () => {
|
|
12
12
|
expect(() => asNonZeroUint16(1)).not.toThrow();
|
|
13
13
|
expect(() => asNonZeroUint16(1000)).not.toThrow();
|
|
@@ -68,7 +68,7 @@ describe('NonZeroUint16', () => {
|
|
|
68
68
|
);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
describe(
|
|
71
|
+
describe(isNonZeroUint16, () => {
|
|
72
72
|
test('correctly identifies non-zero uint16 values', () => {
|
|
73
73
|
expect(isNonZeroUint16(1)).toBe(true);
|
|
74
74
|
expect(isNonZeroUint16(1000)).toBe(true);
|
|
@@ -128,6 +128,7 @@ describe('NonZeroUint16', () => {
|
|
|
128
128
|
asNonZeroUint16(65_000),
|
|
129
129
|
asNonZeroUint16(1000),
|
|
130
130
|
);
|
|
131
|
+
|
|
131
132
|
expect(result).toBe(65_535); // clamped to max
|
|
132
133
|
expect(NonZeroUint16.add(a, b)).toBe(150);
|
|
133
134
|
});
|
|
@@ -142,6 +143,7 @@ describe('NonZeroUint16', () => {
|
|
|
142
143
|
asNonZeroUint16(1000),
|
|
143
144
|
asNonZeroUint16(100),
|
|
144
145
|
);
|
|
146
|
+
|
|
145
147
|
expect(result).toBe(65_535); // clamped to max
|
|
146
148
|
expect(NonZeroUint16.mul(asNonZeroUint16(10), asNonZeroUint16(5))).toBe(
|
|
147
149
|
50,
|
|
@@ -161,6 +163,7 @@ describe('NonZeroUint16', () => {
|
|
|
161
163
|
asNonZeroUint16(256),
|
|
162
164
|
asNonZeroUint16(3),
|
|
163
165
|
);
|
|
166
|
+
|
|
164
167
|
expect(result).toBe(65_535); // clamped to max
|
|
165
168
|
expect(NonZeroUint16.pow(asNonZeroUint16(2), asNonZeroUint16(3))).toBe(8);
|
|
166
169
|
});
|
|
@@ -173,6 +176,7 @@ describe('NonZeroUint16', () => {
|
|
|
173
176
|
|
|
174
177
|
for (const _ of range(10)) {
|
|
175
178
|
const result = NonZeroUint16.random(min, max);
|
|
179
|
+
|
|
176
180
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
177
181
|
expect(result).toBeLessThanOrEqual(max);
|
|
178
182
|
expect(NonZeroUint16.is(result)).toBe(true);
|
|
@@ -184,6 +188,7 @@ describe('NonZeroUint16', () => {
|
|
|
184
188
|
test('generates values within NonZeroUint16 range', () => {
|
|
185
189
|
for (const _ of range(10)) {
|
|
186
190
|
const result = NonZeroUint16.random(1, 30);
|
|
191
|
+
|
|
187
192
|
expect(result).toBeGreaterThanOrEqual(1);
|
|
188
193
|
expect(result).toBeLessThanOrEqual(65_535);
|
|
189
194
|
}
|