squiggle/__tests__/CDF__Test.re

147 lines
3.4 KiB
ReasonML
Raw Normal View History

2020-02-21 13:17:32 +00:00
open Jest;
open Expect;
2020-02-21 13:39:55 +00:00
exception ShapeWrong(string);
2020-02-21 13:17:32 +00:00
describe("CDF", () => {
2020-02-21 13:39:55 +00:00
test("raise - w/o order", () => {
expect(() => {
2020-02-25 08:39:42 +00:00
module Cdf =
CDF.Make({
2020-02-25 05:20:11 +00:00
let shape: DistTypes.xyShape = {
2020-02-21 13:39:55 +00:00
xs: [|10., 4., 8.|],
ys: [|8., 9., 2.|],
};
});
();
})
|> toThrow
});
test("raise - with order", () => {
expect(() => {
2020-02-25 08:39:42 +00:00
module Cdf =
CDF.Make({
2020-02-25 05:20:11 +00:00
let shape: DistTypes.xyShape = {
2020-02-21 13:39:55 +00:00
xs: [|1., 4., 8.|],
ys: [|8., 9., 2.|],
};
});
();
})
|> not_
|> toThrow
});
2020-02-21 13:21:43 +00:00
test("order#1", () => {
2020-02-25 08:39:42 +00:00
let a = CDF.order({xs: [|1., 4., 8.|], ys: [|8., 9., 2.|]});
2020-02-25 05:20:11 +00:00
let b: DistTypes.xyShape = {xs: [|1., 4., 8.|], ys: [|8., 9., 2.|]};
2020-02-21 13:21:43 +00:00
expect(a) |> toEqual(b);
});
test("order#2", () => {
2020-02-25 08:39:42 +00:00
let a = CDF.order({xs: [|10., 5., 12.|], ys: [|8., 9., 2.|]});
2020-02-25 05:20:11 +00:00
let b: DistTypes.xyShape = {xs: [|5., 10., 12.|], ys: [|9., 8., 2.|]};
2020-02-21 13:21:43 +00:00
expect(a) |> toEqual(b);
2020-02-21 13:17:32 +00:00
});
2020-02-25 08:57:14 +00:00
describe("minX - maxX", () => {
2020-02-25 08:39:42 +00:00
module Dist =
CDF.Make({
let shape = CDF.order({xs: [|20., 4., 8.|], ys: [|8., 9., 2.|]});
2020-02-21 13:50:23 +00:00
});
2020-02-25 08:57:14 +00:00
test("minX", () => {
expect(Dist.minX()) |> toEqual(4.)
});
test("maxX", () => {
expect(Dist.maxX()) |> toEqual(20.)
});
2020-02-21 13:50:23 +00:00
});
2020-02-25 08:57:14 +00:00
describe("findY", () => {
2020-02-25 08:45:44 +00:00
module Dist =
CDF.Make({
let shape = CDF.order({xs: [|1., 2., 3.|], ys: [|5., 6., 7.|]});
});
2020-02-25 09:04:26 +00:00
test("#1", () => {
2020-02-25 08:57:14 +00:00
expect(Dist.findY(1.)) |> toEqual(5.)
});
2020-02-25 09:04:26 +00:00
test("#2", () => {
2020-02-25 08:57:14 +00:00
expect(Dist.findY(1.5)) |> toEqual(5.5)
});
2020-02-25 09:04:26 +00:00
test("#3", () => {
2020-02-25 08:57:14 +00:00
expect(Dist.findY(3.)) |> toEqual(7.)
});
2020-02-25 09:04:26 +00:00
test("#4", () => {
2020-02-25 08:57:14 +00:00
expect(Dist.findY(4.)) |> toEqual(7.)
});
2020-02-25 09:04:26 +00:00
test("#5", () => {
2020-02-25 08:57:14 +00:00
expect(Dist.findY(15.)) |> toEqual(7.)
});
2020-02-25 09:04:26 +00:00
test("#6", () => {
2020-02-25 08:57:14 +00:00
expect(Dist.findY(-1.)) |> toEqual(5.)
});
2020-02-25 08:45:44 +00:00
});
2020-02-25 09:04:26 +00:00
describe("findX", () => {
module Dist =
CDF.Make({
let shape = CDF.order({xs: [|1., 2., 3.|], ys: [|5., 6., 7.|]});
});
test("#1", () => {
expect(Dist.findX(5.)) |> toEqual(1.)
});
test("#2", () => {
expect(Dist.findX(7.)) |> toEqual(3.)
});
test("#3", () => {
expect(Dist.findX(5.5)) |> toEqual(1.5)
});
test("#4", () => {
expect(Dist.findX(8.)) |> toEqual(3.)
});
test("#5", () => {
expect(Dist.findX(4.)) |> toEqual(1.)
});
});
2020-02-25 09:45:41 +00:00
describe("convertWithAlternativeXs", () => {
open Functions;
let xs = up(1, 9);
let ys = up(20, 28);
module Dist =
CDF.Make({
let shape = CDF.order({xs, ys});
});
let xs2 = up(3, 7);
module Dist2 =
CDF.Make({
let shape = Dist.convertWithAlternativeXs(xs2);
});
test("#1", () => {
expect(Dist2.xs) |> toEqual([|3., 4., 5., 6., 7.|])
});
test("#2", () => {
expect(Dist2.ys) |> toEqual([|22., 23., 24., 25., 26.|])
});
});
describe("convertToNewLength", () => {
open Functions;
let xs = up(1, 9);
let ys = up(50, 58);
module Dist =
CDF.Make({
let shape = CDF.order({xs, ys});
});
module Dist2 =
CDF.Make({
let shape = Dist.convertToNewLength(3);
});
test("#1", () => {
expect(Dist2.xs) |> toEqual([|1., 5., 9.|])
});
test("#2", () => {
expect(Dist2.ys) |> toEqual([|50., 54., 58.|])
});
});
2020-02-21 13:17:32 +00:00
});