2022-04-26 20:05:16 +00:00
|
|
|
import { distributions, generateFloat, generateFloatRange } from "./generators";
|
2022-04-26 18:26:02 +00:00
|
|
|
import { test, expectEqual } from "./lib";
|
|
|
|
|
2022-04-26 20:38:17 +00:00
|
|
|
let checkDistributionSame = (
|
|
|
|
distribution: string,
|
|
|
|
operation: (arg: string) => string
|
|
|
|
): void => {
|
|
|
|
expectEqual(
|
|
|
|
operation(distribution),
|
|
|
|
operation(`toPointSet(${distribution})`)
|
|
|
|
);
|
|
|
|
expectEqual(
|
|
|
|
operation(distribution),
|
|
|
|
operation(`toSampleSet(${distribution})`)
|
|
|
|
);
|
|
|
|
};
|
2022-04-26 20:05:16 +00:00
|
|
|
|
|
|
|
Object.entries(distributions).map(([key, generator]) => {
|
|
|
|
let distribution = generator();
|
|
|
|
test(`mean is the same for ${key} distribution under all distribution types`, () =>
|
2022-04-26 20:38:17 +00:00
|
|
|
checkDistributionSame(distribution, (d: string) => `mean(${d})`));
|
2022-04-26 20:05:16 +00:00
|
|
|
|
|
|
|
test(`cdf is the same for ${key} distribution under all distribution types`, () => {
|
|
|
|
let cdf_value = generateFloat();
|
2022-04-26 20:38:17 +00:00
|
|
|
checkDistributionSame(
|
|
|
|
distribution,
|
|
|
|
(d: string) => `cdf(${d}, ${cdf_value})`
|
|
|
|
);
|
|
|
|
});
|
2022-04-26 20:05:16 +00:00
|
|
|
|
|
|
|
test(`pdf is the same for ${key} distribution under all distribution types`, () => {
|
|
|
|
let pdf_value = generateFloat();
|
2022-04-26 20:38:17 +00:00
|
|
|
checkDistributionSame(
|
|
|
|
distribution,
|
|
|
|
(d: string) => `pdf(${d}, ${pdf_value})`
|
|
|
|
);
|
|
|
|
});
|
2022-04-26 20:05:16 +00:00
|
|
|
|
|
|
|
test(`inv is the same for ${key} distribution under all distribution types`, () => {
|
|
|
|
let inv_value = generateFloatRange(0, 1);
|
2022-04-26 20:38:17 +00:00
|
|
|
checkDistributionSame(
|
|
|
|
distribution,
|
|
|
|
(d: string) => `inv(${d}, ${inv_value})`
|
|
|
|
);
|
|
|
|
});
|
2022-04-26 18:26:02 +00:00
|
|
|
});
|