Step 7 - test
This commit is contained in:
parent
da15a2b2a5
commit
fc66ac0082
|
@ -46,4 +46,20 @@ describe("CDF", () => {
|
||||||
};
|
};
|
||||||
expect(a) |> toEqual(b);
|
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.);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ exception ShapeWrong(string);
|
||||||
let order = (shape: DistributionTypes.xyShape): DistributionTypes.xyShape => {
|
let order = (shape: DistributionTypes.xyShape): DistributionTypes.xyShape => {
|
||||||
let xy =
|
let xy =
|
||||||
shape.xs
|
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));
|
|> Belt.SortArray.stableSortBy(_, ([a, _], [b, _]) => a > b ? 1 : (-1));
|
||||||
{
|
{
|
||||||
xs: xy |> Array.map(([x, _]) => x),
|
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))) {
|
if (!Belt.SortArray.isSorted(Config.shape.xs, (a, b) => a > b ? 1 : (-1))) {
|
||||||
raise(ShapeWrong("Arrays of \"xs\" and \"ys\" have different sizes."));
|
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;
|
1;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,6 +42,7 @@ class ContinuousDistribution {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @Done
|
||||||
* @param {number[]} xs
|
* @param {number[]} xs
|
||||||
* @param {number[]} ys
|
* @param {number[]} ys
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
|
@ -51,6 +52,7 @@ class ContinuousDistribution {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @Done
|
||||||
* @param xs
|
* @param xs
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
|
@ -59,6 +61,7 @@ class ContinuousDistribution {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @Done
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
minX() {
|
minX() {
|
||||||
|
@ -66,6 +69,7 @@ class ContinuousDistribution {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @Done
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
maxX() {
|
maxX() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user