Adds tests (5)

This commit is contained in:
Roman Galochkin 2020-02-25 10:59:01 +03:00
parent 822a803d01
commit 790791eab1
2 changed files with 21 additions and 2 deletions

View File

@ -69,4 +69,22 @@ describe("Functions", () => {
test("max#3", () => {
expect(Functions.max([|(-1.), (-2.), 0., (-2.2)|])) |> toEqual(0.)
});
test("random#1", () => {
expect(Functions.random(1, 5)) |> toBeLessThanOrEqual(5)
});
test("random#2", () => {
expect(Functions.random(1, 5)) |> toBeGreaterThanOrEqual(1)
});
test("up#1", () => {
expect(Functions.up(1, 5)) |> toEqual([|1, 2, 3, 4, 5|])
});
test("up#2", () => {
expect(Functions.up(-1, 5)) |> toEqual([|(-1), 0, 1, 2, 3, 4, 5|])
});
test("down#1", () => {
expect(Functions.down(5, 1)) |> toEqual([|5, 4, 3, 2, 1|])
});
test("down#2", () => {
expect(Functions.down(5, -1)) |> toEqual([|5, 4, 3, 2, 1, 0, (-1)|])
});
});

View File

@ -13,8 +13,9 @@ let sum = Belt.Array.reduce(_, 0., (i, j) => i +. j);
let mean = a => sum(a) /. (Array.length(a) |> float_of_int);
let min = a => Belt.Array.reduce(a, a[0], (i, j) => i < j ? i : j);
let max = a => Belt.Array.reduce(a, a[0], (i, j) => i > j ? i : j);
let up = (a, b) => Array.make(b - a, a) |> Array.mapi((i, c) => c + i);
let down = (a, b) => Array.make(a - b, a) |> Array.mapi((i, c) => c - i);
let up = (a, b) => Array.make(b - a + 1, a) |> Array.mapi((i, c) => c + i);
let down = (a, b) =>
Array.make(a - b + 1, a) |> Array.mapi((i, c) => c - i);
let range = (min: float, max: float, n: int): array(float) => {
switch (n) {
| 0 => [||]