@fincity/kirun-js 1.4.12 → 1.4.13

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.
@@ -0,0 +1,81 @@
1
+ import {
2
+ EventResult,
3
+ FunctionExecutionParameters,
4
+ KIRunFunctionRepository,
5
+ KIRunSchemaRepository,
6
+ } from '../../../../../src';
7
+ import { CountLoop } from '../../../../../src/engine/function/system/loop/CountLoop';
8
+
9
+ test('Count Loop1', async () => {
10
+ const loop1 = await new CountLoop().execute(
11
+ new FunctionExecutionParameters(
12
+ new KIRunFunctionRepository(),
13
+ new KIRunSchemaRepository(),
14
+ 'Test',
15
+ ).setArguments(new Map([['count', 10]])),
16
+ );
17
+
18
+ let er: EventResult | undefined;
19
+ let iterations = new Array<number>();
20
+ while ((er = loop1.next())?.getName() !== 'output') {
21
+ iterations.push(er?.getResult().get('index'));
22
+ }
23
+
24
+ expect(iterations).toMatchObject([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
25
+ expect(er?.getName()).toBe('output');
26
+ expect(er?.getResult().get('value')).toBe(10);
27
+ });
28
+
29
+ test('Count Loop2', async () => {
30
+ const loop1 = await new CountLoop().execute(
31
+ new FunctionExecutionParameters(
32
+ new KIRunFunctionRepository(),
33
+ new KIRunSchemaRepository(),
34
+ 'Test',
35
+ ).setArguments(new Map([['count', -1]])),
36
+ );
37
+
38
+ let er: EventResult | undefined;
39
+ let iterations = new Array<number>();
40
+ while ((er = loop1.next())?.getName() !== 'output') {
41
+ iterations.push(er?.getResult().get('index'));
42
+ }
43
+
44
+ expect(iterations).toMatchObject([]);
45
+ expect(er?.getName()).toBe('output');
46
+ expect(er?.getResult().get('value')).toBe(-1);
47
+ });
48
+
49
+ test('Count Loop3', async () => {
50
+ const loop1 = await new CountLoop().execute(
51
+ new FunctionExecutionParameters(
52
+ new KIRunFunctionRepository(),
53
+ new KIRunSchemaRepository(),
54
+ 'Test',
55
+ ).setArguments(new Map([['count', 0]])),
56
+ );
57
+
58
+ let er: EventResult | undefined;
59
+ let iterations = new Array<number>();
60
+ while ((er = loop1.next())?.getName() !== 'output') {
61
+ iterations.push(er?.getResult().get('index'));
62
+ }
63
+
64
+ expect(iterations).toMatchObject([]);
65
+ expect(er?.getName()).toBe('output');
66
+ expect(er?.getResult().get('value')).toBe(0);
67
+ });
68
+
69
+ test('Count Loop4', async () => {
70
+ (
71
+ await expect(async () => {
72
+ const loop1 = await new CountLoop().execute(
73
+ new FunctionExecutionParameters(
74
+ new KIRunFunctionRepository(),
75
+ new KIRunSchemaRepository(),
76
+ 'Test',
77
+ ).setArguments(new Map([])),
78
+ );
79
+ })
80
+ ).rejects.toThrowError();
81
+ });