time-to-botec/squiggle/node_modules/@quri/squiggle-lang/benchmark/conversion_tests.ts
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

47 lines
1.3 KiB
TypeScript

import { distributions, generateInt, generateFloatRange } from "./generators";
import { test, expectEqual } from "./lib";
let checkDistributionSame = (
distribution: string,
operation: (arg: string) => string
): void => {
expectEqual(
operation(distribution),
operation(`toPointSet(${distribution})`)
);
expectEqual(
operation(distribution),
operation(`toSampleSet(${distribution})`)
);
};
Object.entries(distributions).map(([key, generator]) => {
let distribution = generator();
test(`mean is the same for ${key} distribution under all distribution types`, () =>
checkDistributionSame(distribution, (d: string) => `mean(${d})`));
test(`cdf is the same for ${key} distribution under all distribution types`, () => {
let cdf_value = generateInt();
checkDistributionSame(
distribution,
(d: string) => `cdf(${d}, ${cdf_value})`
);
});
test(`pdf is the same for ${key} distribution under all distribution types`, () => {
let pdf_value = generateInt();
checkDistributionSame(
distribution,
(d: string) => `pdf(${d}, ${pdf_value})`
);
});
test(`inv is the same for ${key} distribution under all distribution types`, () => {
let inv_value = generateFloatRange(0, 1);
checkDistributionSame(
distribution,
(d: string) => `inv(${d}, ${inv_value})`
);
});
});