squiggle/__tests__/Foo/Foo__Test.re

94 lines
2.3 KiB
ReasonML
Raw Normal View History

2020-02-18 15:50:36 +00:00
open Jest;
open Expect;
2020-02-23 13:27:52 +00:00
let shape: DistTypes.xyShape = {xs: [|1., 4., 8.|], ys: [|8., 9., 2.|]};
2020-02-18 15:50:36 +00:00
2020-02-23 18:59:04 +00:00
let makeTest = (str, item1, item2) =>
test(str, () =>
expect(item1) |> toEqual(item2)
);
2020-02-18 15:50:36 +00:00
2020-02-23 18:59:04 +00:00
describe("Shape", () => {
describe("Continuous", () => {
open Distributions.Continuous;
let continuous = make(shape, `Stepwise);
makeTest("minX", T.minX(continuous), Some(1.0));
makeTest("maxX", T.maxX(continuous), Some(8.0));
makeTest(
"pointwiseFmap",
T.pointwiseFmap(r => r *. 2.0, continuous) |> getShape |> (r => r.ys),
[|16., 18.0, 4.0|],
);
makeTest(
"xToY at 4.0",
T.xToY(4., continuous),
{continuous: 9.0, discrete: 0.0},
);
makeTest(
"xToY at 0.0",
T.xToY(0., continuous),
{continuous: 8.0, discrete: 0.0},
);
makeTest(
"xToY at 5.0",
T.xToY(5., continuous),
{continuous: 7.25, discrete: 0.0},
);
makeTest(
"integral",
T.Integral.get(~cache=None, continuous) |> getShape,
{xs: [|4.0, 8.0|], ys: [|25.5, 47.5|]},
);
makeTest(
"integralXToY",
T.Integral.xToY(~cache=None, 2.0, continuous),
25.5,
);
makeTest("integralSum", T.Integral.sum(~cache=None, continuous), 73.0);
});
describe("Discrete", () => {
open Distributions.Discrete;
2020-02-23 19:40:38 +00:00
let shape: DistTypes.xyShape = {
xs: [|1., 4., 8.|],
ys: [|0.3, 0.5, 0.2|],
};
2020-02-23 18:59:04 +00:00
let discrete = shape;
makeTest("minX", T.minX(discrete), Some(1.0));
makeTest("maxX", T.maxX(discrete), Some(8.0));
makeTest(
"pointwiseFmap",
T.pointwiseFmap(r => r *. 2.0, discrete) |> (r => r.ys),
2020-02-23 19:40:38 +00:00
[|0.6, 1.0, 0.4|],
2020-02-23 18:59:04 +00:00
);
makeTest(
"xToY at 4.0",
T.xToY(4., discrete),
2020-02-23 19:40:38 +00:00
{discrete: 0.5, continuous: 0.0},
2020-02-23 18:59:04 +00:00
);
makeTest(
"xToY at 0.0",
T.xToY(0., discrete),
2020-02-23 19:40:38 +00:00
{discrete: 0.0, continuous: 0.0},
2020-02-23 18:59:04 +00:00
);
makeTest(
"xToY at 5.0",
T.xToY(5., discrete),
2020-02-23 19:40:38 +00:00
{discrete: 0.0, continuous: 0.0},
);
makeTest(
"integral",
T.Integral.get(~cache=None, discrete),
Distributions.Continuous.make(
{xs: [|1., 4., 8.|], ys: [|0.3, 0.8, 1.0|]},
`Stepwise,
),
2020-02-23 18:59:04 +00:00
);
makeTest(
"integralXToY",
2020-02-23 19:40:38 +00:00
T.Integral.xToY(~cache=None, 6.0, discrete),
0.9,
2020-02-23 18:59:04 +00:00
);
2020-02-23 19:40:38 +00:00
makeTest("integralSum", T.Integral.sum(~cache=None, discrete), 1.0);
2020-02-23 18:59:04 +00:00
});
});