Step 7 - test

This commit is contained in:
Roman Galochkin 2020-02-21 16:50:23 +03:00
parent da15a2b2a5
commit fc66ac0082
3 changed files with 24 additions and 2 deletions

View File

@ -46,4 +46,20 @@ describe("CDF", () => {
};
expect(a) |> toEqual(b);
});
test("minX", () => {
module CDF =
CDFunctor.Make({
let shape: DistributionTypes.xyShape =
CDFunctor.order({xs: [|20., 4., 8.|], ys: [|8., 9., 2.|]});
});
expect(CDF.minX()) |> toEqual(4.);
});
test("maxX", () => {
module CDF =
CDFunctor.Make({
let shape: DistributionTypes.xyShape =
CDFunctor.order({xs: [|20., 4., 8.|], ys: [|8., 9., 2.|]});
});
expect(CDF.maxX()) |> toEqual(20.);
});
});

View File

@ -5,7 +5,7 @@ exception ShapeWrong(string);
let order = (shape: DistributionTypes.xyShape): DistributionTypes.xyShape => {
let xy =
shape.xs
|> Array.mapi((i, x) => [x, shape.ys[i]])
|> Array.mapi((i, x) => [x, shape.ys |> Array.get(_, i)])
|> Belt.SortArray.stableSortBy(_, ([a, _], [b, _]) => a > b ? 1 : (-1));
{
xs: xy |> Array.map(([x, _]) => x),
@ -26,6 +26,8 @@ module Make = (Config: Config) => {
if (!Belt.SortArray.isSorted(Config.shape.xs, (a, b) => a > b ? 1 : (-1))) {
raise(ShapeWrong("Arrays of \"xs\" and \"ys\" have different sizes."));
};
let minX = () => Config.shape.xs |> Array.get(_, 0);
let maxX = () =>
Config.shape.xs |> Array.get(_, Array.length(Config.shape.xs) - 1);
1;
};

View File

@ -42,6 +42,7 @@ class ContinuousDistribution {
}
/**
* @Done
* @param {number[]} xs
* @param {number[]} ys
* @return {boolean}
@ -51,6 +52,7 @@ class ContinuousDistribution {
}
/**
* @Done
* @param xs
* @returns {boolean}
*/
@ -59,6 +61,7 @@ class ContinuousDistribution {
}
/**
* @Done
* @returns {number}
*/
minX() {
@ -66,6 +69,7 @@ class ContinuousDistribution {
}
/**
* @Done
* @returns {number}
*/
maxX() {