Fix inv tests always checking 0
This commit is contained in:
parent
93c06f85b0
commit
787d4135c7
|
@ -1,4 +1,4 @@
|
||||||
import { distributions, generateFloat, generateFloatRange } from "./generators";
|
import { distributions, generateInt, generateFloatRange } from "./generators";
|
||||||
import { test, expectEqual } from "./lib";
|
import { test, expectEqual } from "./lib";
|
||||||
|
|
||||||
let checkDistributionSame = (
|
let checkDistributionSame = (
|
||||||
|
@ -21,7 +21,7 @@ Object.entries(distributions).map(([key, generator]) => {
|
||||||
checkDistributionSame(distribution, (d: string) => `mean(${d})`));
|
checkDistributionSame(distribution, (d: string) => `mean(${d})`));
|
||||||
|
|
||||||
test(`cdf is the same for ${key} distribution under all distribution types`, () => {
|
test(`cdf is the same for ${key} distribution under all distribution types`, () => {
|
||||||
let cdf_value = generateFloat();
|
let cdf_value = generateInt();
|
||||||
checkDistributionSame(
|
checkDistributionSame(
|
||||||
distribution,
|
distribution,
|
||||||
(d: string) => `cdf(${d}, ${cdf_value})`
|
(d: string) => `cdf(${d}, ${cdf_value})`
|
||||||
|
@ -29,7 +29,7 @@ Object.entries(distributions).map(([key, generator]) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test(`pdf is the same for ${key} distribution under all distribution types`, () => {
|
test(`pdf is the same for ${key} distribution under all distribution types`, () => {
|
||||||
let pdf_value = generateFloat();
|
let pdf_value = generateInt();
|
||||||
checkDistributionSame(
|
checkDistributionSame(
|
||||||
distribution,
|
distribution,
|
||||||
(d: string) => `pdf(${d}, ${pdf_value})`
|
(d: string) => `pdf(${d}, ${pdf_value})`
|
||||||
|
|
|
@ -1,38 +1,39 @@
|
||||||
export let generateFloatRange = (min: number, max: number): number =>
|
export let generateFloatRange = (min: number, max: number): number =>
|
||||||
Math.floor(Math.random() * (max - min) + min);
|
Math.random() * (max - min) + min;
|
||||||
|
export let generateIntRange = (min: number, max: number): number =>
|
||||||
|
Math.floor(generateFloatRange(min, max));
|
||||||
|
|
||||||
export let generateFloatMin = (min: number): number =>
|
export let generateIntMin = (min: number): number => generateIntRange(min, 100);
|
||||||
generateFloatRange(min, 100);
|
|
||||||
|
|
||||||
export let generateFloat = (): number => generateFloatMin(-100);
|
export let generateInt = (): number => generateIntMin(-100);
|
||||||
|
|
||||||
let generatePositive = (): number => generateFloatMin(1);
|
let generatePositiveInt = (): number => generateIntMin(1);
|
||||||
|
|
||||||
export let generateNormal = (): string =>
|
export let generateNormal = (): string =>
|
||||||
`normal(${generateFloat()}, ${generatePositive()})`;
|
`normal(${generateInt()}, ${generatePositiveInt()})`;
|
||||||
|
|
||||||
export let generateBeta = (): string =>
|
export let generateBeta = (): string =>
|
||||||
`beta(${generatePositive()}, ${generatePositive()})`;
|
`beta(${generatePositiveInt()}, ${generatePositiveInt()})`;
|
||||||
|
|
||||||
export let generateLognormal = (): string =>
|
export let generateLognormal = (): string =>
|
||||||
`lognormal(${generateFloat()}, ${generatePositive()})`;
|
`lognormal(${generateInt()}, ${generatePositiveInt()})`;
|
||||||
|
|
||||||
export let generateExponential = (): string =>
|
export let generateExponential = (): string =>
|
||||||
`exponential(${generatePositive()})`;
|
`exponential(${generatePositiveInt()})`;
|
||||||
|
|
||||||
export let generateUniform = (): string => {
|
export let generateUniform = (): string => {
|
||||||
let a = generateFloat();
|
let a = generateInt();
|
||||||
let b = generateFloatMin(a + 1);
|
let b = generateIntMin(a + 1);
|
||||||
return `uniform(${a}, ${b})`;
|
return `uniform(${a}, ${b})`;
|
||||||
};
|
};
|
||||||
export let generateCauchy = (): string => {
|
export let generateCauchy = (): string => {
|
||||||
return `cauchy(${generateFloat()}, ${generatePositive()})`;
|
return `cauchy(${generateInt()}, ${generatePositiveInt()})`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let generateTriangular = (): string => {
|
export let generateTriangular = (): string => {
|
||||||
let a = generateFloat();
|
let a = generateInt();
|
||||||
let b = generateFloatMin(a + 1);
|
let b = generateIntMin(a + 1);
|
||||||
let c = generateFloatMin(b + 1);
|
let c = generateIntMin(b + 1);
|
||||||
return `triangular(${a}, ${b}, ${c})`;
|
return `triangular(${a}, ${b}, ${c})`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user