squiggle/packages/squiggle-lang/__tests__/TS/Jstat_test.ts
Quinn Dougherty 36f929b726 Tackled infinite loop by changing float64Array generator to
`float32Array` generator; gave up on avoiding `any` type in
`Jstat_test.ts`
2022-04-19 20:52:53 -04:00

59 lines
1.8 KiB
TypeScript

import {
run,
Distribution,
squiggleExpression,
errorValueToString,
errorValue,
result,
} from "../../src/js/index";
import * as fc from "fast-check";
let testRun = (x: string): any => {
//result<squiggleExpression, errorValue> => {
return run(x, { sampleCount: 1000, xyPointLength: 100 });
};
let failDefault = () => expect("codepath should never").toBe("be reached");
describe("Jstat: cumulative density function", () => {
test("of a normal distribution at 3 stdevs to the right of the mean is within epsilon of 1", () => {
fc.assert(
fc.property(fc.float(), fc.float({ min: 1e-7 }), (mean, stdev) => {
let squiggleString = `cdf(normal(${mean}, ${stdev}), ${
mean + 3 * stdev
})`;
let squiggleResult = testRun(squiggleString);
let epsilon = 5e-3;
switch (squiggleResult.tag) {
case "Error":
expect(errorValueToString(squiggleResult.value)).toEqual(
"<Test cases don't seem to be finding this>"
);
case "Ok":
expect(squiggleResult.value.value).toBeGreaterThan(1 - epsilon);
}
})
);
});
test("of a normal distribution at 3 stdevs to the left of the mean is within epsilon of 0", () => {
fc.assert(
fc.property(fc.float(), fc.float({ min: 1e-7 }), (mean, stdev) => {
let squiggleString = `cdf(normal(${mean}, ${stdev}), ${
mean - 3 * stdev
})`;
let squiggleResult = testRun(squiggleString);
let epsilon = 5e-3;
switch (squiggleResult.tag) {
case "Error":
expect(errorValueToString(squiggleResult.value)).toEqual(
"<Test cases don't seem to be finding this>"
);
case "Ok":
expect(squiggleResult.value.value).toBeLessThan(epsilon);
}
})
);
});
});