2022-04-20 00:52:53 +00:00
|
|
|
import * as fc from "fast-check";
|
2022-04-20 03:42:24 +00:00
|
|
|
import { testRun } from "./TestHelpers";
|
2022-04-20 00:52:53 +00:00
|
|
|
|
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", () => {
|
2022-04-20 00:52:53 +00:00
|
|
|
fc.assert(
|
2022-06-22 21:51:14 +00:00
|
|
|
fc.property(fc.integer(), fc.integer({ min: 1 }), (mean, stdev) => {
|
2022-04-20 22:48:04 +00:00
|
|
|
let threeStdevsAboveMean = mean + 3 * stdev;
|
|
|
|
let squiggleString = `cdf(normal(${mean}, ${stdev}), ${threeStdevsAboveMean})`;
|
2022-04-20 00:52:53 +00:00
|
|
|
let squiggleResult = testRun(squiggleString);
|
2022-04-20 22:48:04 +00:00
|
|
|
expect(squiggleResult.value).toBeCloseTo(1);
|
2022-04-20 00:52:53 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-04-20 22:48:04 +00:00
|
|
|
test("at 3 stdevs to the left of the mean is near 0", () => {
|
2022-04-20 00:52:53 +00:00
|
|
|
fc.assert(
|
2022-06-22 21:51:14 +00:00
|
|
|
fc.property(fc.integer(), fc.integer({ min: 1 }), (mean, stdev) => {
|
2022-04-20 22:48:04 +00:00
|
|
|
let threeStdevsBelowMean = mean - 3 * stdev;
|
|
|
|
let squiggleString = `cdf(normal(${mean}, ${stdev}), ${threeStdevsBelowMean})`;
|
2022-04-20 00:52:53 +00:00
|
|
|
let squiggleResult = testRun(squiggleString);
|
2022-04-20 22:48:04 +00:00
|
|
|
expect(squiggleResult.value).toBeCloseTo(0);
|
2022-04-20 00:52:53 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|