@fincity/kirun-js 1.1.3 → 1.1.4
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/__tests__/engine/function/system/math/MathFunctionRepositoryTest.ts +108 -0
- package/__tests__/engine/function/system/math/MaximumTest.ts +38 -0
- package/__tests__/engine/function/system/math/MinimumTest.ts +38 -0
- package/__tests__/engine/function/system/math/RandomFloatTest.ts +83 -0
- package/__tests__/engine/json/schema/validator/AnyOfAllOfOneOfValidatorTest.ts +38 -0
- package/__tests__/engine/json/schema/validator/SchemaValidatorTest.ts +38 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/function/system/math/Maximum.ts +1 -1
- package/src/engine/function/system/math/Minimum.ts +1 -1
- package/src/engine/function/system/math/RandomFloat.ts +2 -2
- package/src/engine/model/AbstractStatement.ts +10 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from "../../../../../src";
|
|
2
|
+
import { GenericMathFunction } from "../../../../../src/engine/function/system/math/GenericMathFunction";
|
|
3
|
+
import { MathFunctionRepository } from "../../../../../src/engine/function/system/math/MathFunctionRepository";
|
|
4
|
+
import { Namespaces } from "../../../../../src/engine/namespaces/Namespaces";
|
|
5
|
+
import { FunctionExecutionParameters } from "../../../../../src/engine/runtime/FunctionExecutionParameters";
|
|
6
|
+
|
|
7
|
+
const MathFunction: MathFunctionRepository = new MathFunctionRepository();
|
|
8
|
+
|
|
9
|
+
test("Test Math Functions 1", async () => {
|
|
10
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
11
|
+
new KIRunFunctionRepository(),
|
|
12
|
+
new KIRunSchemaRepository()
|
|
13
|
+
).setArguments(
|
|
14
|
+
new Map([['value', 1.2]]),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect((await MathFunction.find(Namespaces.MATH, "Ceiling")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).toBe(2);
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test("Test Math Functions 2", () => {
|
|
21
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
22
|
+
new KIRunFunctionRepository(),
|
|
23
|
+
new KIRunSchemaRepository()
|
|
24
|
+
).setArguments(
|
|
25
|
+
new Map([['value', "-1.2"]]),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(async () => (await (MathFunction.find(Namespaces.MATH, "Absolute")?.execute(fep)))?.allResults()[0]?.getResult()?.get("value")).rejects.toThrowError("Value \"-1.2\" is not of valid type(s)\n-1.2 is not a Integer\n-1.2 is not a Long\n-1.2 is not a Float\n-1.2 is not a Double");
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test("Test Math Functions 3", async () => {
|
|
32
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
33
|
+
new KIRunFunctionRepository(),
|
|
34
|
+
new KIRunSchemaRepository()
|
|
35
|
+
).setArguments(
|
|
36
|
+
new Map([['value', 90]]),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect((await MathFunction.find(Namespaces.MATH, "ACosine")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).toBe(NaN);
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test("Test Math Functions 4", () => {
|
|
43
|
+
expect(MathFunction.find(Namespaces.STRING, "ASine")).toBe(undefined);
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test("test Math Functions 5", () => {
|
|
47
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
48
|
+
new KIRunFunctionRepository(),
|
|
49
|
+
new KIRunSchemaRepository()
|
|
50
|
+
).setArguments(
|
|
51
|
+
new Map([['value', "-1"]]),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(async () => (await MathFunction.find(Namespaces.MATH, "ATangent")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).rejects.toThrowError("Value \"-1\" is not of valid type(s)\n-1 is not a Integer\n-1 is not a Long\n-1 is not a Float\n-1 is not a Double");
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test("test Math Functions 6", async () => {
|
|
58
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
59
|
+
new KIRunFunctionRepository(),
|
|
60
|
+
new KIRunSchemaRepository()
|
|
61
|
+
).setArguments(
|
|
62
|
+
new Map([['value', 1]]),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect((await MathFunction.find(Namespaces.MATH, "Cosine")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).toBe(0.5403023058681398);
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test("test Math Functions 7", async () => {
|
|
69
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
70
|
+
new KIRunFunctionRepository(),
|
|
71
|
+
new KIRunSchemaRepository()
|
|
72
|
+
).setArguments(
|
|
73
|
+
new Map([['value1', 2], ['value2', 3]]),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
expect((await MathFunction.find(Namespaces.MATH, "Power")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).toBe(8);
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test("test Math Functions 8", () => {
|
|
80
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
81
|
+
new KIRunFunctionRepository(),
|
|
82
|
+
new KIRunSchemaRepository()
|
|
83
|
+
).setArguments(
|
|
84
|
+
new Map([['value1', '1'], ['value2', '1']]),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(async () => (await MathFunction.find(Namespaces.MATH, "Power")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).rejects.toThrowError("Value \"1\" is not of valid type(s)\n1 is not a Integer\n1 is not a Long\n1 is not a Float\n1 is not a Double");
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test("test Math Functions 9", async () => {
|
|
91
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
92
|
+
new KIRunFunctionRepository(),
|
|
93
|
+
new KIRunSchemaRepository()
|
|
94
|
+
).setArguments(
|
|
95
|
+
new Map([['value', [3, 2, 3, 5, 3]]]),
|
|
96
|
+
);
|
|
97
|
+
expect((await MathFunction.find(Namespaces.MATH, "Add")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).toBe(16);
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test("test Math Functions 10", async () => {
|
|
101
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
102
|
+
new KIRunFunctionRepository(),
|
|
103
|
+
new KIRunSchemaRepository()
|
|
104
|
+
).setArguments(
|
|
105
|
+
new Map([['value', [3, 2]]]),
|
|
106
|
+
);
|
|
107
|
+
expect((await MathFunction.find(Namespaces.MATH, "Hypotenuse")?.execute(fep))?.allResults()[0]?.getResult()?.get("value")).toBe(3.605551275463989);
|
|
108
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Maximum } from "../../../../../src/engine/function/system/math/Maximum";
|
|
2
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
3
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
4
|
+
|
|
5
|
+
const max = new Maximum();
|
|
6
|
+
|
|
7
|
+
test('Minimum Test 1', async () => {
|
|
8
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository,
|
|
10
|
+
new KIRunSchemaRepository
|
|
11
|
+
).setArguments(
|
|
12
|
+
new Map([['value', [3, 2, 3, 5, 3]]]),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
expect((await max.execute(fep)).allResults()[0].getResult().get('value')).toBe(5);
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('Minimum Test 2', async () => {
|
|
19
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
20
|
+
new KIRunFunctionRepository,
|
|
21
|
+
new KIRunSchemaRepository
|
|
22
|
+
).setArguments(
|
|
23
|
+
new Map([['value', [-1, -1, 0, -1, -2]]]),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
expect((await max.execute(fep)).allResults()[0].getResult().get('value')).toBe(0);
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('Minimum Test 3', () => {
|
|
30
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
31
|
+
new KIRunFunctionRepository,
|
|
32
|
+
new KIRunSchemaRepository
|
|
33
|
+
).setArguments(
|
|
34
|
+
new Map([['value', ["-1", -1, 0, -1, -2]]]),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
expect(async () => (await max.execute(fep)).allResults()[0].getResult().get('value')).rejects.toThrowError("Value \"-1\" is not of valid type(s)\n-1 is not a Integer\n-1 is not a Long\n-1 is not a Float\n-1 is not a Double");
|
|
38
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Minimum } from "../../../../../src/engine/function/system/math/Minimum";
|
|
2
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
3
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
4
|
+
|
|
5
|
+
const min = new Minimum();
|
|
6
|
+
|
|
7
|
+
test('Minimum Test 1', async () => {
|
|
8
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository,
|
|
10
|
+
new KIRunSchemaRepository
|
|
11
|
+
).setArguments(
|
|
12
|
+
new Map([['value', [3, 2, 3, 5, 3]]]),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
expect((await min.execute(fep)).allResults()[0].getResult().get('value')).toBe(2);
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('Minimum Test 2', () => {
|
|
19
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
20
|
+
new KIRunFunctionRepository,
|
|
21
|
+
new KIRunSchemaRepository
|
|
22
|
+
).setArguments(
|
|
23
|
+
new Map([['value', ["3", 2, 3, 5, 3]]]),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
expect(async () => (await min.execute(fep)).allResults()[0].getResult().get('value')).rejects.toThrowError("Value \"3\" is not of valid type(s)\n3 is not a Integer\n3 is not a Long\n3 is not a Float\n3 is not a Double");
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('Minimum Test 3', async () => {
|
|
30
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
31
|
+
new KIRunFunctionRepository,
|
|
32
|
+
new KIRunSchemaRepository
|
|
33
|
+
).setArguments(
|
|
34
|
+
new Map([['value', [-1, -2, -3, -5, -3]]]),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
expect((await min.execute(fep)).allResults()[0].getResult().get('value')).toBe(-5);
|
|
38
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RandomFloat } from "../../../../../src/engine/function/system/math/RandomFloat";
|
|
2
|
+
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
3
|
+
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
4
|
+
|
|
5
|
+
const rand = new RandomFloat();
|
|
6
|
+
|
|
7
|
+
test('rand Float 1', async () => {
|
|
8
|
+
let min = 1,
|
|
9
|
+
max = 10;
|
|
10
|
+
|
|
11
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
12
|
+
new KIRunFunctionRepository,
|
|
13
|
+
new KIRunSchemaRepository
|
|
14
|
+
).setArguments(
|
|
15
|
+
new Map([
|
|
16
|
+
['minValue', min],
|
|
17
|
+
['maxValue', max],
|
|
18
|
+
]),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
let num: number = (await rand.execute(fep)).allResults()[0].getResult().get('value');
|
|
22
|
+
|
|
23
|
+
expect(num).toBeLessThanOrEqual(max);
|
|
24
|
+
expect(num).toBeGreaterThanOrEqual(min);
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('rand Float 2', async () => {
|
|
28
|
+
let min = 0.1,
|
|
29
|
+
max = 0.9;
|
|
30
|
+
|
|
31
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
32
|
+
new KIRunFunctionRepository,
|
|
33
|
+
new KIRunSchemaRepository
|
|
34
|
+
).setArguments(
|
|
35
|
+
new Map([
|
|
36
|
+
['minValue', min],
|
|
37
|
+
['maxValue', max],
|
|
38
|
+
]),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
let num: number = (await rand.execute(fep)).allResults()[0].getResult().get('value');
|
|
42
|
+
|
|
43
|
+
expect(num).toBeLessThanOrEqual(max);
|
|
44
|
+
expect(num).toBeGreaterThanOrEqual(min);
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('rand Float 3', async () => {
|
|
48
|
+
let min = 1, max = 2147483647;
|
|
49
|
+
|
|
50
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
51
|
+
new KIRunFunctionRepository,
|
|
52
|
+
new KIRunSchemaRepository
|
|
53
|
+
).setArguments(
|
|
54
|
+
new Map([
|
|
55
|
+
['minValue', min],
|
|
56
|
+
]),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
let num: number = (await rand.execute(fep)).allResults()[0].getResult().get('value');
|
|
60
|
+
|
|
61
|
+
expect(num).toBeLessThanOrEqual(max);
|
|
62
|
+
expect(num).toBeGreaterThanOrEqual(min);
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('rand Float 4', async () => {
|
|
66
|
+
let min = 1.1,
|
|
67
|
+
max = 1.2;
|
|
68
|
+
|
|
69
|
+
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
70
|
+
new KIRunFunctionRepository,
|
|
71
|
+
new KIRunSchemaRepository
|
|
72
|
+
).setArguments(
|
|
73
|
+
new Map([
|
|
74
|
+
['minValue', min],
|
|
75
|
+
['maxValue', max],
|
|
76
|
+
]),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
let num: number = (await rand.execute(fep)).allResults()[0].getResult().get('value');
|
|
80
|
+
|
|
81
|
+
expect(num).toBeLessThanOrEqual(max);
|
|
82
|
+
expect(num).toBeGreaterThanOrEqual(min);
|
|
83
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Schema } from "../../../../../src/engine/json/schema/Schema";
|
|
2
|
+
import { SchemaType } from "../../../../../src/engine/json/schema/type/SchemaType";
|
|
3
|
+
import { TypeUtil } from "../../../../../src/engine/json/schema/type/TypeUtil";
|
|
4
|
+
import { AnyOfAllOfOneOfValidator } from "../../../../../src/engine/json/schema/validator/AnyOfAllOfOneOfValidator";
|
|
5
|
+
import { KIRunSchemaRepository } from "../../../../../src/engine/repository/KIRunSchemaRepository";
|
|
6
|
+
|
|
7
|
+
const repo = new KIRunSchemaRepository();
|
|
8
|
+
|
|
9
|
+
test("Any Of All Of One Validator Test 1", () => {
|
|
10
|
+
let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.INTEGER));
|
|
11
|
+
|
|
12
|
+
expect(AnyOfAllOfOneOfValidator.validate([], schema, repo, 10)).toBe(10);
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test("Any Of All Of One Validator Test 2", () => {
|
|
16
|
+
let arraySchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.ARRAY));
|
|
17
|
+
|
|
18
|
+
expect(AnyOfAllOfOneOfValidator.validate([], arraySchema, repo, [1, 2, 3])).toStrictEqual([1, 2, 3]);
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test("Any Of All Of One Validator Test 3", () => {
|
|
22
|
+
let objSchema: Schema = Schema.ofObject("testObj").setProperties(new Map<string, Schema>([['key', Schema.ofString('key')]]));
|
|
23
|
+
|
|
24
|
+
expect(AnyOfAllOfOneOfValidator.validate([], objSchema, repo, { "key": "value" })).toStrictEqual({ "key": "value" });
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("Any Of All Of One Validator Test 3", () => {
|
|
28
|
+
let nullSchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.NULL));
|
|
29
|
+
|
|
30
|
+
expect(AnyOfAllOfOneOfValidator.validate([], nullSchema, repo, null)).toBe(null);
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test("Any Of All Of One Validator Test 3", () => {
|
|
34
|
+
let nullSchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.BOOLEAN));
|
|
35
|
+
|
|
36
|
+
expect(AnyOfAllOfOneOfValidator.validate([], nullSchema, repo, null)).toBe(null);
|
|
37
|
+
})
|
|
38
|
+
|
|
@@ -53,3 +53,41 @@ test('Schema Validator Test 2', () => {
|
|
|
53
53
|
|
|
54
54
|
expect(SchemaValidator.validate(undefined, Schema.ofRef('Test.Location'), repo, obj)).toBe(obj);
|
|
55
55
|
});
|
|
56
|
+
|
|
57
|
+
test('Schema Validator Test 3', () => {
|
|
58
|
+
const obj = { url: 'http://xxxx.com' };
|
|
59
|
+
|
|
60
|
+
const locationSchema = Schema.from({
|
|
61
|
+
name: 'Location',
|
|
62
|
+
namespace: 'Test',
|
|
63
|
+
type: 'Object',
|
|
64
|
+
properties: {
|
|
65
|
+
url: { name: 'url', type: 'String' },
|
|
66
|
+
},
|
|
67
|
+
required: ['url'],
|
|
68
|
+
defaultValue: obj,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const repo = new HybridRepository<Schema>(
|
|
72
|
+
{
|
|
73
|
+
find(namespace, name): Schema | undefined {
|
|
74
|
+
if (namespace === 'Test' && name === 'Location') {
|
|
75
|
+
return locationSchema;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
new KIRunSchemaRepository(),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const obj1 = { url: 'http://yyyy.com' };
|
|
84
|
+
|
|
85
|
+
expect(
|
|
86
|
+
SchemaValidator.validate(
|
|
87
|
+
undefined,
|
|
88
|
+
Schema.ofRef('Test.Location').setDefaultValue(obj1),
|
|
89
|
+
repo,
|
|
90
|
+
undefined,
|
|
91
|
+
),
|
|
92
|
+
).toMatchObject(obj1);
|
|
93
|
+
});
|