Step 6 - test

This commit is contained in:
Roman Galochkin 2020-02-21 16:39:55 +03:00
parent 7ed722047f
commit da15a2b2a5
3 changed files with 35 additions and 5 deletions

View File

@ -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 = {

View File

@ -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;
};

View File

@ -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