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