MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / checkJson

Function checkJson

test/utils.ts:151–237  ·  view source on GitHub ↗
(
  inExpr: ExpressionInput | null,
  variants?: Array<ExprVariant>
)

Source from the content-addressed store, hash-verified

149 inExpr: ExpressionInput | null,
150 variants?: Array<ExprVariant>
151): string {
152 if (!inExpr) return 'null';
153 const ce =
154 inExpr instanceof _BoxedExpression
155 ? inExpr.engine
156 : engine; /* default test engine */
157 const precision = ce.precision;
158 try {
159 ce.precision = 'auto';
160
161 variants ??= [
162 'box',
163 'canonical',
164 'simplify',
165 'eval-auto',
166 'eval-mach',
167 'N-mach',
168 'N-auto',
169 ];
170
171 const boxed = exprToString(ce.expr(inExpr, { form: 'raw' }));
172
173 const expr = ce.expr(inExpr);
174
175 if (!expr.isValid) return `invalid =${exprToString(expr)}`;
176
177 const canonical = exprToString(expr);
178
179 const simplifyExpr = expr.simplify();
180 const simplify = simplifyExpr.toString();
181 const evalAuto = expr.evaluate().toString();
182 const numEvalAuto = expr.N().toString();
183
184 ce.precision = 'machine';
185 // Re-box at machine precision so internal NumericValue representations
186 // use MachineNumericValue, not BigNumericValue from the higher-precision parse
187 const machExpr = ce.expr(expr.json);
188 const evalMachine = machExpr.evaluate().toString();
189 const numEvalMachine = machExpr.N().toString();
190
191 if (
192 boxed === canonical &&
193 simplifyExpr.isSame(expr) &&
194 evalAuto === simplify &&
195 evalAuto === evalMachine &&
196 evalAuto === numEvalAuto &&
197 evalAuto === numEvalMachine
198 ) {
199 return boxed;
200 }
201
202 const result: string[] = [];
203 if (variants.includes('box')) result.push('box = ' + boxed);
204
205 if (canonical !== boxed && variants.includes('canonical'))
206 result.push('canonical = ' + canonical);
207
208 if (simplify !== expr.toString() && variants.includes('simplify'))

Callers 4

checkExpandFunction · 0.90
numeric.test.tsFile · 0.90
arithmetic.test.tsFile · 0.90
checkFunction · 0.85

Calls 7

exprToStringFunction · 0.85
exprMethod · 0.65
simplifyMethod · 0.65
toStringMethod · 0.65
evaluateMethod · 0.65
NMethod · 0.65
isSameMethod · 0.65

Tested by 1

checkExpandFunction · 0.72