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

Function expectApprox

test/compute-engine/special-functions.test.ts:9–23  ·  view source on GitHub ↗
(
  expr: any,
  expected: number,
  tolerance = 1e-10
)

Source from the content-addressed store, hash-verified

7
8// Helper: check numeric approximation within tolerance
9function expectApprox(
10 expr: any,
11 expected: number,
12 tolerance = 1e-10
13) {
14 const result = expr.N();
15 const val = result.re;
16 if (!isFinite(expected)) {
17 expect(val).toBe(expected);
18 } else {
19 expect(Math.abs(val - expected)).toBeLessThan(
20 Math.abs(expected) * tolerance + tolerance
21 );
22 }
23}
24
25describe('DIGAMMA FUNCTION', () => {
26 test('ψ(1) = -γ (Euler-Mascheroni constant)', () => {

Callers 1

Calls 3

isFiniteFunction · 0.85
NMethod · 0.65
absMethod · 0.65

Tested by

no test coverage detected