FindY tests (2)

This commit is contained in:
Roman Galochkin 2020-02-25 11:57:14 +03:00
parent 80a52a2a7b
commit 94a9712788
2 changed files with 30 additions and 20 deletions

View File

@ -40,32 +40,42 @@ describe("CDF", () => {
let b: DistTypes.xyShape = {xs: [|5., 10., 12.|], ys: [|9., 8., 2.|]};
expect(a) |> toEqual(b);
});
test("minX", () => {
describe("minX - maxX", () => {
module Dist =
CDF.Make({
let shape = CDF.order({xs: [|20., 4., 8.|], ys: [|8., 9., 2.|]});
});
expect(Dist.minX()) |> toEqual(4.);
test("minX", () => {
expect(Dist.minX()) |> toEqual(4.)
});
test("maxX", () => {
expect(Dist.maxX()) |> toEqual(20.)
});
});
describe("findY", () => {
module Dist =
CDF.Make({
let shape = CDF.order({xs: [|20., 4., 8.|], ys: [|8., 9., 2.|]});
});
expect(Dist.maxX()) |> toEqual(20.);
let shape = CDF.order({xs: [|1., 2., 3.|], ys: [|5., 6., 7.|]});
});
test("findY#1", () => {
module Dist =
CDF.Make({
let shape = CDF.order({xs: [|1., 2., 3.|], ys: [|5., 6., 7.|]});
});
expect(Dist.findY(1.)) |> toEqual(5.);
expect(Dist.findY(1.)) |> toEqual(5.)
});
test("findY#2", () => {
module Dist =
CDF.Make({
let shape = CDF.order({xs: [|1., 2., 3.|], ys: [|5., 6., 7.|]});
expect(Dist.findY(1.5)) |> toEqual(5.5)
});
test("findY#3", () => {
expect(Dist.findY(3.)) |> toEqual(7.)
});
test("findY#4", () => {
expect(Dist.findY(4.)) |> toEqual(7.)
});
test("findY#5", () => {
expect(Dist.findY(15.)) |> toEqual(7.)
});
test("findY#6", () => {
expect(Dist.findY(-1.)) |> toEqual(5.)
});
expect(Dist.findY(1.5)) |> toEqual(5.5);
});
});

View File

@ -38,7 +38,7 @@ module Make = (Config: Config) => {
let firstHigherIndex = Belt.Array.getIndexBy(xs, e => e >= x);
switch (firstHigherIndex) {
| None => maxY()
| Some(1) => minY()
| Some(0) => minY()
| Some(firstHigherIndex) =>
let lowerOrEqualIndex =
firstHigherIndex - 1 < 0 ? 0 : firstHigherIndex - 1;
@ -60,7 +60,7 @@ module Make = (Config: Config) => {
let firstHigherIndex = Belt.Array.getIndexBy(ys, e => e >= y);
switch (firstHigherIndex) {
| None => maxX()
| Some(1) => minX()
| Some(0) => minX()
| Some(firstHigherIndex) =>
let lowerOrEqualIndex =
firstHigherIndex - 1 < 0 ? 0 : firstHigherIndex - 1;