Step 6 - test
This commit is contained in:
parent
7ed722047f
commit
da15a2b2a5
|
@ -1,12 +1,35 @@
|
|||
open Jest;
|
||||
open Expect;
|
||||
|
||||
exception ShapeWrong(string);
|
||||
describe("CDF", () => {
|
||||
module CDF =
|
||||
CDFunctor.Make({
|
||||
let shape: DistributionTypes.xyShape =
|
||||
CDFunctor.order({xs: [|1., 4., 8.|], ys: [|8., 9., 2.|]});
|
||||
});
|
||||
test("raise - w/o order", () => {
|
||||
expect(() => {
|
||||
module CDF =
|
||||
CDFunctor.Make({
|
||||
let shape: DistributionTypes.xyShape = {
|
||||
xs: [|10., 4., 8.|],
|
||||
ys: [|8., 9., 2.|],
|
||||
};
|
||||
});
|
||||
();
|
||||
})
|
||||
|> toThrow
|
||||
});
|
||||
test("raise - with order", () => {
|
||||
expect(() => {
|
||||
module CDF =
|
||||
CDFunctor.Make({
|
||||
let shape: DistributionTypes.xyShape = {
|
||||
xs: [|1., 4., 8.|],
|
||||
ys: [|8., 9., 2.|],
|
||||
};
|
||||
});
|
||||
();
|
||||
})
|
||||
|> not_
|
||||
|> toThrow
|
||||
});
|
||||
test("order#1", () => {
|
||||
let a = CDFunctor.order({xs: [|1., 4., 8.|], ys: [|8., 9., 2.|]});
|
||||
let b: DistributionTypes.xyShape = {
|
||||
|
|
|
@ -23,4 +23,9 @@ module Make = (Config: Config) => {
|
|||
if (!validateSize()) {
|
||||
raise(ShapeWrong("Arrays of \"xs\" and \"ys\" have different sizes."));
|
||||
};
|
||||
if (!Belt.SortArray.isSorted(Config.shape.xs, (a, b) => a > b ? 1 : (-1))) {
|
||||
raise(ShapeWrong("Arrays of \"xs\" and \"ys\" have different sizes."));
|
||||
};
|
||||
|
||||
1;
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@ const { interpolate, range, min, max } = require('./functions');
|
|||
|
||||
class ContinuousDistribution {
|
||||
/**
|
||||
* @Done
|
||||
* @param {number[]} xs
|
||||
* @param {number[]} ys
|
||||
*/
|
||||
|
@ -20,6 +21,7 @@ class ContinuousDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* @Done
|
||||
* Order them to make sure that xs are increasing
|
||||
* @param {number[]} xs
|
||||
* @param {number[]} ys
|
||||
|
|
Loading…
Reference in New Issue
Block a user