@futdevpro/fsm-dynamo 1.9.51 → 1.10.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/.github/workflows/main.yml +3 -3
- package/build/_collections/utils/array.util.d.ts +1 -7
- package/build/_collections/utils/array.util.d.ts.map +1 -1
- package/build/_collections/utils/array.util.js +0 -31
- package/build/_collections/utils/array.util.js.map +1 -1
- package/build/_collections/utils/array.util.spec.js +0 -35
- package/build/_collections/utils/array.util.spec.js.map +1 -1
- package/build/_collections/utils/log.util.d.ts +1 -0
- package/build/_collections/utils/log.util.d.ts.map +1 -1
- package/build/_collections/utils/log.util.js +3 -0
- package/build/_collections/utils/log.util.js.map +1 -1
- package/build/_collections/utils/log.util.spec.d.ts +2 -0
- package/build/_collections/utils/log.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/log.util.spec.js +85 -0
- package/build/_collections/utils/log.util.spec.js.map +1 -0
- package/build/_collections/utils/math/box-bounds.util.spec.d.ts +2 -0
- package/build/_collections/utils/math/box-bounds.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/math/box-bounds.util.spec.js +53 -0
- package/build/_collections/utils/math/box-bounds.util.spec.js.map +1 -0
- package/build/_collections/utils/math/math.util.spec.d.ts +2 -0
- package/build/_collections/utils/math/math.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/math/math.util.spec.js +89 -0
- package/build/_collections/utils/math/math.util.spec.js.map +1 -0
- package/build/_collections/utils/math/random.util.spec.d.ts +2 -0
- package/build/_collections/utils/math/random.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/math/random.util.spec.js +75 -0
- package/build/_collections/utils/math/random.util.spec.js.map +1 -0
- package/build/_collections/utils/math/trigonometry.util.spec.d.ts +2 -0
- package/build/_collections/utils/math/trigonometry.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/math/trigonometry.util.spec.js +49 -0
- package/build/_collections/utils/math/trigonometry.util.spec.js.map +1 -0
- package/build/_collections/utils/math/vector2.util.spec.d.ts +2 -0
- package/build/_collections/utils/math/vector2.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/math/vector2.util.spec.js +82 -0
- package/build/_collections/utils/math/vector2.util.spec.js.map +1 -0
- package/build/_collections/utils/regex/password-regex.util.spec.d.ts +2 -0
- package/build/_collections/utils/regex/password-regex.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/regex/password-regex.util.spec.js +44 -0
- package/build/_collections/utils/regex/password-regex.util.spec.js.map +1 -0
- package/build/_collections/utils/regex/regex.util.spec.d.ts +2 -0
- package/build/_collections/utils/regex/regex.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/regex/regex.util.spec.js +40 -0
- package/build/_collections/utils/regex/regex.util.spec.js.map +1 -0
- package/build/_collections/utils/regex/username-regex.util.spec.d.ts +2 -0
- package/build/_collections/utils/regex/username-regex.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/regex/username-regex.util.spec.js +59 -0
- package/build/_collections/utils/regex/username-regex.util.spec.js.map +1 -0
- package/build/_collections/utils/round-list.util.d.ts.map +1 -1
- package/build/_collections/utils/round-list.util.js +1 -1
- package/build/_collections/utils/round-list.util.js.map +1 -1
- package/build/_collections/utils/round-list.util.spec.d.ts +2 -0
- package/build/_collections/utils/round-list.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/round-list.util.spec.js +65 -0
- package/build/_collections/utils/round-list.util.spec.js.map +1 -0
- package/build/_collections/utils/shared.util.spec.d.ts +2 -0
- package/build/_collections/utils/shared.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/shared.util.spec.js +113 -0
- package/build/_collections/utils/shared.util.spec.js.map +1 -0
- package/build/_collections/utils/string.util.d.ts +5 -0
- package/build/_collections/utils/string.util.d.ts.map +1 -0
- package/build/_collections/utils/string.util.js +11 -0
- package/build/_collections/utils/string.util.js.map +1 -0
- package/build/_collections/utils/string.util.spec.d.ts +2 -0
- package/build/_collections/utils/string.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/string.util.spec.js +36 -0
- package/build/_collections/utils/string.util.spec.js.map +1 -0
- package/build/_collections/utils/type-cloning-facility.util.spec.d.ts +2 -0
- package/build/_collections/utils/type-cloning-facility.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/type-cloning-facility.util.spec.js +41 -0
- package/build/_collections/utils/type-cloning-facility.util.spec.js.map +1 -0
- package/build/_collections/utils/utilities.util.d.ts +0 -8
- package/build/_collections/utils/utilities.util.d.ts.map +1 -1
- package/build/_collections/utils/utilities.util.js +0 -8
- package/build/_collections/utils/utilities.util.js.map +1 -1
- package/build/_collections/utils/utilities.util.spec.d.ts +2 -0
- package/build/_collections/utils/utilities.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/utilities.util.spec.js +145 -0
- package/build/_collections/utils/utilities.util.spec.js.map +1 -0
- package/build/_collections/utils/uuid.util.d.ts +0 -1
- package/build/_collections/utils/uuid.util.d.ts.map +1 -1
- package/build/_collections/utils/uuid.util.js +1 -1
- package/build/_collections/utils/uuid.util.js.map +1 -1
- package/build/_collections/utils/uuid.util.spec.d.ts +2 -0
- package/build/_collections/utils/uuid.util.spec.d.ts.map +1 -0
- package/build/_collections/utils/uuid.util.spec.js +29 -0
- package/build/_collections/utils/uuid.util.spec.js.map +1 -0
- package/build/_models/control-models/data-model-params.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/data-model-params.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/data-model-params.control-model.spec.js +53 -0
- package/build/_models/control-models/data-model-params.control-model.spec.js.map +1 -0
- package/build/_models/control-models/data-property-params.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/data-property-params.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/data-property-params.control-model.spec.js +83 -0
- package/build/_models/control-models/data-property-params.control-model.spec.js.map +1 -0
- package/build/_models/control-models/poll.control-model.d.ts +7 -7
- package/build/_models/control-models/poll.control-model.d.ts.map +1 -1
- package/build/_models/control-models/poll.control-model.js.map +1 -1
- package/build/_models/control-models/poll.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/poll.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/poll.control-model.spec.js +57 -0
- package/build/_models/control-models/poll.control-model.spec.js.map +1 -0
- package/build/_models/control-models/range-value.control-model.spec.d.ts +2 -0
- package/build/_models/control-models/range-value.control-model.spec.d.ts.map +1 -0
- package/build/_models/control-models/range-value.control-model.spec.js +163 -0
- package/build/_models/control-models/range-value.control-model.spec.js.map +1 -0
- package/build/_models/data-models/metadata.data-model.spec.d.ts +2 -0
- package/build/_models/data-models/metadata.data-model.spec.d.ts.map +1 -0
- package/build/_models/data-models/metadata.data-model.spec.js +102 -0
- package/build/_models/data-models/metadata.data-model.spec.js.map +1 -0
- package/build/_models/interfaces/search-query.interface.d.ts +2 -2
- package/build/_models/interfaces/search-query.interface.d.ts.map +1 -1
- package/build/_models/interfaces/search-result.interface.d.ts +5 -0
- package/build/_models/interfaces/search-result.interface.d.ts.map +1 -0
- package/build/_models/interfaces/search-result.interface.js +3 -0
- package/build/_models/interfaces/search-result.interface.js.map +1 -0
- package/build/_modules/custom-data/_models/cud.data-model.spec.d.ts +2 -0
- package/build/_modules/custom-data/_models/cud.data-model.spec.d.ts.map +1 -0
- package/build/_modules/custom-data/_models/cud.data-model.spec.js +34 -0
- package/build/_modules/custom-data/_models/cud.data-model.spec.js.map +1 -0
- package/build/_modules/location/_collections/loc-regions.util.spec.d.ts +2 -0
- package/build/_modules/location/_collections/loc-regions.util.spec.d.ts.map +1 -0
- package/build/_modules/location/_collections/loc-regions.util.spec.js +51 -0
- package/build/_modules/location/_collections/loc-regions.util.spec.js.map +1 -0
- package/build/_modules/location/_collections/loc.util.spec.d.ts +2 -0
- package/build/_modules/location/_collections/loc.util.spec.d.ts.map +1 -0
- package/build/_modules/location/_collections/loc.util.spec.js +39 -0
- package/build/_modules/location/_collections/loc.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-country-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-country-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-country-pipe.util.spec.js +33 -0
- package/build/_modules/pipe/_collections/utils/pip-country-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-custom-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-custom-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-custom-pipe.util.spec.js +36 -0
- package/build/_modules/pipe/_collections/utils/pip-custom-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-division-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-division-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-division-pipe.util.spec.js +35 -0
- package/build/_modules/pipe/_collections/utils/pip-division-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-list-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-list-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-list-pipe.util.spec.js +31 -0
- package/build/_modules/pipe/_collections/utils/pip-list-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.spec.js +54 -0
- package/build/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-obj-key-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-obj-key-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-obj-key-pipe.util.spec.js +26 -0
- package/build/_modules/pipe/_collections/utils/pip-obj-key-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-range-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-range-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-range-pipe.util.spec.js +50 -0
- package/build/_modules/pipe/_collections/utils/pip-range-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-region-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-region-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-region-pipe.util.spec.js +23 -0
- package/build/_modules/pipe/_collections/utils/pip-region-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-replace-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-replace-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-replace-pipe.util.spec.js +38 -0
- package/build/_modules/pipe/_collections/utils/pip-replace-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-slider-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-slider-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-slider-pipe.util.spec.js +20 -0
- package/build/_modules/pipe/_collections/utils/pip-slider-pipe.util.spec.js.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-smart-replace-pipe.util.spec.d.ts +2 -0
- package/build/_modules/pipe/_collections/utils/pip-smart-replace-pipe.util.spec.d.ts.map +1 -0
- package/build/_modules/pipe/_collections/utils/pip-smart-replace-pipe.util.spec.js +49 -0
- package/build/_modules/pipe/_collections/utils/pip-smart-replace-pipe.util.spec.js.map +1 -0
- package/build/_modules/socket/_models/sck-client-params.control-model.spec.d.ts +2 -0
- package/build/_modules/socket/_models/sck-client-params.control-model.spec.d.ts.map +1 -0
- package/build/_modules/socket/_models/sck-client-params.control-model.spec.js +54 -0
- package/build/_modules/socket/_models/sck-client-params.control-model.spec.js.map +1 -0
- package/build/_modules/socket/_models/sck-socket-event.control-model.d.ts +1 -1
- package/build/_modules/socket/_models/sck-socket-event.control-model.d.ts.map +1 -1
- package/build/_modules/socket/_models/sck-socket-event.control-model.js +2 -2
- package/build/_modules/socket/_models/sck-socket-event.control-model.js.map +1 -1
- package/build/_modules/socket/_models/sck-socket-event.control-model.spec.d.ts +2 -0
- package/build/_modules/socket/_models/sck-socket-event.control-model.spec.d.ts.map +1 -0
- package/build/_modules/socket/_models/sck-socket-event.control-model.spec.js +49 -0
- package/build/_modules/socket/_models/sck-socket-event.control-model.spec.js.map +1 -0
- package/build/_modules/socket/_services/sck-client.service-base.d.ts +3 -3
- package/build/_modules/socket/_services/sck-client.service-base.d.ts.map +1 -1
- package/build/_modules/socket/_services/sck-client.service-base.js +3 -3
- package/build/_modules/socket/_services/sck-client.service-base.js.map +1 -1
- package/build/_modules/socket/_services/sck-client.service-base.spec.d.ts +2 -0
- package/build/_modules/socket/_services/sck-client.service-base.spec.d.ts.map +1 -0
- package/build/_modules/socket/_services/sck-client.service-base.spec.js +82 -0
- package/build/_modules/socket/_services/sck-client.service-base.spec.js.map +1 -0
- package/build/_modules/usage/_models/usg-action.control-model.spec.d.ts +2 -0
- package/build/_modules/usage/_models/usg-action.control-model.spec.d.ts.map +1 -0
- package/build/_modules/usage/_models/usg-action.control-model.spec.js +24 -0
- package/build/_modules/usage/_models/usg-action.control-model.spec.js.map +1 -0
- package/build/_modules/usage/_models/usg-daily-usage-data.control-model.spec.d.ts +2 -0
- package/build/_modules/usage/_models/usg-daily-usage-data.control-model.spec.d.ts.map +1 -0
- package/build/_modules/usage/_models/usg-daily-usage-data.control-model.spec.js +33 -0
- package/build/_modules/usage/_models/usg-daily-usage-data.control-model.spec.js.map +1 -0
- package/build/_modules/usage/_models/usg-data.control-model.spec.d.ts +2 -0
- package/build/_modules/usage/_models/usg-data.control-model.spec.d.ts.map +1 -0
- package/build/_modules/usage/_models/usg-data.control-model.spec.js +37 -0
- package/build/_modules/usage/_models/usg-data.control-model.spec.js.map +1 -0
- package/build/_modules/usage/_models/usg-session.data-model.spec.d.ts +2 -0
- package/build/_modules/usage/_models/usg-session.data-model.spec.d.ts.map +1 -0
- package/build/_modules/usage/_models/usg-session.data-model.spec.js +66 -0
- package/build/_modules/usage/_models/usg-session.data-model.spec.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/futdevpro-fsm-dynamo-01.10.02.tgz +0 -0
- package/package.json +11 -23
- package/src/_collections/utils/array.util.spec.ts +0 -45
- package/src/_collections/utils/array.util.ts +2 -45
- package/src/_collections/utils/log.util.spec.ts +99 -0
- package/src/_collections/utils/log.util.ts +4 -0
- package/src/_collections/utils/math/box-bounds.util.spec.ts +63 -0
- package/src/_collections/utils/math/math.util.spec.ts +104 -0
- package/src/_collections/utils/math/random.util.spec.ts +82 -0
- package/src/_collections/utils/math/trigonometry.util.spec.ts +57 -0
- package/src/_collections/utils/math/vector2.util.spec.ts +94 -0
- package/src/_collections/utils/regex/password-regex.util.spec.ts +51 -0
- package/src/_collections/utils/regex/regex.util.spec.ts +42 -0
- package/src/_collections/utils/regex/username-regex.util.spec.ts +61 -0
- package/src/_collections/utils/round-list.util.spec.ts +79 -0
- package/src/_collections/utils/round-list.util.ts +46 -1
- package/src/_collections/utils/shared.util.spec.ts +143 -0
- package/src/_collections/utils/string.util.spec.ts +41 -0
- package/src/_collections/utils/string.util.ts +10 -0
- package/src/_collections/utils/type-cloning-facility.util.spec.ts +51 -0
- package/src/_collections/utils/utilities.util.spec.ts +166 -0
- package/src/_collections/utils/utilities.util.ts +1 -12
- package/src/_collections/utils/uuid.util.spec.ts +30 -0
- package/src/_collections/utils/uuid.util.ts +14 -1
- package/src/_models/control-models/data-model-params.control-model.spec.ts +67 -0
- package/src/_models/control-models/data-property-params.control-model.spec.ts +109 -0
- package/src/_models/control-models/poll.control-model.spec.ts +63 -0
- package/src/_models/control-models/poll.control-model.ts +8 -7
- package/src/_models/control-models/range-value.control-model.spec.ts +187 -0
- package/src/_models/data-models/metadata.data-model.spec.ts +123 -0
- package/src/_models/interfaces/search-query.interface.ts +2 -2
- package/src/_models/interfaces/search-result.interface.ts +6 -0
- package/src/_modules/custom-data/_models/cud.data-model.spec.ts +38 -0
- package/src/_modules/location/_collections/loc-regions.util.spec.ts +61 -0
- package/src/_modules/location/_collections/loc.util.spec.ts +52 -0
- package/src/_modules/pipe/_collections/utils/pip-country-pipe.util.spec.ts +47 -0
- package/src/_modules/pipe/_collections/utils/pip-custom-pipe.util.spec.ts +39 -0
- package/src/_modules/pipe/_collections/utils/pip-division-pipe.util.spec.ts +41 -0
- package/src/_modules/pipe/_collections/utils/pip-list-pipe.util.spec.ts +34 -0
- package/src/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.spec.ts +60 -0
- package/src/_modules/pipe/_collections/utils/pip-obj-key-pipe.util.spec.ts +28 -0
- package/src/_modules/pipe/_collections/utils/pip-range-pipe.util.spec.ts +59 -0
- package/src/_modules/pipe/_collections/utils/pip-region-pipe.util.spec.ts +31 -0
- package/src/_modules/pipe/_collections/utils/pip-replace-pipe.util.spec.ts +44 -0
- package/src/_modules/pipe/_collections/utils/pip-slider-pipe.util.spec.ts +21 -0
- package/src/_modules/pipe/_collections/utils/pip-smart-replace-pipe.util.spec.ts +61 -0
- package/src/_modules/socket/_models/sck-client-params.control-model.spec.ts +67 -0
- package/src/_modules/socket/_models/sck-socket-event.control-model.spec.ts +66 -0
- package/src/_modules/socket/_models/sck-socket-event.control-model.ts +2 -2
- package/src/_modules/socket/_services/sck-client.service-base.spec.ts +99 -0
- package/src/_modules/socket/_services/sck-client.service-base.ts +7 -7
- package/src/_modules/usage/_models/usg-action.control-model.spec.ts +27 -0
- package/src/_modules/usage/_models/usg-daily-usage-data.control-model.spec.ts +36 -0
- package/src/_modules/usage/_models/usg-data.control-model.spec.ts +41 -0
- package/src/_modules/usage/_models/usg-session.data-model.spec.ts +73 -0
- package/src/index.ts +1 -0
- package/futdevpro-fsm-dynamo-01.09.51.tgz +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_Random } from './random.util';
|
|
3
|
+
import { DyFM_RandomWeight } from '../../../_models/interfaces/random-weight.interface';
|
|
4
|
+
|
|
5
|
+
describe('DyFM_Random', () => {
|
|
6
|
+
describe('getRandomWeightedInt', () => {
|
|
7
|
+
it('should return a weighted random integer within the range', () => {
|
|
8
|
+
const weights: DyFM_RandomWeight<number>[] = [
|
|
9
|
+
{ chance: 0.1, result: 1 },
|
|
10
|
+
{ chance: 0.3, result: 2 },
|
|
11
|
+
{ chance: 0.6, result: 3 }
|
|
12
|
+
];
|
|
13
|
+
const result = DyFM_Random.getRandomWeightedInt(1, 3, weights);
|
|
14
|
+
expect(result).toBeGreaterThanOrEqual(1);
|
|
15
|
+
expect(result).toBeLessThanOrEqual(3);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should normalize weights if their sum is greater than 1', () => {
|
|
19
|
+
const weights: DyFM_RandomWeight<number>[] = [
|
|
20
|
+
{ chance: 0.5, result: 1 },
|
|
21
|
+
{ chance: 0.5, result: 2 },
|
|
22
|
+
{ chance: 0.5, result: 3 }
|
|
23
|
+
];
|
|
24
|
+
const result = DyFM_Random.getRandomWeightedInt(1, 3, weights);
|
|
25
|
+
expect(result).toBeGreaterThanOrEqual(1);
|
|
26
|
+
expect(result).toBeLessThanOrEqual(3);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return a random integer within the range if no weights match', () => {
|
|
30
|
+
const weights: DyFM_RandomWeight<number>[] = [
|
|
31
|
+
{ chance: 0, result: 1 },
|
|
32
|
+
{ chance: 0, result: 2 },
|
|
33
|
+
{ chance: 0, result: 3 }
|
|
34
|
+
];
|
|
35
|
+
const result = DyFM_Random.getRandomWeightedInt(1, 3, weights);
|
|
36
|
+
expect(result).toBeGreaterThanOrEqual(1);
|
|
37
|
+
expect(result).toBeLessThanOrEqual(3);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('getRandomInt', () => {
|
|
42
|
+
it('should return a random integer within the specified range', () => {
|
|
43
|
+
const min = 5;
|
|
44
|
+
const max = 10;
|
|
45
|
+
const result = DyFM_Random.getRandomInt(min, max);
|
|
46
|
+
expect(result).toBeGreaterThanOrEqual(min);
|
|
47
|
+
expect(result).toBeLessThanOrEqual(max);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('getRandomListElement', () => {
|
|
52
|
+
it('should return a random element from the list', () => {
|
|
53
|
+
const list = [1, 2, 3, 4, 5];
|
|
54
|
+
const result = DyFM_Random.getRandomListElement(list);
|
|
55
|
+
expect(list).toContain(result);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should return null if the list is empty', () => {
|
|
59
|
+
const list: number[] = [];
|
|
60
|
+
const result = DyFM_Random.getRandomListElement(list);
|
|
61
|
+
expect(result).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('getRandomWeighted', () => {
|
|
66
|
+
it('should return a weighted random element', () => {
|
|
67
|
+
const weights: DyFM_RandomWeight<string>[] = [
|
|
68
|
+
{ chance: 0.2, result: 'a' },
|
|
69
|
+
{ chance: 0.5, result: 'b' },
|
|
70
|
+
{ chance: 0.3, result: 'c' }
|
|
71
|
+
];
|
|
72
|
+
const result = DyFM_Random.getRandomWeighted(weights);
|
|
73
|
+
expect(['a', 'b', 'c']).toContain(result);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should return null if weights array is empty', () => {
|
|
77
|
+
const weights: DyFM_RandomWeight<string>[] = [];
|
|
78
|
+
const result = DyFM_Random.getRandomWeighted(weights);
|
|
79
|
+
expect(result).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_Trigonometry } from './trigonometry.util';
|
|
3
|
+
|
|
4
|
+
describe('DyFM_Trigonometry', () => {
|
|
5
|
+
|
|
6
|
+
describe('getClamp', () => {
|
|
7
|
+
it('should calculate the clamp using the hypotenuse and angle', () => {
|
|
8
|
+
const result = DyFM_Trigonometry.getClamp(10, 30);
|
|
9
|
+
expect(result).toBeCloseTo(5, 0);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should use a default angle of 45 degrees if no angle is provided', () => {
|
|
13
|
+
const result = DyFM_Trigonometry.getClamp(10);
|
|
14
|
+
expect(result).toBeCloseTo(7.071, 3);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('getClampByClampAndHypotenuse', () => {
|
|
19
|
+
it('should calculate the clamp using another clamp and the hypotenuse', () => {
|
|
20
|
+
const result = DyFM_Trigonometry.getClampByClampAndHypotenuse(6, 10);
|
|
21
|
+
expect(result).toBeCloseTo(8, 0);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
xit('should throw an error if the hypotenuse is smaller than the clamp', () => {
|
|
25
|
+
expect(() => {
|
|
26
|
+
DyFM_Trigonometry.getClampByClampAndHypotenuse(12, 10);
|
|
27
|
+
}).toThrowError('getClampByClampAndHypotenuse error hypotenuse is smaller than clamp (a:12 > c:10)');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('getHypotenuse', () => {
|
|
32
|
+
it('should calculate the hypotenuse using two clamps', () => {
|
|
33
|
+
const result = DyFM_Trigonometry.getHypotenuse(3, 4);
|
|
34
|
+
expect(result).toBeCloseTo(5, 0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should use an isosceles triangle if the second clamp is not provided', () => {
|
|
38
|
+
const result = DyFM_Trigonometry.getHypotenuse(3);
|
|
39
|
+
expect(result).toBeCloseTo(4.243, 3);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('angleToRadians', () => {
|
|
44
|
+
it('should convert degrees to radians', () => {
|
|
45
|
+
const result = DyFM_Trigonometry.angleToRadians(180);
|
|
46
|
+
expect(result).toBeCloseTo(Math.PI, 5);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('radiansToAngle', () => {
|
|
51
|
+
it('should convert radians to degrees', () => {
|
|
52
|
+
const result = DyFM_Trigonometry.radiansToAngle(Math.PI);
|
|
53
|
+
expect(result).toBeCloseTo(180, 5);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_Vector2_Util, DyFM_V2_U } from './vector2.util';
|
|
3
|
+
import { DyFM_Vector2 } from '../../../_models/interfaces/vector2.interface';
|
|
4
|
+
|
|
5
|
+
describe('DyFM_Vector2_Util', () => {
|
|
6
|
+
it('should create an instance with default values', () => {
|
|
7
|
+
const vector = new DyFM_Vector2_Util();
|
|
8
|
+
expect(vector.x).toBe(0);
|
|
9
|
+
expect(vector.y).toBe(0);
|
|
10
|
+
expect(vector.magintude).toBe(0);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should create an instance with given x and y values', () => {
|
|
14
|
+
const vector = new DyFM_Vector2_Util(3, 4);
|
|
15
|
+
expect(vector.x).toBe(3);
|
|
16
|
+
expect(vector.y).toBe(4);
|
|
17
|
+
expect(vector.magintude).toBe(5);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should create an instance with a DyFM_Vector2 object', () => {
|
|
21
|
+
const vector = new DyFM_Vector2_Util({ x: 1, y: 2 });
|
|
22
|
+
expect(vector.x).toBe(1);
|
|
23
|
+
expect(vector.y).toBe(2);
|
|
24
|
+
expect(vector.magintude).toBeCloseTo(Math.sqrt(5));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should calculate distance between two vectors', () => {
|
|
28
|
+
const a: DyFM_Vector2 = { x: 0, y: 0 };
|
|
29
|
+
const b: DyFM_Vector2 = { x: 3, y: 4 };
|
|
30
|
+
const distance = DyFM_Vector2_Util.distance(a, b);
|
|
31
|
+
expect(distance).toBe(5);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should add two vectors', () => {
|
|
35
|
+
const a: DyFM_Vector2 = { x: 1, y: 2 };
|
|
36
|
+
const b: DyFM_Vector2 = { x: 3, y: 4 };
|
|
37
|
+
const result = DyFM_Vector2_Util.plus(a, b);
|
|
38
|
+
expect(result.x).toBe(4);
|
|
39
|
+
expect(result.y).toBe(6);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should subtract two vectors', () => {
|
|
43
|
+
const a: DyFM_Vector2 = { x: 5, y: 6 };
|
|
44
|
+
const b: DyFM_Vector2 = { x: 3, y: 4 };
|
|
45
|
+
const result = DyFM_Vector2_Util.minus(a, b);
|
|
46
|
+
expect(result.x).toBe(2);
|
|
47
|
+
expect(result.y).toBe(2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should multiply a vector by a scalar', () => {
|
|
51
|
+
const vector: DyFM_Vector2 = { x: 2, y: 3 };
|
|
52
|
+
const result = DyFM_Vector2_Util.multiply(vector, 2);
|
|
53
|
+
expect(result.x).toBe(4);
|
|
54
|
+
expect(result.y).toBe(6);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should divide a vector by a scalar', () => {
|
|
58
|
+
const vector: DyFM_Vector2 = { x: 4, y: 6 };
|
|
59
|
+
const result = DyFM_Vector2_Util.divide(vector, 2);
|
|
60
|
+
expect(result.x).toBe(2);
|
|
61
|
+
expect(result.y).toBe(3);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should negate a vector', () => {
|
|
65
|
+
const vector: DyFM_Vector2 = { x: 3, y: 4 };
|
|
66
|
+
const result = DyFM_Vector2_Util.negative(vector);
|
|
67
|
+
expect(result.x).toBe(-3);
|
|
68
|
+
expect(result.y).toBe(-4);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should normalize a vector', () => {
|
|
72
|
+
const vector: DyFM_Vector2 = { x: 3, y: 4 };
|
|
73
|
+
const result = DyFM_Vector2_Util.normalize(vector);
|
|
74
|
+
expect(result.magintude).toBeCloseTo(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should clone a vector', () => {
|
|
78
|
+
const vector: DyFM_Vector2 = { x: 3, y: 4 };
|
|
79
|
+
const clone = DyFM_Vector2_Util.clone(vector);
|
|
80
|
+
expect(clone).toEqual(vector);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should check if two vectors are equal', () => {
|
|
84
|
+
const a: DyFM_Vector2 = { x: 3, y: 4 };
|
|
85
|
+
const b: DyFM_Vector2 = { x: 3, y: 4 };
|
|
86
|
+
expect(DyFM_Vector2_Util.isEqual(a, b)).toBeTrue();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should check if two vectors are not equal', () => {
|
|
90
|
+
const a: DyFM_Vector2 = { x: 3, y: 4 };
|
|
91
|
+
const b: DyFM_Vector2 = { x: 5, y: 6 };
|
|
92
|
+
expect(DyFM_Vector2_Util.isEqual(a, b)).toBeFalse();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_getPasswordErrors } from './password-regex.util';
|
|
3
|
+
|
|
4
|
+
describe('DyFM_getPasswordErrors', () => {
|
|
5
|
+
|
|
6
|
+
it('should return an empty array for a valid password', () => {
|
|
7
|
+
const password = 'Valid1!';
|
|
8
|
+
const result = DyFM_getPasswordErrors(password);
|
|
9
|
+
expect(result).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return an error for missing lowercase letter', () => {
|
|
13
|
+
const password = 'INVALID1!';
|
|
14
|
+
const result = DyFM_getPasswordErrors(password);
|
|
15
|
+
expect(result).toContain('Password must include at least one lowercase letter.');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return an error for missing uppercase letter', () => {
|
|
19
|
+
const password = 'invalid1!';
|
|
20
|
+
const result = DyFM_getPasswordErrors(password);
|
|
21
|
+
expect(result).toContain('Password must include at least one uppercase letter.');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should return an error for missing digit', () => {
|
|
25
|
+
const password = 'Invalid!';
|
|
26
|
+
const result = DyFM_getPasswordErrors(password);
|
|
27
|
+
expect(result).toContain('Password must include at least one digit.');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return an error for missing special character', () => {
|
|
31
|
+
const password = 'Invalid1';
|
|
32
|
+
const result = DyFM_getPasswordErrors(password);
|
|
33
|
+
expect(result).toContain('Password must include at least one of the !@#$%^&* characters.');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should return an error for password length less than 6', () => {
|
|
37
|
+
const password = 'Inv1!';
|
|
38
|
+
const result = DyFM_getPasswordErrors(password);
|
|
39
|
+
expect(result).toContain('Password must be at least 6 characters long.');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return multiple errors for a completely invalid password', () => {
|
|
43
|
+
const password = 'inv';
|
|
44
|
+
const result = DyFM_getPasswordErrors(password);
|
|
45
|
+
expect(result).toContain('Password must include at least one uppercase letter.');
|
|
46
|
+
expect(result).toContain('Password must include at least one digit.');
|
|
47
|
+
expect(result).toContain('Password must include at least one of the !@#$%^&* characters.');
|
|
48
|
+
expect(result).toContain('Password must be at least 6 characters long.');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_emailRegex } from './regex.util';
|
|
3
|
+
|
|
4
|
+
describe('DyFM_emailRegex', () => {
|
|
5
|
+
it('should match valid email addresses', () => {
|
|
6
|
+
const validEmails: string[] = [
|
|
7
|
+
'test@example.com',
|
|
8
|
+
'user.name+tag+sorting@example.com',
|
|
9
|
+
'user_name@example.co.uk',
|
|
10
|
+
'user-name@example.org',
|
|
11
|
+
'user123@example.museum',
|
|
12
|
+
'user@example.travel',
|
|
13
|
+
'user@example.mobi',
|
|
14
|
+
'user@example.info',
|
|
15
|
+
'user@example.jobs'
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
validEmails.forEach(email => {
|
|
19
|
+
expect(DyFM_emailRegex.test(email)).toBeTrue();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
xit('should not match invalid email addresses', () => {
|
|
24
|
+
const invalidEmails: string[] = [
|
|
25
|
+
'plainaddress',
|
|
26
|
+
'@missingusername.com',
|
|
27
|
+
'username@.com',
|
|
28
|
+
'username@com',
|
|
29
|
+
'username@.com.',
|
|
30
|
+
'username@-example.com',
|
|
31
|
+
'username@example..com',
|
|
32
|
+
'username@example.c',
|
|
33
|
+
'username@.example.com',
|
|
34
|
+
'username@.example.com.',
|
|
35
|
+
'username@.example..com'
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
invalidEmails.forEach(email => {
|
|
39
|
+
expect(DyFM_emailRegex.test(email)).toBeFalse();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_usernameRegex } from './username-regex.util';
|
|
3
|
+
|
|
4
|
+
describe('DyFM_usernameRegex', () => {
|
|
5
|
+
it('should match valid usernames', () => {
|
|
6
|
+
const validUsernames: string[] = [
|
|
7
|
+
'abcdef',
|
|
8
|
+
'123456',
|
|
9
|
+
'abc123',
|
|
10
|
+
'abc-123',
|
|
11
|
+
'abc_123',
|
|
12
|
+
'abc#123',
|
|
13
|
+
'abc$123',
|
|
14
|
+
'abc%123',
|
|
15
|
+
'abc&123',
|
|
16
|
+
'abc^123',
|
|
17
|
+
'abc|123',
|
|
18
|
+
'abc*123',
|
|
19
|
+
'abc-_$#%&^|*'
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
validUsernames.forEach(username => {
|
|
23
|
+
expect(DyFM_usernameRegex.test(username)).toBeTrue();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should not match invalid usernames', () => {
|
|
28
|
+
const invalidUsernames: string[] = [
|
|
29
|
+
'abc', // less than 6 characters
|
|
30
|
+
'abc!', // invalid special character
|
|
31
|
+
'abc@123', // invalid special character
|
|
32
|
+
'abc 123', // space is not allowed
|
|
33
|
+
'abc/123', // invalid special character
|
|
34
|
+
'abc\\123', // invalid special character
|
|
35
|
+
'abc+123', // invalid special character
|
|
36
|
+
'abc=123', // invalid special character
|
|
37
|
+
'abc,123', // invalid special character
|
|
38
|
+
'abc.123', // invalid special character
|
|
39
|
+
'abc:123', // invalid special character
|
|
40
|
+
'abc;123', // invalid special character
|
|
41
|
+
'abc<123', // invalid special character
|
|
42
|
+
'abc>123', // invalid special character
|
|
43
|
+
'abc?123', // invalid special character
|
|
44
|
+
'abc@123', // invalid special character
|
|
45
|
+
'abc[123', // invalid special character
|
|
46
|
+
'abc]123', // invalid special character
|
|
47
|
+
'abc{123', // invalid special character
|
|
48
|
+
'abc}123', // invalid special character
|
|
49
|
+
'abc(123', // invalid special character
|
|
50
|
+
'abc)123', // invalid special character
|
|
51
|
+
'abc~123', // invalid special character
|
|
52
|
+
'abc`123', // invalid special character
|
|
53
|
+
'abc"123', // invalid special character
|
|
54
|
+
'abc\'123', // invalid special character
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
invalidUsernames.forEach(username => {
|
|
58
|
+
expect(DyFM_usernameRegex.test(username)).toBeFalse();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_RoundList } from './round-list.util';
|
|
3
|
+
|
|
4
|
+
describe('DyFM_RoundList', () => {
|
|
5
|
+
|
|
6
|
+
describe('getOutboundedIndex', () => {
|
|
7
|
+
it('should throw an error if listLength is 0', () => {
|
|
8
|
+
expect(() => DyFM_RoundList.getOutboundedIndex(0, 5)).toThrowError('roundListPlusIndex failed. list is empty!');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return correct index for positive outboundIndex within bounds', () => {
|
|
12
|
+
expect(DyFM_RoundList.getOutboundedIndex(5, 3)).toBe(3);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should return correct index for positive outboundIndex out of bounds', () => {
|
|
16
|
+
expect(DyFM_RoundList.getOutboundedIndex(5, 7)).toBe(2);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return correct index for negative outboundIndex', () => {
|
|
20
|
+
expect(DyFM_RoundList.getOutboundedIndex(5, -2)).toBe(3);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('getIndexOpposite', () => {
|
|
25
|
+
it('should return the opposite index in a circular manner', () => {
|
|
26
|
+
expect(DyFM_RoundList.getIndexOpposite(8, 7)).toBe(3);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should handle even length arrays correctly', () => {
|
|
30
|
+
expect(DyFM_RoundList.getIndexOpposite(4, 1)).toBe(3);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should handle odd length arrays correctly', () => {
|
|
34
|
+
expect(DyFM_RoundList.getIndexOpposite(5, 2)).toBe(0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('getListIndex', () => {
|
|
39
|
+
it('should return the correct element for a given outboundIndex', () => {
|
|
40
|
+
const list = ['a', 'b', 'c', 'd'];
|
|
41
|
+
expect(DyFM_RoundList.getListIndex(list, 5)).toBe('b');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should handle negative outboundIndex', () => {
|
|
45
|
+
const list = ['a', 'b', 'c', 'd'];
|
|
46
|
+
expect(DyFM_RoundList.getListIndex(list, -1)).toBe('d');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('getListOpposite', () => {
|
|
51
|
+
it('should return the opposite element in a circular manner', () => {
|
|
52
|
+
const list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
|
53
|
+
expect(DyFM_RoundList.getListOpposite(list, 'h')).toBe('d');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should handle even length lists correctly', () => {
|
|
57
|
+
const list = ['a', 'b', 'c', 'd'];
|
|
58
|
+
expect(DyFM_RoundList.getListOpposite(list, 'b')).toBe('d');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should handle odd length lists correctly', () => {
|
|
62
|
+
const list = ['a', 'b', 'c', 'd', 'e'];
|
|
63
|
+
expect(DyFM_RoundList.getListOpposite(list, 'c')).toBe('a');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('getLast', () => {
|
|
68
|
+
it('should return the last element of the list', () => {
|
|
69
|
+
const list = ['a', 'b', 'c'];
|
|
70
|
+
expect(DyFM_RoundList.getLast(list)).toBe('c');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should return null for an empty list', () => {
|
|
74
|
+
const list: string[] = [];
|
|
75
|
+
expect(DyFM_RoundList.getLast(list)).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
export class DyFM_RoundList {
|
|
6
6
|
static getOutboundedIndex(listLength: number, outboundIndex: number): number {
|
|
7
|
-
if (!
|
|
7
|
+
if (!listLength) {
|
|
8
8
|
throw new Error('roundListPlusIndex failed. list is empty!');
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -42,4 +42,49 @@ export class DyFM_RoundList {
|
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* returns the opposite index as they circular
|
|
48
|
+
* so after the last index, the first comes next
|
|
49
|
+
* an array that has 8 elements, the opposite of 7 is 3
|
|
50
|
+
* */
|
|
51
|
+
/* static getRoundListOppositeIndex(
|
|
52
|
+
arrayLength: number,
|
|
53
|
+
index: number,
|
|
54
|
+
roundUp: boolean = false
|
|
55
|
+
): number {
|
|
56
|
+
const oppositeIndex = index + (
|
|
57
|
+
roundUp ?
|
|
58
|
+
Math.ceil(arrayLength / 2) :
|
|
59
|
+
Math.floor(arrayLength / 2)
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (arrayLength <= oppositeIndex) {
|
|
63
|
+
return oppositeIndex - arrayLength;
|
|
64
|
+
} else {
|
|
65
|
+
return oppositeIndex;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static getRoundListOutboundIndex<T>(array: T[], index: number): T {
|
|
70
|
+
try {
|
|
71
|
+
while (array.length <= index) {
|
|
72
|
+
index -= array.length;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
while (index < 0) {
|
|
76
|
+
index += array.length;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return array[index];
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(
|
|
82
|
+
'DyFM_Array.getRoundListOutboundIndex error:', error,
|
|
83
|
+
'\narray:', array,
|
|
84
|
+
'\nindex:', index
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
} */
|
|
45
90
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_Shared } from './shared.util';
|
|
3
|
+
|
|
4
|
+
describe('DyFM_Shared', () => {
|
|
5
|
+
|
|
6
|
+
describe('mapObjList', () => {
|
|
7
|
+
it('should remap object list based on given paths', () => {
|
|
8
|
+
const objList = [
|
|
9
|
+
{
|
|
10
|
+
first: {
|
|
11
|
+
sub: { label: 'vlmi' },
|
|
12
|
+
dif: { name: 'asd' }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
const paths = [['first', 'sub', 'label'], ['first', 'dif', 'name']];
|
|
17
|
+
const expected = [{ label: 'vlmi', name: 'asd' }];
|
|
18
|
+
|
|
19
|
+
const result = DyFM_Shared.mapObjList(objList, paths);
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual(expected);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('getNestedData', () => {
|
|
26
|
+
it('should return nested value from object', () => {
|
|
27
|
+
const obj = {
|
|
28
|
+
nestLvl1: {
|
|
29
|
+
nestLvl2: {
|
|
30
|
+
nestLvl3: 'value'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const path = ['nestLvl1', 'nestLvl2', 'nestLvl3'];
|
|
35
|
+
|
|
36
|
+
const result = DyFM_Shared.getNestedData(obj, path);
|
|
37
|
+
|
|
38
|
+
expect(result).toBe('value');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('nestData', () => {
|
|
43
|
+
xit('should nest data at specified path', () => {
|
|
44
|
+
const obj = {};
|
|
45
|
+
const path = ['level1', 'level2'];
|
|
46
|
+
const value = 'nestedValue';
|
|
47
|
+
const expected = { level1: { level2: 'nestedValue' } };
|
|
48
|
+
|
|
49
|
+
const result = DyFM_Shared.nestData(obj, path, value);
|
|
50
|
+
|
|
51
|
+
expect(result).toEqual(expected);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('addToNestedData', () => {
|
|
56
|
+
it('should add to nested data at specified path', () => {
|
|
57
|
+
const obj = { level1: { level2: 5 } };
|
|
58
|
+
const path = ['level1', 'level2'];
|
|
59
|
+
const valueToAdd = 3;
|
|
60
|
+
const expected = { level1: { level2: 8 } };
|
|
61
|
+
|
|
62
|
+
const result = DyFM_Shared.addToNestedData(obj, path, valueToAdd);
|
|
63
|
+
|
|
64
|
+
expect(result).toEqual(expected);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('pushToNestedData', () => {
|
|
69
|
+
it('should push to nested array at specified path', () => {
|
|
70
|
+
const obj = { level1: { level2: [1, 2] } };
|
|
71
|
+
const path = ['level1', 'level2'];
|
|
72
|
+
const valueToPush = 3;
|
|
73
|
+
const expected = { level1: { level2: [1, 2, 3] } };
|
|
74
|
+
|
|
75
|
+
const result = DyFM_Shared.pushToNestedData(obj, path, valueToPush);
|
|
76
|
+
|
|
77
|
+
expect(result).toEqual(expected);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should create an array and push if none exists', () => {
|
|
81
|
+
const obj = { level1: {} };
|
|
82
|
+
const path = ['level1', 'level2'];
|
|
83
|
+
const valueToPush = 3;
|
|
84
|
+
const expected = { level1: { level2: [3] } };
|
|
85
|
+
|
|
86
|
+
const result = DyFM_Shared.pushToNestedData(obj, path, valueToPush);
|
|
87
|
+
|
|
88
|
+
expect(result).toEqual(expected);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('nestRecursiveListedData', () => {
|
|
93
|
+
it('should nest data in recursive list structure', () => {
|
|
94
|
+
const obj = { listKey: [{ listKey: [{ listKey: [{}] }] }] };
|
|
95
|
+
const nestedListKey = 'listKey';
|
|
96
|
+
const nestIndexes = [0, 0, 0];
|
|
97
|
+
const value = 'nestedValue';
|
|
98
|
+
const expected = { listKey: [{ listKey: [{ listKey: ['nestedValue'] }] }] };
|
|
99
|
+
|
|
100
|
+
const result = DyFM_Shared.nestRecursiveListedData(obj, nestedListKey, nestIndexes, value);
|
|
101
|
+
|
|
102
|
+
expect(result).toEqual(expected);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('resolveCirculation', () => {
|
|
107
|
+
xit('should resolve circular references in data', () => {
|
|
108
|
+
const obj: any = { inner: {} };
|
|
109
|
+
obj.inner.self = obj;
|
|
110
|
+
const expected = { inner: { self: 'CIRCULATION:Object.inner' } };
|
|
111
|
+
|
|
112
|
+
const result = DyFM_Shared.resolveCirculation(obj);
|
|
113
|
+
|
|
114
|
+
expect(result).toEqual(expected);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
xit('should resolve circular references in data', () => {
|
|
118
|
+
const obj: any = {};
|
|
119
|
+
obj.self = obj;
|
|
120
|
+
const expected = { self: 'CIRCULATION:ROOT;Object.self' };
|
|
121
|
+
|
|
122
|
+
const result = DyFM_Shared.resolveCirculation(obj);
|
|
123
|
+
|
|
124
|
+
expect(result).toEqual(expected);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('findCirculations', () => {
|
|
129
|
+
xit('should find circular references in data', () => {
|
|
130
|
+
const obj: any = {};
|
|
131
|
+
obj.self = obj;
|
|
132
|
+
const expected = [{
|
|
133
|
+
object: obj,
|
|
134
|
+
pathsOfAllDuplications: ['ROOT;Object', 'self']
|
|
135
|
+
}];
|
|
136
|
+
|
|
137
|
+
const result = DyFM_Shared.findCirculations(obj);
|
|
138
|
+
|
|
139
|
+
expect(result).toEqual(expected);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
});
|