diff --git a/__tests__/CDFunctor__Test.re b/__tests__/CDFunctor__Test.re index 031b55fc..69e483e3 100644 --- a/__tests__/CDFunctor__Test.re +++ b/__tests__/CDFunctor__Test.re @@ -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.); + }); }); diff --git a/src/utility/lib/CDFunctor.re b/src/utility/lib/CDFunctor.re index 09848aaf..3db4f574 100644 --- a/src/utility/lib/CDFunctor.re +++ b/src/utility/lib/CDFunctor.re @@ -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; }; diff --git a/src/utility/lib/continuousDistribution.js b/src/utility/lib/continuousDistribution.js index 65f6e85d..a1eb3117 100644 --- a/src/utility/lib/continuousDistribution.js +++ b/src/utility/lib/continuousDistribution.js @@ -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() {