From 822a803d01f4cf6e2a24cb6d0f02fe368afc5bda Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Tue, 25 Feb 2020 10:38:08 +0300 Subject: [PATCH] Adds tests (4) --- __tests__/Functions__Test.re | 9 +++++++++ src/utility/lib/Functions.re | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/__tests__/Functions__Test.re b/__tests__/Functions__Test.re index a0500e00..d5cc0d03 100644 --- a/__tests__/Functions__Test.re +++ b/__tests__/Functions__Test.re @@ -60,4 +60,13 @@ describe("Functions", () => { expect(Functions.min([|(-1.), (-2.), 0., 20., (-2.2)|])) |> toEqual(-2.2) }); + test("max#1", () => { + expect(Functions.max([|1., 2., 3.|])) |> toEqual(3.) + }); + test("max#2", () => { + expect(Functions.max([|(-1.), (-2.), 0., 20.|])) |> toEqual(20.) + }); + test("max#3", () => { + expect(Functions.max([|(-1.), (-2.), 0., (-2.2)|])) |> toEqual(0.) + }); }); diff --git a/src/utility/lib/Functions.re b/src/utility/lib/Functions.re index 0f310966..4600f237 100644 --- a/src/utility/lib/Functions.re +++ b/src/utility/lib/Functions.re @@ -12,7 +12,7 @@ let interpolate = 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 = Belt.Array.reduce(_, 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 range = (min: float, max: float, n: int): array(float) => {