2022-08-29 03:46:52 +00:00
|
|
|
import { run, SqValueTag } from "../../src/js";
|
|
|
|
export { SqValueTag };
|
2022-04-20 03:42:24 +00:00
|
|
|
|
2022-08-27 17:46:43 +00:00
|
|
|
export function testRun(x: string) {
|
|
|
|
const { result, bindings } = run(x); // FIXME - set environment
|
|
|
|
// x,
|
|
|
|
// bindings,
|
|
|
|
// {
|
|
|
|
// sampleCount: 1000,
|
|
|
|
// xyPointLength: 100,
|
|
|
|
// },
|
|
|
|
// imports
|
|
|
|
// );
|
2022-04-20 22:48:04 +00:00
|
|
|
|
2022-08-27 17:46:43 +00:00
|
|
|
if (result.tag === "Ok") {
|
|
|
|
return result.value;
|
2022-04-29 14:10:41 +00:00
|
|
|
} else {
|
|
|
|
throw new Error(
|
2022-08-27 17:46:43 +00:00
|
|
|
`Expected squiggle expression to evaluate but got error: ${result.value}`
|
2022-04-29 14:10:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-20 04:50:46 +00:00
|
|
|
/**
|
|
|
|
* This appears also in `TestHelpers.res`. According to https://www.math.net/percent-error, it computes
|
|
|
|
* absolute error when numerical stability concerns make me not want to compute relative error.
|
|
|
|
* */
|
|
|
|
export function expectErrorToBeBounded(
|
|
|
|
received: number,
|
|
|
|
expected: number,
|
|
|
|
epsilon: number,
|
|
|
|
digits: number
|
|
|
|
) {
|
|
|
|
let distance = Math.abs(received - expected);
|
|
|
|
let expectedAbs = Math.abs(expected);
|
|
|
|
let normalizingDenom = Math.max(expectedAbs, 1);
|
|
|
|
let error = distance / normalizingDenom;
|
|
|
|
expect(Math.round(10 ** digits * error) / 10 ** digits).toBeLessThanOrEqual(
|
|
|
|
epsilon
|
|
|
|
);
|
2022-04-20 03:42:24 +00:00
|
|
|
}
|