squiggle/packages/squiggle-lang/__tests__/TS/Jstat_test.ts

28 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-04-20 22:48:04 +00:00
// import { errorValueToString } from "../../src/js/index";
import * as fc from "fast-check";
2022-04-20 03:42:24 +00:00
import { testRun } from "./TestHelpers";
2022-04-20 22:48:04 +00:00
describe("cumulative density function of a normal distribution", () => {
test("at 3 stdevs to the right of the mean is near 1", () => {
fc.assert(
2022-06-21 19:43:17 +00:00
fc.property(fc.double(), fc.double({ min: 1e-7 }), (mean, stdev) => {
2022-04-20 22:48:04 +00:00
let threeStdevsAboveMean = mean + 3 * stdev;
let squiggleString = `cdf(normal(${mean}, ${stdev}), ${threeStdevsAboveMean})`;
let squiggleResult = testRun(squiggleString);
2022-04-20 22:48:04 +00:00
expect(squiggleResult.value).toBeCloseTo(1);
})
);
});
2022-04-20 22:48:04 +00:00
test("at 3 stdevs to the left of the mean is near 0", () => {
fc.assert(
2022-06-21 19:43:17 +00:00
fc.property(fc.double(), fc.double({ min: 1e-7 }), (mean, stdev) => {
2022-04-20 22:48:04 +00:00
let threeStdevsBelowMean = mean - 3 * stdev;
let squiggleString = `cdf(normal(${mean}, ${stdev}), ${threeStdevsBelowMean})`;
let squiggleResult = testRun(squiggleString);
2022-04-20 22:48:04 +00:00
expect(squiggleResult.value).toBeCloseTo(0);
})
);
});
});