forked from MishaKanai/ts-spel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduction-test-exact.js
More file actions
116 lines (106 loc) · 3.07 KB
/
production-test-exact.js
File metadata and controls
116 lines (106 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Test the exact failing syntax from production
const { parse, getEvaluator } = require('./lib/index.js');
console.log("=== PRODUCTION EXACT SYNTAX TEST ===\n");
// Test with no custom functions - just built-in MIN
const context = {
PayScalePayComponentList: [
{ PayScaleLevel_code: 'AUT/WEN/AUT/07/15', amount: 4000 },
{ PayScaleLevel_code: 'AUT/WEN/AUT/07/11', amount: 3500 },
],
EmpJob: { payScaleLevel: 'AUT/WEN/AUT/07/11' },
FOCompany: { standardHours: 40 },
maxAmount: 4000,
};
// Create evaluator with exact production settings
const evaluator = getEvaluator(context, {}, {
disableNullPointerExceptions: true,
fallbackToFunctions: true,
});
console.log("TESTING EXACT FAILING CASES:");
console.log("============================");
const testCases = [
{
name: "Simple 2-argument MIN",
formula: "MIN(3500, 4000)",
expected: 3500
},
{
name: "Simple 3-argument MIN",
formula: "MIN(3500, 4000, 2800)",
expected: 2800
},
{
name: "MIN with variables",
formula: "MIN(maxAmount, 3500)",
expected: 3500
},
{
name: "MAX function test",
formula: "MAX(3500, 4000)",
expected: 4000
},
{
name: "DOUBLE function test",
formula: "DOUBLE('3500.5')",
expected: 3500.5
},
{
name: "ABS function test",
formula: "ABS(-1234)",
expected: 1234
},
{
name: "ROUND function test",
formula: "ROUND(3.7)",
expected: 4
},
{
name: "FLOOR function test",
formula: "FLOOR(3.7)",
expected: 3
},
{
name: "CEIL function test",
formula: "CEIL(3.2)",
expected: 4
},
{
name: "Complex production-like formula",
formula: "MIN(DOUBLE(maxAmount), DOUBLE('3500')) * 12 / 52 / DOUBLE(FOCompany.standardHours)",
expected: "calculated value"
}
];
testCases.forEach(test => {
try {
console.log(`Testing: ${test.name}`);
console.log(`Formula: ${test.formula}`);
const ast = parse(test.formula);
const result = evaluator(ast);
console.log(`✓ Result: ${result}`);
console.log(`✓ Expected: ${test.expected}`);
if (typeof test.expected === 'number' && Math.abs(result - test.expected) < 0.0001) {
console.log("✅ PASS\n");
} else if (test.expected === "calculated value") {
console.log("✅ CALCULATED\n");
} else {
console.log("❌ MISMATCH\n");
}
} catch (error) {
console.log(`✗ Error: ${error.message}`);
console.log("❌ FAIL\n");
}
});
console.log("TESTING EXACT PRODUCTION FORMULA:");
console.log("==================================");
// Test the exact production formula structure
const productionFormula = "MIN(DOUBLE(PayScalePayComponentList.^[PayScaleLevel_code == EmpJob.payScaleLevel].amount), DOUBLE(maxAmount)) * 12 / 52 / DOUBLE(FOCompany.standardHours)";
try {
console.log(`Production formula: ${productionFormula}`);
const ast = parse(productionFormula);
const result = evaluator(ast);
console.log(`✓ Result: ${result}`);
console.log("✅ PRODUCTION FORMULA WORKING!");
} catch (error) {
console.log(`✗ Error: ${error.message}`);
console.log("❌ PRODUCTION FORMULA FAILED");
}