test: started rewriting some old tests for modules
This commit is contained in:
@@ -26,22 +26,10 @@ function $$const(x, param) {
|
||||
return x;
|
||||
}
|
||||
|
||||
function $less$neg(f, g, x) {
|
||||
return Curry._1(f, Curry._1(g, x));
|
||||
}
|
||||
|
||||
function flip(f, x, y) {
|
||||
return Curry._2(f, y, x);
|
||||
}
|
||||
|
||||
function $(f, x) {
|
||||
return Curry._1(f, x);
|
||||
}
|
||||
|
||||
function $amp(x, f) {
|
||||
return Curry._1(f, x);
|
||||
}
|
||||
|
||||
function on(b, u, x, y) {
|
||||
return Curry._2(b, Curry._1(u, x), Curry._1(u, y));
|
||||
}
|
||||
@@ -49,9 +37,6 @@ function on(b, u, x, y) {
|
||||
exports.Functor = Functor;
|
||||
exports.id = id;
|
||||
exports.$$const = $$const;
|
||||
exports.$less$neg = $less$neg;
|
||||
exports.flip = flip;
|
||||
exports.$ = $;
|
||||
exports.$amp = $amp;
|
||||
exports.on = on;
|
||||
/* No side effect */
|
||||
|
||||
@@ -8,12 +8,6 @@ let id = x => x;
|
||||
|
||||
let const = (x, _) => x;
|
||||
|
||||
let (<-) = (f, g, x) => f(g(x));
|
||||
|
||||
let flip = (f, x, y) => f(y, x);
|
||||
|
||||
let ($) = (f, x) => f(x);
|
||||
|
||||
let (&) = (x, f) => f(x);
|
||||
|
||||
let on = (b, u, x, y) => b(u(x), u(y));
|
||||
|
||||
+80
-2
@@ -1,9 +1,20 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Caml_int32 = require("bs-platform/lib/js/caml_int32.js");
|
||||
var Pervasives = require("bs-platform/lib/js/pervasives.js");
|
||||
var Caml_format = require("bs-platform/lib/js/caml_format.js");
|
||||
|
||||
function compare(x, y) {
|
||||
if (x < y) {
|
||||
return /* LT */0;
|
||||
} else if (x > y) {
|
||||
return /* GT */2;
|
||||
} else {
|
||||
return /* EQ */1;
|
||||
}
|
||||
}
|
||||
|
||||
function max(x, y) {
|
||||
if (x > y) {
|
||||
return x;
|
||||
@@ -54,14 +65,75 @@ function abs(x) {
|
||||
}
|
||||
}
|
||||
|
||||
function even(x) {
|
||||
return x % 2 === 0;
|
||||
}
|
||||
|
||||
function odd(x) {
|
||||
return x % 2 === 1;
|
||||
}
|
||||
|
||||
function modUntilNoRemainder(_x, _div) {
|
||||
while(true) {
|
||||
var div = _div;
|
||||
var x = _x;
|
||||
var rem = Caml_int32.mod_(x, div);
|
||||
if (rem === 0) {
|
||||
return abs(div);
|
||||
}
|
||||
_div = rem;
|
||||
_x = div;
|
||||
continue ;
|
||||
};
|
||||
}
|
||||
|
||||
function gcd(x, y) {
|
||||
if (x !== 0) {
|
||||
if (y === 0) {
|
||||
return x;
|
||||
}
|
||||
var match = minmax(x, y);
|
||||
return modUntilNoRemainder(match[0], match[1]);
|
||||
}
|
||||
if (y !== 0) {
|
||||
return y;
|
||||
}
|
||||
throw Pervasives.invalid_arg("gcd: Both inputs cannot be 0.");
|
||||
}
|
||||
|
||||
function lcm(x, y) {
|
||||
if (x !== 0) {
|
||||
if (y !== 0) {
|
||||
return Caml_int32.div(Math.imul(x, y), gcd(x, y));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (y !== 0) {
|
||||
return 0;
|
||||
}
|
||||
throw Pervasives.invalid_arg("lcm: Both inputs cannot be 0.");
|
||||
}
|
||||
|
||||
function signum(x) {
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
} else if (x > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function show(prim) {
|
||||
return prim.toString();
|
||||
}
|
||||
|
||||
var read = Caml_format.caml_int_of_string;
|
||||
var unsafeRead = Caml_format.caml_int_of_string;
|
||||
|
||||
var readOption = Pervasives.int_of_string_opt;
|
||||
|
||||
exports.compare = compare;
|
||||
exports.max = max;
|
||||
exports.min = min;
|
||||
exports.minmax = minmax;
|
||||
@@ -69,7 +141,13 @@ exports.inc = inc;
|
||||
exports.dec = dec;
|
||||
exports.negate = negate;
|
||||
exports.abs = abs;
|
||||
exports.even = even;
|
||||
exports.odd = odd;
|
||||
exports.modUntilNoRemainder = modUntilNoRemainder;
|
||||
exports.gcd = gcd;
|
||||
exports.lcm = lcm;
|
||||
exports.signum = signum;
|
||||
exports.show = show;
|
||||
exports.read = read;
|
||||
exports.unsafeRead = unsafeRead;
|
||||
exports.readOption = readOption;
|
||||
/* No side effect */
|
||||
|
||||
+98
-2
@@ -1,22 +1,118 @@
|
||||
type t = int;
|
||||
|
||||
/**
|
||||
* Returns the larger of its two arguments.
|
||||
* `compare x y` compares two integers and returns an ordering that is to be
|
||||
* read *x ordering y*, e.g. if `LT`, `x` is lower than `y`.
|
||||
*/
|
||||
let compare = (x: int, y: int) => x < y ? Ley_Ord.LT : x > y ? GT : EQ;
|
||||
|
||||
/**
|
||||
* `max x y` returns the larger of its two arguments.
|
||||
*/
|
||||
let max = (x: int, y: int) => x > y ? x : y;
|
||||
|
||||
/**
|
||||
* `max x y` returns the smaller of its two arguments.
|
||||
*/
|
||||
let min = (x: int, y: int) => x < y ? x : y;
|
||||
|
||||
/**
|
||||
* `minmax x y` returns a pair `(a, b)` where `a` is the smaller and `b` the
|
||||
* larger of `x` and `y`.
|
||||
*/
|
||||
let minmax = (x: int, y: int) => x < y ? (x, y) : (y, x);
|
||||
|
||||
/**
|
||||
* `inc x` increments its argument by 1.
|
||||
*/
|
||||
let inc = (x: int) => x + 1;
|
||||
|
||||
/**
|
||||
* `dec x` decrements its argument by 1.
|
||||
*/
|
||||
let dec = (x: int) => x - 1;
|
||||
|
||||
/**
|
||||
* `negate x` negates its argument.
|
||||
*/
|
||||
let negate = (x: int) => - x;
|
||||
|
||||
/**
|
||||
* `abs x` returns the absolute value of its argument.
|
||||
*/
|
||||
let abs = (x: int) => x < 0 ? - x : x;
|
||||
|
||||
/**
|
||||
* `even x` checks if its argument is even.
|
||||
*/
|
||||
let even = (x: int) => x mod 2 === 0;
|
||||
|
||||
/**
|
||||
* `odd x` checks if its argument is odd.
|
||||
*/
|
||||
let odd = (x: int) => x mod 2 === 1;
|
||||
|
||||
let rec modUntilNoRemainder = (x, div) => {
|
||||
let rem = x mod div;
|
||||
|
||||
if (rem === 0) {
|
||||
abs(div);
|
||||
} else {
|
||||
modUntilNoRemainder(div, rem);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* `gcd x y` is the greatest (positive) integer that divides both `x` and `y`;
|
||||
* for example `gcd (-3) 6 = 3`, `gcd (-3) (-6) = 3`, `gcd 0 4 = 4`. `gcd 0 0`
|
||||
* raises a runtime error.
|
||||
*/
|
||||
let gcd = (x, y) =>
|
||||
switch (x, y) {
|
||||
| (0, 0) => raise(invalid_arg("gcd: Both inputs cannot be 0."))
|
||||
| (0, a)
|
||||
| (a, 0) => a
|
||||
| (a, b) =>
|
||||
let (lower, upper) = minmax(a, b);
|
||||
modUntilNoRemainder(lower, upper);
|
||||
};
|
||||
|
||||
/**
|
||||
* `lcm x y` is the smallest positive integer that both `x` and `y` divide.
|
||||
*/
|
||||
let lcm = (x, y) =>
|
||||
switch (x, y) {
|
||||
| (0, 0) => raise(invalid_arg("lcm: Both inputs cannot be 0."))
|
||||
| (0, _)
|
||||
| (_, 0) => 0
|
||||
| (a, b) => a * b / gcd(a, b)
|
||||
};
|
||||
|
||||
/**
|
||||
* Sign of a number. The functions abs and signum should satisfy the law:
|
||||
*
|
||||
* ```haskell
|
||||
* abs x * signum x == x
|
||||
* ```
|
||||
*
|
||||
* For real numbers, the `signum` is either `-1` (negative), `0` (zero) or `1`
|
||||
* (positive).
|
||||
*/
|
||||
let signum = x => x < 0 ? (-1) : x > 0 ? 1 : 0;
|
||||
|
||||
/**
|
||||
* `show x` converts its argument to a string.
|
||||
*/
|
||||
let show = Js.Int.toString;
|
||||
|
||||
let read = int_of_string;
|
||||
/**
|
||||
* `unsafeRead x` converts its argument to an integer, but raises an exception
|
||||
* if the given string is not a valid representation of an integer.
|
||||
*/
|
||||
let unsafeRead = int_of_string;
|
||||
|
||||
/**
|
||||
* `readOption x` converts its argument to an integer in a `Some` and returns
|
||||
* `None` if the given string is not a valid representation of an integer.
|
||||
*/
|
||||
let readOption = int_of_string_opt;
|
||||
|
||||
@@ -151,15 +151,13 @@ function catOptions(xs) {
|
||||
}
|
||||
|
||||
function mapOption(f, xs) {
|
||||
return List.fold_right((function (param) {
|
||||
return Ley_Function$OptolithClient.$less$neg((function (param) {
|
||||
return option(Ley_Function$OptolithClient.id, (function (x, xs) {
|
||||
return {
|
||||
hd: x,
|
||||
tl: xs
|
||||
};
|
||||
}), param);
|
||||
}), f, param);
|
||||
return List.fold_right((function (x) {
|
||||
return option(Ley_Function$OptolithClient.id, (function (x, xs) {
|
||||
return {
|
||||
hd: x,
|
||||
tl: xs
|
||||
};
|
||||
}), Curry._1(f, x));
|
||||
}), xs, /* [] */0);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ let catOptions = xs =>
|
||||
List.fold_right(option(id, (x, xs) => [x, ...xs]), xs, []);
|
||||
|
||||
let mapOption = (f, xs) =>
|
||||
List.fold_right(option(id, (x, xs) => [x, ...xs]) <- f, xs, []);
|
||||
List.fold_right(x => x |> f |> option(id, (x, xs) => [x, ...xs]), xs, []);
|
||||
|
||||
let ensure = (pred, x) => pred(x) ? Some(x) : None;
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
import * as Bool from "../Bool"
|
||||
|
||||
describe ("and", () => {
|
||||
it ("returns False if at least one parameter is False", () => {
|
||||
expect (Bool.and (true) (false)) .toBe (false)
|
||||
expect (Bool.and (false) (true)) .toBe (false)
|
||||
expect (Bool.and (false) (false)) .toBe (false)
|
||||
})
|
||||
|
||||
it ("returns True if both parameters are True", () => {
|
||||
expect (Bool.and (true) (true)) .toBe (true)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("andFL", () => {
|
||||
it ("returns False if at least one parameter is False", () => {
|
||||
expect (Bool.andFL (() => false) (true)) .toBe (false)
|
||||
expect (Bool.andFL (() => true) (false)) .toBe (false)
|
||||
expect (Bool.andFL (() => false) (false)) .toBe (false)
|
||||
})
|
||||
|
||||
it ("returns True if both parameters are True", () => {
|
||||
expect (Bool.andFL (() => true) (true)) .toBe (true)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("or", () => {
|
||||
it ("returns True if at least one parameter is True", () => {
|
||||
expect (Bool.or (true) (false)) .toBe (true)
|
||||
expect (Bool.or (false) (true)) .toBe (true)
|
||||
expect (Bool.or (true) (true)) .toBe (true)
|
||||
})
|
||||
|
||||
it ("returns False if both parameters are False", () => {
|
||||
expect (Bool.or (false) (false)) .toBe (false)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("orFL", () => {
|
||||
it ("returns True if at least one parameter is True", () => {
|
||||
expect (Bool.orFL (() => false) (true)) .toBe (true)
|
||||
expect (Bool.orFL (() => true) (false)) .toBe (true)
|
||||
expect (Bool.orFL (() => true) (true)) .toBe (true)
|
||||
})
|
||||
|
||||
it ("returns False if both parameters are False", () => {
|
||||
expect (Bool.orFL (() => false) (false)) .toBe (false)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("not", () => {
|
||||
it ("returns True if it receives False", () => {
|
||||
expect (Bool.not (false)) .toBe (true)
|
||||
})
|
||||
|
||||
it ("returns False if it receives True", () => {
|
||||
expect (Bool.not (true)) .toBe (false)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("notP", () => {
|
||||
it ("returns True if it returns False", () => {
|
||||
expect (Bool.notP<void> (() => false) ()) .toBe (true)
|
||||
})
|
||||
|
||||
it ("returns False if it returns True", () => {
|
||||
expect (Bool.notP<void> (() => true) ()) .toBe (false)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("otherwise", () => {
|
||||
it ("is True", () => {
|
||||
expect (Bool.otherwise) .toBe (true)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("bool", () => {
|
||||
it ("is returns x if the condition is False", () => {
|
||||
expect (Bool.bool (1) (2) (false)) .toBe (1)
|
||||
})
|
||||
|
||||
it ("is returns y if the condition is True", () => {
|
||||
expect (Bool.bool (1) (2) (true)) .toBe (2)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("bool_", () => {
|
||||
it ("is returns x if the condition is False", () => {
|
||||
expect (Bool.bool_ (() => 1) (() => 2) (false)) .toBe (1)
|
||||
})
|
||||
|
||||
it ("is returns y if the condition is True", () => {
|
||||
expect (Bool.bool_ (() => 1) (() => 2) (true)) .toBe (2)
|
||||
})
|
||||
})
|
||||
@@ -1,39 +0,0 @@
|
||||
import { index, inRange, inRangeN, range, rangeN, rangeSize } from "../Ix"
|
||||
import { List } from "../List"
|
||||
import { Pair } from "../Tuple"
|
||||
|
||||
test ("range", () => {
|
||||
expect (range (Pair (1, 5))) .toEqual (List (1, 2, 3, 4, 5))
|
||||
expect (range (Pair (1, 1))) .toEqual (List (1))
|
||||
expect (range (Pair (1, -2))) .toEqual (List ())
|
||||
})
|
||||
|
||||
test ("rangeN", () => {
|
||||
expect (rangeN (1, 5)) .toEqual (List (1, 2, 3, 4, 5))
|
||||
expect (rangeN (1, 1)) .toEqual (List (1))
|
||||
expect (rangeN (1, -2)) .toEqual (List ())
|
||||
})
|
||||
|
||||
test ("index", () => {
|
||||
expect (index (Pair (1, 5)) (3)) .toEqual (2)
|
||||
expect (index (Pair (1, 5)) (1)) .toEqual (0)
|
||||
expect (() => index (Pair (1, 5)) (-1)) .toThrow ()
|
||||
})
|
||||
|
||||
test ("inRange", () => {
|
||||
expect (inRange (Pair (1, 5)) (3)) .toEqual (true)
|
||||
expect (inRange (Pair (1, 5)) (1)) .toEqual (true)
|
||||
expect (inRange (Pair (1, 5)) (-1)) .toEqual (false)
|
||||
})
|
||||
|
||||
test ("inRangeN", () => {
|
||||
expect (inRangeN (1, 5) (3)) .toEqual (true)
|
||||
expect (inRangeN (1, 5) (1)) .toEqual (true)
|
||||
expect (inRangeN (1, 5) (-1)) .toEqual (false)
|
||||
})
|
||||
|
||||
test ("rangeSize", () => {
|
||||
expect (rangeSize (Pair (1, 5))) .toEqual (5)
|
||||
expect (rangeSize (Pair (1, 1))) .toEqual (1)
|
||||
expect (rangeSize (Pair (1, -2))) .toEqual (0)
|
||||
})
|
||||
@@ -0,0 +1,61 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
|
||||
var Ley_Bool$OptolithClient = require("../Ley_Bool.bs.js");
|
||||
|
||||
Jest.describe("not", (function (param) {
|
||||
Jest.test("returns True if it receives False", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(Ley_Bool$OptolithClient.not_(false)));
|
||||
}));
|
||||
return Jest.test("returns False if it receives True", (function (param) {
|
||||
return Jest.Expect.toBe(false, Jest.Expect.expect(Ley_Bool$OptolithClient.not_(true)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("notP", (function (param) {
|
||||
Jest.test("returns True if it returns False", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(Ley_Bool$OptolithClient.notP((function (param) {
|
||||
return false;
|
||||
}), undefined)));
|
||||
}));
|
||||
return Jest.test("returns False if it returns True", (function (param) {
|
||||
return Jest.Expect.toBe(false, Jest.Expect.expect(Ley_Bool$OptolithClient.notP((function (param) {
|
||||
return true;
|
||||
}), undefined)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("otherwise", (function (param) {
|
||||
return Jest.test("is True", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(true));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("bool", (function (param) {
|
||||
Jest.test("is returns x if the condition is False", (function (param) {
|
||||
return Jest.Expect.toBe(1, Jest.Expect.expect(Ley_Bool$OptolithClient.bool(1, 2, false)));
|
||||
}));
|
||||
return Jest.test("is returns y if the condition is True", (function (param) {
|
||||
return Jest.Expect.toBe(2, Jest.Expect.expect(Ley_Bool$OptolithClient.bool(1, 2, true)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("bool_", (function (param) {
|
||||
Jest.test("is returns x if the condition is False", (function (param) {
|
||||
return Jest.Expect.toBe(1, Jest.Expect.expect(Ley_Bool$OptolithClient.bool_((function (param) {
|
||||
return 1;
|
||||
}), (function (param) {
|
||||
return 2;
|
||||
}), false)));
|
||||
}));
|
||||
return Jest.test("is returns y if the condition is True", (function (param) {
|
||||
return Jest.Expect.toBe(2, Jest.Expect.expect(Ley_Bool$OptolithClient.bool_((function (param) {
|
||||
return 1;
|
||||
}), (function (param) {
|
||||
return 2;
|
||||
}), true)));
|
||||
}));
|
||||
}));
|
||||
|
||||
/* Not a pure module */
|
||||
@@ -0,0 +1,48 @@
|
||||
open Jest;
|
||||
open Expect;
|
||||
|
||||
describe("not", () => {
|
||||
test("returns True if it receives False", () => {
|
||||
expect(Ley_Bool.not(false)) |> toBe(true)
|
||||
});
|
||||
|
||||
test("returns False if it receives True", () => {
|
||||
expect(Ley_Bool.not(true)) |> toBe(false)
|
||||
});
|
||||
});
|
||||
|
||||
describe("notP", () => {
|
||||
test("returns True if it returns False", () => {
|
||||
expect(Ley_Bool.notP(() => false, ())) |> toBe(true)
|
||||
});
|
||||
|
||||
test("returns False if it returns True", () => {
|
||||
expect(Ley_Bool.notP(() => true, ())) |> toBe(false)
|
||||
});
|
||||
});
|
||||
|
||||
describe("otherwise", () => {
|
||||
test("is True", () => {
|
||||
expect(Ley_Bool.otherwise) |> toBe(true)
|
||||
})
|
||||
});
|
||||
|
||||
describe("bool", () => {
|
||||
test("is returns x if the condition is False", () => {
|
||||
expect(Ley_Bool.bool(1, 2, false)) |> toBe(1)
|
||||
});
|
||||
|
||||
test("is returns y if the condition is True", () => {
|
||||
expect(Ley_Bool.bool(1, 2, true)) |> toBe(2)
|
||||
});
|
||||
});
|
||||
|
||||
describe("bool_", () => {
|
||||
test("is returns x if the condition is False", () => {
|
||||
expect(Ley_Bool.bool_(() => 1, () => 2, false)) |> toBe(1)
|
||||
});
|
||||
|
||||
test("is returns y if the condition is True", () => {
|
||||
expect(Ley_Bool.bool_(() => 1, () => 2, true)) |> toBe(2)
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
|
||||
var Ley_Function$OptolithClient = require("../Ley_Function.bs.js");
|
||||
|
||||
Jest.describe("id", (function (param) {
|
||||
return Jest.test("returns its argument", (function (param) {
|
||||
return Jest.Expect.toBe(1023, Jest.Expect.expect(Ley_Function$OptolithClient.id(1023)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("const", (function (param) {
|
||||
return Jest.test("returns its first argument", (function (param) {
|
||||
return Jest.Expect.toBe(956, Jest.Expect.expect(Ley_Function$OptolithClient.$$const(956, "test")));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("flip", (function (param) {
|
||||
return Jest.test("flips the first two arguments of the function", (function (param) {
|
||||
return Jest.Expect.toBe("test", Jest.Expect.expect(Ley_Function$OptolithClient.flip(Ley_Function$OptolithClient.$$const, 956, "test")));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("on", (function (param) {
|
||||
return Jest.test("applies its functions to its values", (function (param) {
|
||||
return Jest.Expect.toBe(3, Jest.Expect.expect(Ley_Function$OptolithClient.on((function (prim, prim$1) {
|
||||
return prim + prim$1 | 0;
|
||||
}), (function (x) {
|
||||
if (x !== undefined) {
|
||||
return x;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}), 3, undefined)));
|
||||
}));
|
||||
}));
|
||||
|
||||
/* Not a pure module */
|
||||
@@ -0,0 +1,37 @@
|
||||
open Jest;
|
||||
open Expect;
|
||||
open Ley_Function;
|
||||
|
||||
describe("id", () => {
|
||||
test("returns its argument", () =>
|
||||
expect(id(1023)) |> toBe(1023)
|
||||
)
|
||||
});
|
||||
|
||||
describe("const", () => {
|
||||
test("returns its first argument", () =>
|
||||
expect(const(956, "test")) |> toBe(956)
|
||||
)
|
||||
});
|
||||
|
||||
describe("flip", () => {
|
||||
test("flips the first two arguments of the function", () =>
|
||||
expect(flip(const, 956, "test")) |> toBe("test")
|
||||
)
|
||||
});
|
||||
|
||||
describe("on", () => {
|
||||
test("applies its functions to its values", () =>
|
||||
expect(
|
||||
on(
|
||||
(+),
|
||||
fun
|
||||
| Some(x) => x
|
||||
| None => 0,
|
||||
Some(3),
|
||||
None,
|
||||
),
|
||||
)
|
||||
|> toBe(3)
|
||||
)
|
||||
});
|
||||
@@ -0,0 +1,300 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
|
||||
var Ley_Int$OptolithClient = require("../Ley_Int.bs.js");
|
||||
|
||||
Jest.describe("compare", (function (param) {
|
||||
Jest.test("returns LT if the first is lower than the second", (function (param) {
|
||||
return Jest.Expect.toBe(/* LT */0, Jest.Expect.expect(Ley_Int$OptolithClient.compare(1, 2)));
|
||||
}));
|
||||
Jest.test("returns GT if the first is greater than the second", (function (param) {
|
||||
return Jest.Expect.toBe(/* GT */2, Jest.Expect.expect(Ley_Int$OptolithClient.compare(3, 2)));
|
||||
}));
|
||||
return Jest.test("returns EQ if the first equals the second", (function (param) {
|
||||
return Jest.Expect.toBe(/* EQ */1, Jest.Expect.expect(Ley_Int$OptolithClient.compare(2, 2)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("max", (function (param) {
|
||||
Jest.test("returns the first argument if its larger", (function (param) {
|
||||
return Jest.Expect.toBe(6, Jest.Expect.expect(Ley_Int$OptolithClient.max(6, 5)));
|
||||
}));
|
||||
return Jest.test("returns the second argument if its larger", (function (param) {
|
||||
return Jest.Expect.toBe(5, Jest.Expect.expect(Ley_Int$OptolithClient.max(3, 5)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("min", (function (param) {
|
||||
Jest.test("returns the first argument if its smaller", (function (param) {
|
||||
return Jest.Expect.toBe(5, Jest.Expect.expect(Ley_Int$OptolithClient.max(3, 5)));
|
||||
}));
|
||||
return Jest.test("returns the second argument if its smaller", (function (param) {
|
||||
return Jest.Expect.toBe(6, Jest.Expect.expect(Ley_Int$OptolithClient.max(6, 5)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("minmax", (function (param) {
|
||||
Jest.test("returns the smaller first argument as the first tuple element", (function (param) {
|
||||
return Jest.Expect.toEqual([
|
||||
3,
|
||||
5
|
||||
], Jest.Expect.expect(Ley_Int$OptolithClient.minmax(3, 5)));
|
||||
}));
|
||||
return Jest.test("returns the larger first argument as the second tuple element", (function (param) {
|
||||
return Jest.Expect.toEqual([
|
||||
5,
|
||||
6
|
||||
], Jest.Expect.expect(Ley_Int$OptolithClient.minmax(6, 5)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("inc", (function (param) {
|
||||
return Jest.testAll("increments its argument by 1", {
|
||||
hd: [
|
||||
3,
|
||||
4
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
5,
|
||||
6
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Ley_Int$OptolithClient.inc(param[0])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("dec", (function (param) {
|
||||
return Jest.testAll("decrements its argument by 1", {
|
||||
hd: [
|
||||
3,
|
||||
2
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
5,
|
||||
4
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Ley_Int$OptolithClient.dec(param[0])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("negate", (function (param) {
|
||||
return Jest.testAll("negates its argument", {
|
||||
hd: [
|
||||
3,
|
||||
-3
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
-5,
|
||||
5
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Ley_Int$OptolithClient.negate(param[0])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("abs", (function (param) {
|
||||
return Jest.testAll("returns the absolute value", {
|
||||
hd: [
|
||||
3,
|
||||
3
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
0,
|
||||
0
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
-5,
|
||||
5
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Ley_Int$OptolithClient.abs(param[0])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("even", (function (param) {
|
||||
return Jest.testAll("returns if an integer is even", {
|
||||
hd: [
|
||||
1,
|
||||
false
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
2,
|
||||
true
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Ley_Int$OptolithClient.even(param[0])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("odd", (function (param) {
|
||||
return Jest.testAll("returns if an integer is odd", {
|
||||
hd: [
|
||||
1,
|
||||
true
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
2,
|
||||
false
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Ley_Int$OptolithClient.odd(param[0])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("gcd", (function (param) {
|
||||
Jest.testAll("returns the greatest common divisor for an integer", {
|
||||
hd: [
|
||||
-3,
|
||||
6,
|
||||
3
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
-3,
|
||||
-6,
|
||||
3
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
12,
|
||||
18,
|
||||
6
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
0,
|
||||
4,
|
||||
4
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[2], Jest.Expect.expect(Ley_Int$OptolithClient.gcd(param[0], param[1])));
|
||||
}));
|
||||
return Jest.test("throws if both arguments are 0", (function (param) {
|
||||
return Jest.Expect.toThrow(Jest.Expect.expect(function (param) {
|
||||
return Ley_Int$OptolithClient.gcd(0, 0);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("lcm", (function (param) {
|
||||
Jest.testAll("returns the greatest common divisor for an integer", {
|
||||
hd: [
|
||||
-3,
|
||||
6,
|
||||
-6
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
-3,
|
||||
-6,
|
||||
6
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
12,
|
||||
18,
|
||||
36
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
0,
|
||||
4,
|
||||
0
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[2], Jest.Expect.expect(Ley_Int$OptolithClient.lcm(param[0], param[1])));
|
||||
}));
|
||||
return Jest.test("throws if both arguments are 0", (function (param) {
|
||||
return Jest.Expect.toThrow(Jest.Expect.expect(function (param) {
|
||||
return Ley_Int$OptolithClient.lcm(0, 0);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("signum", (function (param) {
|
||||
Jest.test("returns -1 for a negative integer", (function (param) {
|
||||
return Jest.Expect.toBe(-1, Jest.Expect.expect(Ley_Int$OptolithClient.signum(-43)));
|
||||
}));
|
||||
Jest.test("returns 0 for a 0", (function (param) {
|
||||
return Jest.Expect.toBe(0, Jest.Expect.expect(Ley_Int$OptolithClient.signum(0)));
|
||||
}));
|
||||
return Jest.test("returns 1 for a positive integer", (function (param) {
|
||||
return Jest.Expect.toBe(1, Jest.Expect.expect(Ley_Int$OptolithClient.signum(61)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("show", (function (param) {
|
||||
return Jest.testAll("converts an integer to a string", {
|
||||
hd: [
|
||||
1,
|
||||
"1"
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
2,
|
||||
"2"
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
-3,
|
||||
"-3"
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Ley_Int$OptolithClient.show(param[0])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("unsafeRead", (function (param) {
|
||||
Jest.test("parses a string as an integer", (function (param) {
|
||||
return Jest.Expect.toBe(-6, Jest.Expect.expect(Ley_Int$OptolithClient.unsafeRead("-6")));
|
||||
}));
|
||||
return Jest.test("throws if string representation is invalid", (function (param) {
|
||||
return Jest.Expect.toThrow(Jest.Expect.expect(function (param) {
|
||||
return Ley_Int$OptolithClient.unsafeRead("--6");
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("readOption", (function (param) {
|
||||
Jest.test("parses a string as an integer", (function (param) {
|
||||
return Jest.Expect.toEqual(-6, Jest.Expect.expect(Ley_Int$OptolithClient.readOption("-6")));
|
||||
}));
|
||||
return Jest.test("returns None if string representation is invalid", (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Ley_Int$OptolithClient.readOption("--6")));
|
||||
}));
|
||||
}));
|
||||
|
||||
/* Not a pure module */
|
||||
@@ -0,0 +1,169 @@
|
||||
open Jest;
|
||||
open Expect;
|
||||
open Ley_Int;
|
||||
|
||||
describe("compare", () => {
|
||||
test("returns LT if the first is lower than the second", () =>
|
||||
expect(compare(1, 2)) |> toBe(Ley_Ord.LT)
|
||||
);
|
||||
|
||||
test("returns GT if the first is greater than the second", () =>
|
||||
expect(compare(3, 2)) |> toBe(Ley_Ord.GT)
|
||||
);
|
||||
|
||||
test("returns EQ if the first equals the second", () =>
|
||||
expect(compare(2, 2)) |> toBe(Ley_Ord.EQ)
|
||||
);
|
||||
});
|
||||
|
||||
describe("max", () => {
|
||||
test("returns the first argument if its larger", () =>
|
||||
expect(max(6, 5)) |> toBe(6)
|
||||
);
|
||||
|
||||
test("returns the second argument if its larger", () =>
|
||||
expect(max(3, 5)) |> toBe(5)
|
||||
);
|
||||
});
|
||||
|
||||
describe("min", () => {
|
||||
test("returns the first argument if its smaller", () =>
|
||||
expect(max(3, 5)) |> toBe(5)
|
||||
);
|
||||
|
||||
test("returns the second argument if its smaller", () =>
|
||||
expect(max(6, 5)) |> toBe(6)
|
||||
);
|
||||
});
|
||||
|
||||
describe("minmax", () => {
|
||||
test("returns the smaller first argument as the first tuple element", () =>
|
||||
expect(minmax(3, 5)) |> toEqual((3, 5))
|
||||
);
|
||||
|
||||
test("returns the larger first argument as the second tuple element", () =>
|
||||
expect(minmax(6, 5)) |> toEqual((5, 6))
|
||||
);
|
||||
});
|
||||
|
||||
describe("inc", () => {
|
||||
testAll(
|
||||
"increments its argument by 1", [(3, 4), (5, 6)], ((x, expected)) =>
|
||||
expect(inc(x)) |> toBe(expected)
|
||||
)
|
||||
});
|
||||
|
||||
describe("dec", () => {
|
||||
testAll(
|
||||
"decrements its argument by 1", [(3, 2), (5, 4)], ((x, expected)) =>
|
||||
expect(dec(x)) |> toBe(expected)
|
||||
)
|
||||
});
|
||||
|
||||
describe("negate", () => {
|
||||
testAll("negates its argument", [(3, (-3)), ((-5), 5)], ((x, expected)) =>
|
||||
expect(negate(x)) |> toBe(expected)
|
||||
)
|
||||
});
|
||||
|
||||
describe("abs", () => {
|
||||
testAll(
|
||||
"returns the absolute value",
|
||||
[(3, 3), (0, 0), ((-5), 5)],
|
||||
((x, expected)) =>
|
||||
expect(abs(x)) |> toBe(expected)
|
||||
)
|
||||
});
|
||||
|
||||
describe("even", () => {
|
||||
testAll(
|
||||
"returns if an integer is even",
|
||||
[(1, false), (2, true)],
|
||||
((x, expected)) =>
|
||||
expect(even(x)) |> toBe(expected)
|
||||
)
|
||||
});
|
||||
|
||||
describe("odd", () => {
|
||||
testAll(
|
||||
"returns if an integer is odd",
|
||||
[(1, true), (2, false)],
|
||||
((x, expected)) =>
|
||||
expect(odd(x)) |> toBe(expected)
|
||||
)
|
||||
});
|
||||
|
||||
describe("gcd", () => {
|
||||
testAll(
|
||||
"returns the greatest common divisor for an integer",
|
||||
[((-3), 6, 3), ((-3), (-6), 3), (12, 18, 6), (0, 4, 4)],
|
||||
((x, y, expected)) =>
|
||||
expect(gcd(x, y)) |> toBe(expected)
|
||||
);
|
||||
|
||||
test("throws if both arguments are 0", () =>
|
||||
expect(() =>
|
||||
gcd(0, 0)
|
||||
) |> toThrow
|
||||
);
|
||||
});
|
||||
|
||||
describe("lcm", () => {
|
||||
testAll(
|
||||
"returns the greatest common divisor for an integer",
|
||||
[((-3), 6, (-6)), ((-3), (-6), 6), (12, 18, 36), (0, 4, 0)],
|
||||
((x, y, expected)) =>
|
||||
expect(lcm(x, y)) |> toBe(expected)
|
||||
);
|
||||
|
||||
test("throws if both arguments are 0", () =>
|
||||
expect(() =>
|
||||
lcm(0, 0)
|
||||
) |> toThrow
|
||||
);
|
||||
});
|
||||
|
||||
describe("signum", () => {
|
||||
test("returns -1 for a negative integer", () =>
|
||||
expect(signum(-43)) |> toBe(-1)
|
||||
);
|
||||
|
||||
test("returns 0 for a 0", () =>
|
||||
expect(signum(0)) |> toBe(0)
|
||||
);
|
||||
|
||||
test("returns 1 for a positive integer", () =>
|
||||
expect(signum(61)) |> toBe(1)
|
||||
);
|
||||
});
|
||||
|
||||
describe("show", () => {
|
||||
testAll(
|
||||
"converts an integer to a string",
|
||||
[(1, "1"), (2, "2"), ((-3), "-3")],
|
||||
((x, expected)) =>
|
||||
expect(show(x)) |> toBe(expected)
|
||||
)
|
||||
});
|
||||
|
||||
describe("unsafeRead", () => {
|
||||
test("parses a string as an integer", () =>
|
||||
expect(unsafeRead("-6")) |> toBe(-6)
|
||||
);
|
||||
|
||||
test("throws if string representation is invalid", () =>
|
||||
expect(() =>
|
||||
unsafeRead("--6")
|
||||
) |> toThrow
|
||||
);
|
||||
});
|
||||
|
||||
describe("readOption", () => {
|
||||
test("parses a string as an integer", () =>
|
||||
expect(readOption("-6")) |> toEqual(Some(-6))
|
||||
);
|
||||
|
||||
test("returns None if string representation is invalid", () =>
|
||||
expect(readOption("--6")) |> toEqual(None)
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,111 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
|
||||
var Ley_Ix$OptolithClient = require("../Ley_Ix.bs.js");
|
||||
|
||||
Jest.describe("range", (function (param) {
|
||||
Jest.test("returns an empty list if the upper bound is lower than the lower bound", (function (param) {
|
||||
return Jest.Expect.toEqual(/* [] */0, Jest.Expect.expect(Ley_Ix$OptolithClient.range([
|
||||
1,
|
||||
-2
|
||||
])));
|
||||
}));
|
||||
Jest.test("returns an singleton list if the bounds are equal", (function (param) {
|
||||
return Jest.Expect.toEqual({
|
||||
hd: 1,
|
||||
tl: /* [] */0
|
||||
}, Jest.Expect.expect(Ley_Ix$OptolithClient.range([
|
||||
1,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
return Jest.test("returns multiple elements if the upper bound is greater than the lower bound", (function (param) {
|
||||
return Jest.Expect.toEqual({
|
||||
hd: 1,
|
||||
tl: {
|
||||
hd: 2,
|
||||
tl: {
|
||||
hd: 3,
|
||||
tl: {
|
||||
hd: 4,
|
||||
tl: {
|
||||
hd: 5,
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Jest.Expect.expect(Ley_Ix$OptolithClient.range([
|
||||
1,
|
||||
5
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("inRange", (function (param) {
|
||||
Jest.test("checks if a value is between the bounds", (function (param) {
|
||||
return Jest.Expect.toEqual(true, Jest.Expect.expect(Ley_Ix$OptolithClient.inRange([
|
||||
1,
|
||||
5
|
||||
], 3)));
|
||||
}));
|
||||
Jest.test("checks if the bounds are inclusive", (function (param) {
|
||||
return Jest.Expect.toEqual(true, Jest.Expect.expect(Ley_Ix$OptolithClient.inRange([
|
||||
1,
|
||||
5
|
||||
], 1)));
|
||||
}));
|
||||
return Jest.test("checks if a value is outside of the bounds", (function (param) {
|
||||
return Jest.Expect.toEqual(false, Jest.Expect.expect(Ley_Ix$OptolithClient.inRange([
|
||||
1,
|
||||
5
|
||||
], -1)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("index", (function (param) {
|
||||
Jest.test("returns the index of a value between the bounds", (function (param) {
|
||||
return Jest.Expect.toEqual(2, Jest.Expect.expect(Ley_Ix$OptolithClient.index([
|
||||
1,
|
||||
5
|
||||
], 3)));
|
||||
}));
|
||||
Jest.test("returns the index of a bounding value", (function (param) {
|
||||
return Jest.Expect.toEqual(0, Jest.Expect.expect(Ley_Ix$OptolithClient.index([
|
||||
1,
|
||||
5
|
||||
], 1)));
|
||||
}));
|
||||
return Jest.test("throws if a value is outside of the bounds", (function (param) {
|
||||
return Jest.Expect.toThrow(Jest.Expect.expect(function (param) {
|
||||
return Ley_Ix$OptolithClient.index([
|
||||
1,
|
||||
5
|
||||
], -1);
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("rangeSize", (function (param) {
|
||||
Jest.test("returns 0 if the upper bound is lower than the lower bound", (function (param) {
|
||||
return Jest.Expect.toEqual(0, Jest.Expect.expect(Ley_Ix$OptolithClient.rangeSize([
|
||||
1,
|
||||
-2
|
||||
])));
|
||||
}));
|
||||
Jest.test("returns 1 if the bounds are equal", (function (param) {
|
||||
return Jest.Expect.toEqual(1, Jest.Expect.expect(Ley_Ix$OptolithClient.rangeSize([
|
||||
1,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
return Jest.test("returns the size if the upper bound is greater than the lower bound", (function (param) {
|
||||
return Jest.Expect.toEqual(5, Jest.Expect.expect(Ley_Ix$OptolithClient.rangeSize([
|
||||
1,
|
||||
5
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
|
||||
/* Not a pure module */
|
||||
@@ -0,0 +1,66 @@
|
||||
open Jest;
|
||||
open Expect;
|
||||
open Ley_Ix;
|
||||
|
||||
describe("range", () => {
|
||||
test(
|
||||
"returns an empty list if the upper bound is lower than the lower bound",
|
||||
() =>
|
||||
expect(range((1, (-2)))) |> toEqual([])
|
||||
);
|
||||
|
||||
test("returns an singleton list if the bounds are equal", () =>
|
||||
expect(range((1, 1))) |> toEqual([1])
|
||||
);
|
||||
|
||||
test(
|
||||
"returns multiple elements if the upper bound is greater than the lower bound",
|
||||
() =>
|
||||
expect(range((1, 5))) |> toEqual([1, 2, 3, 4, 5])
|
||||
);
|
||||
});
|
||||
|
||||
describe("inRange", () => {
|
||||
test("checks if a value is between the bounds", () =>
|
||||
expect(inRange((1, 5), 3)) |> toEqual(true)
|
||||
);
|
||||
|
||||
test("checks if the bounds are inclusive", () =>
|
||||
expect(inRange((1, 5), 1)) |> toEqual(true)
|
||||
);
|
||||
|
||||
test("checks if a value is outside of the bounds", () =>
|
||||
expect(inRange((1, 5), -1)) |> toEqual(false)
|
||||
);
|
||||
});
|
||||
|
||||
describe("index", () => {
|
||||
test("returns the index of a value between the bounds", () =>
|
||||
expect(index((1, 5), 3)) |> toEqual(2)
|
||||
);
|
||||
|
||||
test("returns the index of a bounding value", () =>
|
||||
expect(index((1, 5), 1)) |> toEqual(0)
|
||||
);
|
||||
|
||||
test("throws if a value is outside of the bounds", () =>
|
||||
expect(() =>
|
||||
index((1, 5), -1)
|
||||
) |> toThrow
|
||||
);
|
||||
});
|
||||
|
||||
describe("rangeSize", () => {
|
||||
test("returns 0 if the upper bound is lower than the lower bound", () =>
|
||||
expect(rangeSize((1, (-2)))) |> toEqual(0)
|
||||
);
|
||||
|
||||
test("returns 1 if the bounds are equal", () =>
|
||||
expect(rangeSize((1, 1))) |> toEqual(1)
|
||||
);
|
||||
|
||||
test(
|
||||
"returns the size if the upper bound is greater than the lower bound", () =>
|
||||
expect(rangeSize((1, 5))) |> toEqual(5)
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,528 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
|
||||
var Curry = require("bs-platform/lib/js/curry.js");
|
||||
var Js_int = require("bs-platform/lib/js/js_int.js");
|
||||
var Caml_option = require("bs-platform/lib/js/caml_option.js");
|
||||
var Ley_Option$OptolithClient = require("../Ley_Option.bs.js");
|
||||
|
||||
Jest.describe("Functor", (function (param) {
|
||||
return Jest.describe("fmap", (function (param) {
|
||||
Jest.test("maps a function over a value in a Some", (function (param) {
|
||||
return Jest.Expect.toEqual(6, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.fmap, (function (param) {
|
||||
return (param << 1);
|
||||
}), 3)));
|
||||
}));
|
||||
return Jest.test("does nothing if its a None", (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.fmap, (function (param) {
|
||||
return (param << 1);
|
||||
}), undefined)));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("Applicative", (function (param) {
|
||||
Jest.describe("pure", (function (param) {
|
||||
return Jest.test("lifts a value into an option", (function (param) {
|
||||
return Jest.Expect.toEqual(2, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.pure, 2)));
|
||||
}));
|
||||
}));
|
||||
return Jest.describe("liftA2", (function (param) {
|
||||
Jest.test("maps a function over two values in Somes", (function (param) {
|
||||
return Jest.Expect.toEqual(5, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.liftA2, (function (prim, prim$1) {
|
||||
return prim + prim$1 | 0;
|
||||
}), 3, 2)));
|
||||
}));
|
||||
return Jest.testAll("does nothing if at least one of the values is a None", {
|
||||
hd: [
|
||||
undefined,
|
||||
2
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
3,
|
||||
undefined
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
undefined,
|
||||
undefined
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.liftA2, (function (prim, prim$1) {
|
||||
return prim + prim$1 | 0;
|
||||
}), param[0], param[1])));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("Alternative", (function (param) {
|
||||
return Jest.describe("empty", (function (param) {
|
||||
return Jest.test("is the empty option", (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Ley_Option$OptolithClient.empty));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("Monad", (function (param) {
|
||||
Jest.describe("return", (function (param) {
|
||||
return Jest.test("lifts a value into an option", (function (param) {
|
||||
return Jest.Expect.toEqual(2, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.pure, 2)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("join", (function (param) {
|
||||
Jest.test("joins two nested Somes into a single Some", (function (param) {
|
||||
return Jest.Expect.toEqual(3, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.join, 3)));
|
||||
}));
|
||||
Jest.test("joins a nested None into a single None", (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.join, Caml_option.some(undefined))));
|
||||
}));
|
||||
return Jest.test("does nothing if its a None", (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.join, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("liftM2", (function (param) {
|
||||
Jest.test("maps a function over two values in Somes", (function (param) {
|
||||
return Jest.Expect.toEqual(5, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.liftM2, (function (prim, prim$1) {
|
||||
return prim + prim$1 | 0;
|
||||
}), 3, 2)));
|
||||
}));
|
||||
return Jest.testAll("does nothing if at least one of the values is a None", {
|
||||
hd: [
|
||||
undefined,
|
||||
2
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
3,
|
||||
undefined
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
undefined,
|
||||
undefined
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.liftM2, (function (prim, prim$1) {
|
||||
return prim + prim$1 | 0;
|
||||
}), param[0], param[1])));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("liftM3", (function (param) {
|
||||
Jest.test("maps a function over three values in Somes", (function (param) {
|
||||
return Jest.Expect.toEqual(6, Jest.Expect.expect(Curry._4(Ley_Option$OptolithClient.liftM3, (function (a, b, c) {
|
||||
return (a + b | 0) + c | 0;
|
||||
}), 1, 2, 3)));
|
||||
}));
|
||||
return Jest.testAll("does nothing if at least one of the values is a None", {
|
||||
hd: [
|
||||
undefined,
|
||||
2,
|
||||
3
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
undefined,
|
||||
3
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
2,
|
||||
undefined
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._4(Ley_Option$OptolithClient.liftM3, (function (a, b, c) {
|
||||
return (a + b | 0) + c | 0;
|
||||
}), param[0], param[1], param[2])));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("liftM4", (function (param) {
|
||||
Jest.test("maps a function over three values in Somes", (function (param) {
|
||||
return Jest.Expect.toEqual(10, Jest.Expect.expect(Curry._5(Ley_Option$OptolithClient.liftM4, (function (a, b, c, d) {
|
||||
return ((a + b | 0) + c | 0) + d | 0;
|
||||
}), 1, 2, 3, 4)));
|
||||
}));
|
||||
return Jest.testAll("does nothing if at least one of the values is a None", {
|
||||
hd: [
|
||||
undefined,
|
||||
2,
|
||||
3,
|
||||
4
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
undefined,
|
||||
3,
|
||||
4
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
2,
|
||||
undefined,
|
||||
4
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
undefined
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._5(Ley_Option$OptolithClient.liftM4, (function (a, b, c, d) {
|
||||
return ((a + b | 0) + c | 0) + d | 0;
|
||||
}), param[0], param[1], param[2], param[3])));
|
||||
}));
|
||||
}));
|
||||
return Jest.describe("liftM5", (function (param) {
|
||||
Jest.test("maps a function over three values in Somes", (function (param) {
|
||||
return Jest.Expect.toEqual(15, Jest.Expect.expect(Curry._6(Ley_Option$OptolithClient.liftM5, (function (a, b, c, d, e) {
|
||||
return (((a + b | 0) + c | 0) + d | 0) + e | 0;
|
||||
}), 1, 2, 3, 4, 5)));
|
||||
}));
|
||||
return Jest.testAll("does nothing if at least one of the values is a None", {
|
||||
hd: [
|
||||
undefined,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
undefined,
|
||||
3,
|
||||
4,
|
||||
5
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
2,
|
||||
undefined,
|
||||
4,
|
||||
5
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
undefined,
|
||||
5
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
undefined
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._6(Ley_Option$OptolithClient.liftM5, (function (a, b, c, d, e) {
|
||||
return (((a + b | 0) + c | 0) + d | 0) + e | 0;
|
||||
}), param[0], param[1], param[2], param[3], param[4])));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("Foldable", (function (param) {
|
||||
Jest.describe("foldr", (function (param) {
|
||||
Jest.test("folds the value from a Some into the default", (function (param) {
|
||||
return Jest.Expect.toEqual(8, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.foldr, (function (x, acc) {
|
||||
return (x << 1) + acc | 0;
|
||||
}), 2, 3)));
|
||||
}));
|
||||
return Jest.test("returns the initial value if its a None", (function (param) {
|
||||
return Jest.Expect.toEqual(2, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.foldr, (function (x, acc) {
|
||||
return (x << 1) + acc | 0;
|
||||
}), 2, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("foldl", (function (param) {
|
||||
Jest.test("folds the value from a Some into the default", (function (param) {
|
||||
return Jest.Expect.toEqual(8, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.foldl, (function (acc, x) {
|
||||
return (x << 1) + acc | 0;
|
||||
}), 2, 3)));
|
||||
}));
|
||||
return Jest.test("returns the initial value if its a None", (function (param) {
|
||||
return Jest.Expect.toEqual(2, Jest.Expect.expect(Curry._3(Ley_Option$OptolithClient.foldl, (function (acc, x) {
|
||||
return (x << 1) + acc | 0;
|
||||
}), 2, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("toList", (function (param) {
|
||||
Jest.test("returns a singleton list with the value from the Some", (function (param) {
|
||||
return Jest.Expect.toEqual({
|
||||
hd: 3,
|
||||
tl: /* [] */0
|
||||
}, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.toList, 3)));
|
||||
}));
|
||||
return Jest.test("returns an empty list if the value is None", (function (param) {
|
||||
return Jest.Expect.toEqual(/* [] */0, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.toList, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("null", (function (param) {
|
||||
Jest.test("returns true if its a Some", (function (param) {
|
||||
return Jest.Expect.toBe(false, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.$$null, 3)));
|
||||
}));
|
||||
return Jest.test("returns false if its a None", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.$$null, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("length", (function (param) {
|
||||
Jest.test("returns 1 if its a Some", (function (param) {
|
||||
return Jest.Expect.toBe(1, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.length, 3)));
|
||||
}));
|
||||
return Jest.test("returns 0 if its a None", (function (param) {
|
||||
return Jest.Expect.toBe(0, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.length, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("elem", (function (param) {
|
||||
Jest.test("returns if the value is a None", (function (param) {
|
||||
return Jest.Expect.toBe(false, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.elem, 3, undefined)));
|
||||
}));
|
||||
Jest.test("returns if the search value does not equal the value in the Some", (function (param) {
|
||||
return Jest.Expect.toBe(false, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.elem, 3, 2)));
|
||||
}));
|
||||
return Jest.test("returns if the search value equals the value in the Some", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.elem, 3, 3)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("sum", (function (param) {
|
||||
Jest.test("returns the value in the Some if its a Some", (function (param) {
|
||||
return Jest.Expect.toBe(3, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.sum, 3)));
|
||||
}));
|
||||
return Jest.test("returns 0 if its a None", (function (param) {
|
||||
return Jest.Expect.toBe(0, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.sum, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("maximum", (function (param) {
|
||||
Jest.test("returns the value in the Some if its a Some", (function (param) {
|
||||
return Jest.Expect.toBe(3, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.maximum, 3)));
|
||||
}));
|
||||
return Jest.test("returns the minimum possible integer if its a None", (function (param) {
|
||||
return Jest.Expect.toBe(Js_int.min, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.maximum, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("minimum", (function (param) {
|
||||
Jest.test("returns the value in the Some if its a Some", (function (param) {
|
||||
return Jest.Expect.toBe(3, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.minimum, 3)));
|
||||
}));
|
||||
return Jest.test("returns the maximum possible integer if its a None", (function (param) {
|
||||
return Jest.Expect.toBe(Js_int.max, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.minimum, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("concat", (function (param) {
|
||||
Jest.test("returns the list in the Some if its a Some", (function (param) {
|
||||
return Jest.Expect.toEqual({
|
||||
hd: 1,
|
||||
tl: {
|
||||
hd: 2,
|
||||
tl: {
|
||||
hd: 3,
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.concat, {
|
||||
hd: 1,
|
||||
tl: {
|
||||
hd: 2,
|
||||
tl: {
|
||||
hd: 3,
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
})));
|
||||
}));
|
||||
return Jest.test("returns an empty list if its a None", (function (param) {
|
||||
return Jest.Expect.toEqual(/* [] */0, Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.concat, undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("concatMap", (function (param) {
|
||||
Jest.test("returns the list in the Some if its a Some", (function (param) {
|
||||
return Jest.Expect.toEqual({
|
||||
hd: 3,
|
||||
tl: {
|
||||
hd: 6,
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.concatMap, (function (x) {
|
||||
return {
|
||||
hd: x,
|
||||
tl: {
|
||||
hd: (x << 1),
|
||||
tl: /* [] */0
|
||||
}
|
||||
};
|
||||
}), 3)));
|
||||
}));
|
||||
return Jest.test("returns an empty list if its a None", (function (param) {
|
||||
return Jest.Expect.toEqual(/* [] */0, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.concatMap, (function (x) {
|
||||
return {
|
||||
hd: x,
|
||||
tl: {
|
||||
hd: (x << 1),
|
||||
tl: /* [] */0
|
||||
}
|
||||
};
|
||||
}), undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("con", (function (param) {
|
||||
return Jest.testAll("returns the conjunction of an option and a boolean value", {
|
||||
hd: [
|
||||
true,
|
||||
true
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
false,
|
||||
false
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
undefined,
|
||||
true
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.con, param[0])));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("dis", (function (param) {
|
||||
return Jest.testAll("returns the disjunction of an option and a boolean value", {
|
||||
hd: [
|
||||
true,
|
||||
true
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
false,
|
||||
false
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
undefined,
|
||||
false
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Curry._1(Ley_Option$OptolithClient.dis, param[0])));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("any", (function (param) {
|
||||
Jest.testAll("returns if the predicate matches the value in the Some", {
|
||||
hd: [
|
||||
5,
|
||||
true
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
3,
|
||||
false
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.any, (function (e) {
|
||||
return e > 3;
|
||||
}), param[0])));
|
||||
}));
|
||||
return Jest.test("returns false if its a None", (function (param) {
|
||||
return Jest.Expect.toBe(false, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.any, (function (e) {
|
||||
return e > 3;
|
||||
}), undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("all", (function (param) {
|
||||
Jest.testAll("returns if the predicate matches the value in the Some", {
|
||||
hd: [
|
||||
5,
|
||||
true
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
3,
|
||||
false
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toBe(param[1], Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.all, (function (e) {
|
||||
return e > 3;
|
||||
}), param[0])));
|
||||
}));
|
||||
return Jest.test("returns true if its a None", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.all, (function (e) {
|
||||
return e > 3;
|
||||
}), undefined)));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("notElem", (function (param) {
|
||||
Jest.test("returns if the value is a None", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.notElem, 3, undefined)));
|
||||
}));
|
||||
Jest.test("returns if the search value does not equal the value in the Some", (function (param) {
|
||||
return Jest.Expect.toBe(true, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.notElem, 3, 2)));
|
||||
}));
|
||||
return Jest.test("returns if the search value equals the value in the Some", (function (param) {
|
||||
return Jest.Expect.toBe(false, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.notElem, 3, 3)));
|
||||
}));
|
||||
}));
|
||||
return Jest.describe("find", (function (param) {
|
||||
Jest.testAll("returns the option if the predicate matches the value in the Some", {
|
||||
hd: [
|
||||
5,
|
||||
5
|
||||
],
|
||||
tl: {
|
||||
hd: [
|
||||
3,
|
||||
undefined
|
||||
],
|
||||
tl: /* [] */0
|
||||
}
|
||||
}, (function (param) {
|
||||
return Jest.Expect.toEqual(param[1], Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.find, (function (e) {
|
||||
return e > 3;
|
||||
}), param[0])));
|
||||
}));
|
||||
return Jest.test("returns None if its a None", (function (param) {
|
||||
return Jest.Expect.toEqual(undefined, Jest.Expect.expect(Curry._2(Ley_Option$OptolithClient.find, (function (e) {
|
||||
return e > 3;
|
||||
}), undefined)));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
/* Not a pure module */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
|
||||
var Ley_Ord$OptolithClient = require("../Ley_Ord.bs.js");
|
||||
|
||||
Jest.describe("toOrdering", (function (param) {
|
||||
Jest.test("returns GT for a positive integer", (function (param) {
|
||||
return Jest.Expect.toBe(/* GT */2, Jest.Expect.expect(Ley_Ord$OptolithClient.toOrdering(2)));
|
||||
}));
|
||||
Jest.test("returns EQ for a 0", (function (param) {
|
||||
return Jest.Expect.toBe(/* EQ */1, Jest.Expect.expect(Ley_Ord$OptolithClient.toOrdering(0)));
|
||||
}));
|
||||
return Jest.test("returns LT for a negative integer", (function (param) {
|
||||
return Jest.Expect.toBe(/* LT */0, Jest.Expect.expect(Ley_Ord$OptolithClient.toOrdering(-3)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("fromOrdering", (function (param) {
|
||||
Jest.test("returns -1 for LT", (function (param) {
|
||||
return Jest.Expect.toBe(-1, Jest.Expect.expect(Ley_Ord$OptolithClient.fromOrdering(/* LT */0)));
|
||||
}));
|
||||
Jest.test("returns 0 for EQ", (function (param) {
|
||||
return Jest.Expect.toBe(0, Jest.Expect.expect(Ley_Ord$OptolithClient.fromOrdering(/* EQ */1)));
|
||||
}));
|
||||
return Jest.test("returns 1 for GT", (function (param) {
|
||||
return Jest.Expect.toBe(1, Jest.Expect.expect(Ley_Ord$OptolithClient.fromOrdering(/* GT */2)));
|
||||
}));
|
||||
}));
|
||||
|
||||
/* Not a pure module */
|
||||
@@ -0,0 +1,31 @@
|
||||
open Jest;
|
||||
open Expect;
|
||||
open Ley_Ord;
|
||||
|
||||
describe("toOrdering", () => {
|
||||
test("returns GT for a positive integer", () =>
|
||||
expect(toOrdering(2)) |> toBe(GT)
|
||||
);
|
||||
|
||||
test("returns EQ for a 0", () =>
|
||||
expect(toOrdering(0)) |> toBe(EQ)
|
||||
);
|
||||
|
||||
test("returns LT for a negative integer", () =>
|
||||
expect(toOrdering(-3)) |> toBe(LT)
|
||||
);
|
||||
});
|
||||
|
||||
describe("fromOrdering", () => {
|
||||
test("returns -1 for LT", () =>
|
||||
expect(fromOrdering(LT)) |> toBe(-1)
|
||||
);
|
||||
|
||||
test("returns 0 for EQ", () =>
|
||||
expect(fromOrdering(EQ)) |> toBe(0)
|
||||
);
|
||||
|
||||
test("returns 1 for GT", () =>
|
||||
expect(fromOrdering(GT)) |> toBe(1)
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||
'use strict';
|
||||
|
||||
var Jest = require("@glennsl/bs-jest/src/jest.bs.js");
|
||||
var Ley_Tuple$OptolithClient = require("../Ley_Tuple.bs.js");
|
||||
|
||||
Jest.describe("pair", (function (param) {
|
||||
return Jest.test("returns a pair of its arguments", (function (param) {
|
||||
return Jest.Expect.toEqual([
|
||||
2,
|
||||
3
|
||||
], Jest.Expect.expect(Ley_Tuple$OptolithClient.pair(2, 3)));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("Bifunctor", (function (param) {
|
||||
Jest.describe("bimap", (function (param) {
|
||||
return Jest.test("maps over both values of the pair", (function (param) {
|
||||
return Jest.Expect.toEqual([
|
||||
5,
|
||||
4
|
||||
], Jest.Expect.expect(Ley_Tuple$OptolithClient.Bifunctor.bimap((function (a) {
|
||||
return a + 2 | 0;
|
||||
}), (function (b) {
|
||||
return b + 3 | 0;
|
||||
}), [
|
||||
3,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
Jest.describe("first", (function (param) {
|
||||
return Jest.test("maps over the first value of the pair", (function (param) {
|
||||
return Jest.Expect.toEqual([
|
||||
5,
|
||||
1
|
||||
], Jest.Expect.expect(Ley_Tuple$OptolithClient.Bifunctor.first((function (a) {
|
||||
return a + 2 | 0;
|
||||
}), [
|
||||
3,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
return Jest.describe("second", (function (param) {
|
||||
return Jest.test("maps over the second value of the pair", (function (param) {
|
||||
return Jest.Expect.toEqual([
|
||||
3,
|
||||
4
|
||||
], Jest.Expect.expect(Ley_Tuple$OptolithClient.Bifunctor.second((function (b) {
|
||||
return b + 3 | 0;
|
||||
}), [
|
||||
3,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("fst", (function (param) {
|
||||
return Jest.test("returns the first element of the pair", (function (param) {
|
||||
return Jest.Expect.toBe(3, Jest.Expect.expect(Ley_Tuple$OptolithClient.fst([
|
||||
3,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("snd", (function (param) {
|
||||
return Jest.test("returns the second element of the pair", (function (param) {
|
||||
return Jest.Expect.toBe(1, Jest.Expect.expect(Ley_Tuple$OptolithClient.snd([
|
||||
3,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
|
||||
Jest.describe("swap", (function (param) {
|
||||
return Jest.test("swaps the elements of the pair", (function (param) {
|
||||
return Jest.Expect.toEqual([
|
||||
1,
|
||||
3
|
||||
], Jest.Expect.expect(Ley_Tuple$OptolithClient.swap([
|
||||
3,
|
||||
1
|
||||
])));
|
||||
}));
|
||||
}));
|
||||
|
||||
/* Not a pure module */
|
||||
@@ -0,0 +1,49 @@
|
||||
open Jest;
|
||||
open Expect;
|
||||
open Ley_Tuple;
|
||||
|
||||
describe("pair", () => {
|
||||
test("returns a pair of its arguments", () =>
|
||||
expect(pair(2, 3)) |> toEqual((2, 3))
|
||||
)
|
||||
});
|
||||
|
||||
describe("Bifunctor", () => {
|
||||
open Bifunctor;
|
||||
|
||||
describe("bimap", () => {
|
||||
test("maps over both values of the pair", () =>
|
||||
expect(bimap(a => a + 2, b => b + 3, (3, 1))) |> toEqual((5, 4))
|
||||
)
|
||||
});
|
||||
|
||||
describe("first", () => {
|
||||
test("maps over the first value of the pair", () =>
|
||||
expect(first(a => a + 2, (3, 1))) |> toEqual((5, 1))
|
||||
)
|
||||
});
|
||||
|
||||
describe("second", () => {
|
||||
test("maps over the second value of the pair", () =>
|
||||
expect(second(b => b + 3, (3, 1))) |> toEqual((3, 4))
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
describe("fst", () => {
|
||||
test("returns the first element of the pair", () =>
|
||||
expect(fst((3, 1))) |> toBe(3)
|
||||
)
|
||||
});
|
||||
|
||||
describe("snd", () => {
|
||||
test("returns the second element of the pair", () =>
|
||||
expect(snd((3, 1))) |> toBe(1)
|
||||
)
|
||||
});
|
||||
|
||||
describe("swap", () => {
|
||||
test("swaps the elements of the pair", () =>
|
||||
expect(swap((3, 1))) |> toEqual((1, 3))
|
||||
)
|
||||
});
|
||||
@@ -1,914 +0,0 @@
|
||||
import React from "react"
|
||||
import { fmap } from "../Functor"
|
||||
import { Internals } from "../Internals"
|
||||
import { List } from "../List"
|
||||
import { Just, Maybe } from "../Maybe"
|
||||
import { add } from "../Num"
|
||||
|
||||
const { Nothing } = Internals
|
||||
|
||||
// CONSTRUCTORS
|
||||
|
||||
test ("Just", () => {
|
||||
expect (Just (3) .value) .toEqual (3)
|
||||
expect (Just (3) .isJust) .toEqual (true)
|
||||
expect (Just (3) .isNothing) .toEqual (false)
|
||||
})
|
||||
|
||||
test ("Nothing", () => {
|
||||
expect (Nothing .isJust) .toEqual (false)
|
||||
expect (Nothing .isNothing) .toEqual (true)
|
||||
})
|
||||
|
||||
test ("Maybe", () => {
|
||||
expect (Maybe (3)) .toEqual (Just (3))
|
||||
expect (Maybe (undefined)) .toEqual (Nothing)
|
||||
expect (Maybe (null)) .toEqual (Nothing)
|
||||
})
|
||||
|
||||
// MAYBE FUNCTIONS (PART 1)
|
||||
|
||||
test ("isJust", () => {
|
||||
expect (Maybe.isJust (Maybe (3)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.isJust (Maybe (null)))
|
||||
.toBeFalsy ()
|
||||
})
|
||||
|
||||
test ("isNothing", () => {
|
||||
expect (Maybe.isNothing (Maybe (3)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.isNothing (Maybe (null)))
|
||||
.toBeTruthy ()
|
||||
})
|
||||
|
||||
test ("fromJust", () => {
|
||||
expect (Maybe.fromJust (Maybe (3) as Just<number>))
|
||||
.toEqual (3)
|
||||
expect (() => Maybe.fromJust (Maybe (null) as Just<null>))
|
||||
.toThrow ()
|
||||
})
|
||||
|
||||
test ("fromMaybe", () => {
|
||||
expect (Maybe.fromMaybe (0) (Maybe (3)))
|
||||
.toEqual (3)
|
||||
expect (Maybe.fromMaybe (0) (Maybe (null) as Maybe<number>))
|
||||
.toEqual (0)
|
||||
})
|
||||
|
||||
test ("fromMaybe_", () => {
|
||||
expect (Maybe.fromMaybe_ (() => 0) (Maybe (3)))
|
||||
.toEqual (3)
|
||||
expect (Maybe.fromMaybe_ (() => 0) (Maybe (null) as Maybe<number>))
|
||||
.toEqual (0)
|
||||
})
|
||||
|
||||
// APPLICATIVE
|
||||
|
||||
test ("pure", () => {
|
||||
expect (Maybe.pure (2)) .toEqual (Just (2))
|
||||
})
|
||||
|
||||
test ("ap", () => {
|
||||
expect (Maybe.ap (Just ((x: number) => x * 2)) (Just (3)))
|
||||
.toEqual (Just (6))
|
||||
expect (Maybe.ap (Just ((x: number) => x * 2)) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.ap (Nothing) (Just (3)))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.ap (Nothing) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
// ALTERNATIVE
|
||||
|
||||
test ("alt", () => {
|
||||
expect (Maybe.alt (Just (3)) (Just (2)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.alt (Just (3)) (Nothing))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.alt (Nothing) (Just (2)))
|
||||
.toEqual (Just (2))
|
||||
expect (Maybe.alt (Nothing) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("alt_", () => {
|
||||
expect (Maybe.alt_ (Just (3)) (() => Just (2)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.alt_ (Just (3)) (() => Nothing))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.alt_ (Nothing) (() => Just (2)))
|
||||
.toEqual (Just (2))
|
||||
expect (Maybe.alt_ (Nothing) (() => Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("altF", () => {
|
||||
expect (Maybe.altF (Just (2)) (Just (3)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.altF (Nothing) (Just (3)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.altF (Just (2)) (Nothing))
|
||||
.toEqual (Just (2))
|
||||
expect (Maybe.altF (Nothing) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("altF_", () => {
|
||||
expect (Maybe.altF_ (() => Just (2)) (Just (3)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.altF_ (() => Nothing) (Just (3)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.altF_ (() => Just (2)) (Nothing))
|
||||
.toEqual (Just (2))
|
||||
expect (Maybe.altF_ (() => Nothing) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("empty", () => {
|
||||
expect (Maybe.empty) .toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("guard", () => {
|
||||
expect (Maybe.guard (true))
|
||||
.toEqual (Just (undefined))
|
||||
expect (Maybe.guard (false))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
// MONAD
|
||||
|
||||
test ("bind", () => {
|
||||
expect (Maybe.bind (Maybe (3))
|
||||
(x => Just (x * 2)))
|
||||
.toEqual (Just (6))
|
||||
expect (Maybe.bind (Maybe (null) as Maybe<number>)
|
||||
(x => Just (x * 2)))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("bindF", () => {
|
||||
expect (Maybe.bindF ((x: number) => Just (x * 2))
|
||||
(Maybe (3)))
|
||||
.toEqual (Just (6))
|
||||
expect (Maybe.bindF ((x: number) => Just (x * 2))
|
||||
(Maybe (null) as Maybe<number>))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("then", () => {
|
||||
expect (Maybe.then (Just (3)) (Just (2)))
|
||||
.toEqual (Just (2))
|
||||
expect (Maybe.then (Nothing) (Maybe.Just (2)))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.then (Just (3)) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.then (Nothing) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("kleisli", () => {
|
||||
expect (Maybe.kleisli ((x: number) => x > 5 ? Nothing : Just (x))
|
||||
(x => x < 0 ? Nothing : Just (x))
|
||||
(2))
|
||||
.toEqual (Just (2))
|
||||
expect (Maybe.kleisli ((x: number) => x > 5 ? Nothing : Just (x))
|
||||
(x => x < 0 ? Nothing : Just (x))
|
||||
(6))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.kleisli ((x: number) => x > 5 ? Nothing : Just (x))
|
||||
(x => x < 0 ? Nothing : Just (x))
|
||||
(-1))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("join", () => {
|
||||
expect (Maybe.join (Just (Just (3))))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.join (Just (Nothing)))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.join (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("mapM", () => {
|
||||
expect (
|
||||
Maybe.mapM ((x: number) => x === 2 ? Nothing : Just (x + 1))
|
||||
(List.empty)
|
||||
)
|
||||
.toEqual (Just (List.empty))
|
||||
|
||||
expect (
|
||||
Maybe.mapM ((x: number) => x === 2 ? Nothing : Just (x + 1))
|
||||
(List (1, 3))
|
||||
)
|
||||
.toEqual (Just (List (2, 4)))
|
||||
|
||||
expect (
|
||||
Maybe.mapM ((x: number) => x === 2 ? Nothing : Just (x + 1))
|
||||
(List (1, 2, 3))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("liftM2", () => {
|
||||
expect (Maybe.liftM2 ((x: number) => (y: number) => x + y) (Just (1)) (Just (2)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.liftM2 ((x: number) => (y: number) => x + y) (Nothing) (Just (2)))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.liftM2 ((x: number) => (y: number) => x + y) (Just (1)) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.liftM2 ((x: number) => (y: number) => x + y) (Nothing) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("liftM3", () => {
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Just (1))
|
||||
(Just (2))
|
||||
(Just (3))
|
||||
)
|
||||
.toEqual (Just (6))
|
||||
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Nothing)
|
||||
(Just (2))
|
||||
(Just (3))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Just (1))
|
||||
(Nothing)
|
||||
(Just (3))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Just (1))
|
||||
(Just (2))
|
||||
(Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Just (1))
|
||||
(Nothing)
|
||||
(Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Nothing)
|
||||
(Just (2))
|
||||
(Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Nothing)
|
||||
(Nothing)
|
||||
(Just (3))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM3 ((x: number) => (y: number) => (z: number) => x + y + z)
|
||||
(Nothing)
|
||||
(Nothing)
|
||||
(Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("liftM4", () => {
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Just (2)) (Just (3)) (Just (4))
|
||||
)
|
||||
.toEqual (Just (10))
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Just (2)) (Just (3)) (Just (4))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Nothing) (Just (3)) (Just (4))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Just (2)) (Nothing) (Just (4))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Just (2)) (Just (3)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Just (2)) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Nothing) (Just (3)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Nothing) (Nothing) (Just (4))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Just (2)) (Just (3)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Just (2)) (Nothing) (Just (4))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Nothing) (Just (3)) (Just (4))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Just (1)) (Nothing) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Just (2)) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Nothing) (Just (3)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Nothing) (Nothing) (Just (4))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM4 ((x: number) => (y: number) => (z: number) => (a: number) => x + y + z + a)
|
||||
(Nothing) (Nothing) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("liftM5", () => {
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Just (3)) (Just (4)) (Just (5))
|
||||
)
|
||||
.toEqual (Just (15))
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Just (2)) (Just (3)) (Just (4)) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Just (3)) (Just (4)) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Nothing) (Just (4)) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Just (3)) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Just (3)) (Just (4)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Just (3)) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Nothing) (Just (4)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Just (3)) (Just (4)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Just (2)) (Just (3)) (Just (4)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Nothing) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Just (3)) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Just (2)) (Just (3)) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Nothing) (Just (4)) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Just (2)) (Nothing) (Just (4)) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Nothing) (Nothing) (Just (4)) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Nothing) (Just (3)) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Nothing) (Just (3)) (Just (4)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Nothing) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Nothing) (Just (4)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Just (2)) (Nothing) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Just (3)) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Just (2)) (Just (3)) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Just (2)) (Nothing) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Just (1)) (Nothing) (Nothing) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Just (2)) (Nothing) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Nothing) (Just (3)) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Nothing) (Nothing) (Just (4)) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Nothing) (Nothing) (Nothing) (Just (5))
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
|
||||
expect (
|
||||
Maybe.liftM5 ((x: number) => (y: number) => (z: number) => (a: number) => (b: number) =>
|
||||
x + y + z + a + b)
|
||||
(Nothing) (Nothing) (Nothing) (Nothing) (Nothing)
|
||||
)
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
// FOLDABLE
|
||||
|
||||
test ("foldr", () => {
|
||||
expect (Maybe.foldr ((x: number) => (acc: number) => x * 2 + acc) (2) (Just (3)))
|
||||
.toEqual (8)
|
||||
expect (Maybe.foldr ((x: number) => (acc: number) => x * 2 + acc) (2) (Nothing))
|
||||
.toEqual (2)
|
||||
})
|
||||
|
||||
test ("foldl", () => {
|
||||
expect (Maybe.foldl ((acc: number) => (x: number) => x * 2 + acc) (2) (Just (3)))
|
||||
.toEqual (8)
|
||||
expect (Maybe.foldl ((acc: number) => (x: number) => x * 2 + acc) (2) (Nothing))
|
||||
.toEqual (2)
|
||||
})
|
||||
|
||||
test ("toList", () => {
|
||||
expect (Maybe.toList (Just (3)))
|
||||
.toEqual (List (3))
|
||||
expect (Maybe.toList (Nothing))
|
||||
.toEqual (List ())
|
||||
})
|
||||
|
||||
test ("fnull", () => {
|
||||
expect (Maybe.fnull (Just (3)))
|
||||
.toEqual (false)
|
||||
expect (Maybe.fnull (Nothing))
|
||||
.toEqual (true)
|
||||
})
|
||||
|
||||
test ("flength", () => {
|
||||
expect (Maybe.flength (Just (3)))
|
||||
.toEqual (1)
|
||||
expect (Maybe.flength (Nothing))
|
||||
.toEqual (0)
|
||||
})
|
||||
|
||||
test ("elem", () => {
|
||||
expect (Maybe.elem (3) (Nothing))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.elem (3) (Just (2)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.elem (3) (Just (3)))
|
||||
.toBeTruthy ()
|
||||
})
|
||||
|
||||
test ("elemF", () => {
|
||||
expect (Maybe.elemF (Nothing) (3))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.elemF (Just (2)) (3))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.elemF (Just (3)) (3))
|
||||
.toBeTruthy ()
|
||||
})
|
||||
|
||||
test ("sum", () => {
|
||||
expect (Maybe.sum (Just (3)))
|
||||
.toEqual (3)
|
||||
expect (Maybe.sum (Nothing))
|
||||
.toEqual (0)
|
||||
})
|
||||
|
||||
test ("product", () => {
|
||||
expect (Maybe.product (Just (3)))
|
||||
.toEqual (3)
|
||||
expect (Maybe.product (Nothing))
|
||||
.toEqual (1)
|
||||
})
|
||||
|
||||
test ("concat", () => {
|
||||
expect (Maybe.concat (Just (List (1, 2, 3))))
|
||||
.toEqual (List (1, 2, 3))
|
||||
expect (Maybe.concat (Nothing))
|
||||
.toEqual (List ())
|
||||
})
|
||||
|
||||
test ("concatMap", () => {
|
||||
expect (Maybe.concatMap ((e: number) => List (e, e)) (Just (3)))
|
||||
.toEqual (List (3, 3))
|
||||
expect (Maybe.concatMap ((e: number) => List (e, e)) (Nothing))
|
||||
.toEqual (List ())
|
||||
})
|
||||
|
||||
test ("and", () => {
|
||||
expect (Maybe.and (Just (true)))
|
||||
.toEqual (true)
|
||||
expect (Maybe.and (Just (false)))
|
||||
.toEqual (false)
|
||||
expect (Maybe.and (Nothing))
|
||||
.toEqual (true)
|
||||
})
|
||||
|
||||
test ("or", () => {
|
||||
expect (Maybe.or (Just (true)))
|
||||
.toEqual (true)
|
||||
expect (Maybe.or (Just (false)))
|
||||
.toEqual (false)
|
||||
expect (Maybe.or (Nothing))
|
||||
.toEqual (false)
|
||||
})
|
||||
|
||||
test ("any", () => {
|
||||
expect (Maybe.any ((e: number) => e > 3) (Just (5)))
|
||||
.toEqual (true)
|
||||
expect (Maybe.any ((e: number) => e > 3) (Just (3)))
|
||||
.toEqual (false)
|
||||
expect (Maybe.any ((e: number) => e > 3) (Nothing))
|
||||
.toEqual (false)
|
||||
})
|
||||
|
||||
test ("all", () => {
|
||||
expect (Maybe.all ((e: number) => e > 3) (Just (5)))
|
||||
.toEqual (true)
|
||||
expect (Maybe.all ((e: number) => e > 3) (Just (3)))
|
||||
.toEqual (false)
|
||||
expect (Maybe.all ((e: number) => e > 3) (Nothing))
|
||||
.toEqual (true)
|
||||
})
|
||||
|
||||
test ("notElem", () => {
|
||||
expect (Maybe.notElem (3) (Nothing))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.notElem (3) (Just (2)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.notElem (3) (Just (3)))
|
||||
.toBeFalsy ()
|
||||
})
|
||||
|
||||
test ("find", () => {
|
||||
expect (Maybe.find ((e: number) => e > 3) (Just (5)))
|
||||
.toEqual (Just (5))
|
||||
expect (Maybe.find ((e: number) => e > 3) (Just (3)))
|
||||
.toEqual (Nothing)
|
||||
expect (Maybe.find ((e: number) => e > 3) (Nothing))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
// ORD
|
||||
|
||||
test ("gt", () => {
|
||||
expect (Maybe.gt (Just (1)) (Just (2)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.gt (Just (1)) (Just (1)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.gt (Just (1)) (Nothing))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.gt (Nothing) (Just (2)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.gt (Nothing) (Nothing))
|
||||
.toBeFalsy ()
|
||||
})
|
||||
|
||||
test ("lt", () => {
|
||||
expect (Maybe.lt (Just (3)) (Just (2)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.lt (Just (1)) (Just (1)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.lt (Just (3)) (Nothing))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.lt (Nothing) (Just (2)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.lt (Nothing) (Nothing))
|
||||
.toBeFalsy ()
|
||||
})
|
||||
|
||||
test ("gte", () => {
|
||||
expect (Maybe.gte (Just (1)) (Just (2)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.gte (Just (2)) (Just (2)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.gte (Just (2)) (Just (1)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.gte (Just (1)) (Nothing))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.gte (Just (2)) (Nothing))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.gte (Nothing) (Just (2)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.gte (Nothing) (Nothing))
|
||||
.toBeFalsy ()
|
||||
})
|
||||
|
||||
test ("lte", () => {
|
||||
expect (Maybe.lte (Just (3)) (Just (2)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.lte (Just (2)) (Just (2)))
|
||||
.toBeTruthy ()
|
||||
expect (Maybe.lte (Just (2)) (Just (3)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.lte (Just (3)) (Nothing))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.lte (Just (2)) (Nothing))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.lte (Nothing) (Just (2)))
|
||||
.toBeFalsy ()
|
||||
expect (Maybe.lte (Nothing) (Nothing))
|
||||
.toBeFalsy ()
|
||||
})
|
||||
|
||||
// SEMIGROUP
|
||||
|
||||
// test('mappend', () => {
|
||||
// expect(Just (List(3)).mappend(Just (List(2))))
|
||||
// .toEqual(Just (List(3, 2)))
|
||||
// expect(Just (List(3)).mappend(Nothing))
|
||||
// .toEqual(Just (List(3)))
|
||||
// expect(Nothing.mappend(Just (List(2))))
|
||||
// .toEqual(Nothing)
|
||||
// expect(Nothing.mappend(Nothing))
|
||||
// .toEqual(Nothing)
|
||||
// })
|
||||
|
||||
// MAYBE FUNCTIONS (PART 2)
|
||||
|
||||
test ("maybe", () => {
|
||||
expect (Maybe.maybe (0) ((x: number) => x * 2) (Just (3)))
|
||||
.toEqual (6)
|
||||
expect (Maybe.maybe (0) ((x: number) => x * 2) (Nothing))
|
||||
.toEqual (0)
|
||||
})
|
||||
|
||||
test ("listToMaybe", () => {
|
||||
expect (Maybe.listToMaybe (List (3)))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.listToMaybe (List ()))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("maybeToList", () => {
|
||||
expect (Maybe.maybeToList (Just (3)))
|
||||
.toEqual (List (3))
|
||||
expect (Maybe.maybeToList (Nothing))
|
||||
.toEqual (List ())
|
||||
})
|
||||
|
||||
test ("catMaybes", () => {
|
||||
expect (Maybe.catMaybes (List<Maybe<number>> (Just (3), Just (2), Nothing, Just (1))))
|
||||
.toEqual (List (3, 2, 1))
|
||||
})
|
||||
|
||||
test ("mapMaybe", () => {
|
||||
expect (Maybe.mapMaybe (Maybe.ensure ((x: number) => x > 2)) (List (1, 2, 3, 4, 5)))
|
||||
.toEqual (List (3, 4, 5))
|
||||
})
|
||||
|
||||
// CUSTOM MAYBE FUNCTIONS
|
||||
|
||||
test ("isMaybe", () => {
|
||||
expect (Maybe.isMaybe (4)) .toEqual (false)
|
||||
expect (Maybe.isMaybe (Just (4))) .toEqual (true)
|
||||
expect (Maybe.isMaybe (Nothing)) .toEqual (true)
|
||||
})
|
||||
|
||||
test ("normalize", () => {
|
||||
expect (Maybe.normalize (4)) .toEqual (Just (4))
|
||||
expect (Maybe.normalize (Just (4))) .toEqual (Just (4))
|
||||
expect (Maybe.normalize (Nothing)) .toEqual (Nothing)
|
||||
expect (Maybe.normalize (undefined)) .toEqual (Nothing)
|
||||
expect (Maybe.normalize (null)) .toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("ensure", () => {
|
||||
expect (Maybe.ensure ((x: number) => x > 2) (3))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.ensure ((x: number) => x > 3) (3))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("imapMaybe", () => {
|
||||
expect (Maybe.imapMaybe (i => (e: number) => fmap (add (i))
|
||||
(Maybe.ensure ((x: number) => x > 2) (e)))
|
||||
(List (1, 2, 3, 4, 5)))
|
||||
.toEqual (List (5, 7, 9))
|
||||
})
|
||||
|
||||
test ("maybeToNullable", () => {
|
||||
const element = React.createElement ("div")
|
||||
expect (Maybe.maybeToNullable (Nothing)) .toEqual (null)
|
||||
expect (Maybe.maybeToNullable (Just (element))) .toEqual (element)
|
||||
})
|
||||
|
||||
test ("maybeToUndefined", () => {
|
||||
const element = React.createElement ("div")
|
||||
expect (Maybe.maybeToUndefined (Nothing)) .toEqual (undefined)
|
||||
expect (Maybe.maybeToUndefined (Just (element))) .toEqual (element)
|
||||
})
|
||||
|
||||
test ("maybe_", () => {
|
||||
expect (Maybe.maybe_ (() => 0) ((x: number) => x * 2) (Just (3)))
|
||||
.toEqual (6)
|
||||
expect (Maybe.maybe_ (() => 0) ((x: number) => x * 2) (Nothing))
|
||||
.toEqual (0)
|
||||
})
|
||||
|
||||
test ("joinMaybeList", () => {
|
||||
expect (Maybe.joinMaybeList (Just (List (1, 2, 3))))
|
||||
.toEqual (List (1, 2, 3))
|
||||
expect (Maybe.joinMaybeList (Nothing))
|
||||
.toEqual (List ())
|
||||
})
|
||||
|
||||
test ("guardReplace", () => {
|
||||
expect (Maybe.guardReplace (true) (3))
|
||||
.toEqual (Just (3))
|
||||
expect (Maybe.guardReplace (false) (3))
|
||||
.toEqual (Nothing)
|
||||
})
|
||||
|
||||
test ("orN", () => {
|
||||
expect (Maybe.orN (true)) .toEqual (true)
|
||||
expect (Maybe.orN (false)) .toEqual (false)
|
||||
expect (Maybe.orN (undefined)) .toEqual (false)
|
||||
})
|
||||
@@ -1,134 +0,0 @@
|
||||
import * as Num from "../Num"
|
||||
import { EQ, GT, LT } from "../Ord"
|
||||
import * as Tuple from "../Tuple"
|
||||
|
||||
test ("add", () => {
|
||||
expect (Num.add (1) (2)) .toEqual (3)
|
||||
})
|
||||
|
||||
test ("subtract", () => {
|
||||
expect (Num.subtract (1) (2)) .toEqual (-1)
|
||||
})
|
||||
|
||||
test ("subtractBy", () => {
|
||||
expect (Num.subtractBy (1) (2)) .toEqual (1)
|
||||
})
|
||||
|
||||
test ("subtractAbs", () => {
|
||||
expect (Num.subtractAbs (1) (2)) .toEqual (-1)
|
||||
expect (Num.subtractAbs (-1) (2)) .toEqual (1)
|
||||
expect (Num.subtractAbs (1) (-2)) .toEqual (3)
|
||||
expect (Num.subtractAbs (-1) (-2)) .toEqual (-3)
|
||||
})
|
||||
|
||||
test ("subtractAbsBy", () => {
|
||||
expect (Num.subtractAbsBy (1) (2)) .toEqual (1)
|
||||
expect (Num.subtractAbsBy (1) (-2)) .toEqual (-1)
|
||||
expect (Num.subtractAbsBy (-1) (2)) .toEqual (3)
|
||||
expect (Num.subtractAbsBy (-1) (-2)) .toEqual (-3)
|
||||
})
|
||||
|
||||
test ("multiply", () => {
|
||||
expect (Num.multiply (1) (2)) .toEqual (2)
|
||||
})
|
||||
|
||||
test ("divide", () => {
|
||||
expect (Num.divide (1) (2)) .toEqual (0.5)
|
||||
})
|
||||
|
||||
test ("divideBy", () => {
|
||||
expect (Num.divideBy (1) (2)) .toEqual (2)
|
||||
})
|
||||
|
||||
test ("compare", () => {
|
||||
expect (Num.compare (1) (2)) .toEqual (LT)
|
||||
expect (Num.compare (3) (2)) .toEqual (GT)
|
||||
expect (Num.compare (2) (2)) .toEqual (EQ)
|
||||
})
|
||||
|
||||
test ("lt", () => {
|
||||
expect (Num.lt (3) (5)) .toEqual (false)
|
||||
expect (Num.lt (3) (3)) .toEqual (false)
|
||||
expect (Num.lt (3) (1)) .toEqual (true)
|
||||
})
|
||||
|
||||
test ("lte", () => {
|
||||
expect (Num.lte (3) (5)) .toEqual (false)
|
||||
expect (Num.lte (3) (3)) .toEqual (true)
|
||||
expect (Num.lte (3) (1)) .toEqual (true)
|
||||
})
|
||||
|
||||
test ("gt", () => {
|
||||
expect (Num.gt (3) (5)) .toEqual (true)
|
||||
expect (Num.gt (3) (3)) .toEqual (false)
|
||||
expect (Num.gt (3) (1)) .toEqual (false)
|
||||
})
|
||||
|
||||
test ("gte", () => {
|
||||
expect (Num.gte (3) (5)) .toEqual (true)
|
||||
expect (Num.gte (3) (3)) .toEqual (true)
|
||||
expect (Num.gte (3) (1)) .toEqual (false)
|
||||
})
|
||||
|
||||
test ("max", () => {
|
||||
expect (Num.max (3) (5)) .toEqual (5)
|
||||
expect (Num.max (6) (5)) .toEqual (6)
|
||||
})
|
||||
|
||||
test ("min", () => {
|
||||
expect (Num.min (3) (5)) .toEqual (3)
|
||||
expect (Num.min (6) (5)) .toEqual (5)
|
||||
})
|
||||
|
||||
test ("minmax", () => {
|
||||
expect (Num.minmax (3) (5)) .toEqual (Tuple.Pair (3, 5))
|
||||
expect (Num.minmax (6) (5)) .toEqual (Tuple.Pair (5, 6))
|
||||
expect (Num.minmax (5) (5)) .toEqual (Tuple.Pair (5, 5))
|
||||
})
|
||||
|
||||
test ("inc", () => {
|
||||
expect (Num.inc (3)) .toEqual (4)
|
||||
expect (Num.inc (5)) .toEqual (6)
|
||||
})
|
||||
|
||||
test ("dec", () => {
|
||||
expect (Num.dec (3)) .toEqual (2)
|
||||
expect (Num.dec (5)) .toEqual (4)
|
||||
})
|
||||
|
||||
test ("negate", () => {
|
||||
expect (Num.negate (3)) .toEqual (-3)
|
||||
expect (Num.negate (-5)) .toEqual (5)
|
||||
})
|
||||
|
||||
test ("abs", () => {
|
||||
expect (Num.abs (3)) .toEqual (3)
|
||||
expect (Num.abs (0)) .toEqual (0)
|
||||
expect (Num.abs (-5)) .toEqual (5)
|
||||
})
|
||||
|
||||
test ("even", () => {
|
||||
expect (Num.even (1)) .toEqual (false)
|
||||
expect (Num.even (2)) .toEqual (true)
|
||||
})
|
||||
|
||||
test ("odd", () => {
|
||||
expect (Num.odd (1)) .toEqual (true)
|
||||
expect (Num.odd (2)) .toEqual (false)
|
||||
})
|
||||
|
||||
test ("gcd", () => {
|
||||
expect (Num.gcd (-3) (6)) .toEqual (3)
|
||||
expect (Num.gcd (-3) (-6)) .toEqual (3)
|
||||
expect (Num.gcd (12) (18)) .toEqual (6)
|
||||
expect (Num.gcd (0) (4)) .toEqual (4)
|
||||
expect (() => Num.gcd (0) (0)) .toThrow ()
|
||||
})
|
||||
|
||||
test ("lcm", () => {
|
||||
expect (Num.lcm (-3) (6)) .toEqual (-6)
|
||||
expect (Num.lcm (-3) (-6)) .toEqual (6)
|
||||
expect (Num.lcm (12) (18)) .toEqual (36)
|
||||
expect (Num.lcm (0) (4)) .toEqual (0)
|
||||
expect (() => Num.lcm (0) (0)) .toThrow ()
|
||||
})
|
||||
@@ -1,13 +0,0 @@
|
||||
import * as Ord from "../Ord"
|
||||
|
||||
test ("isLTorEQ", () => {
|
||||
expect (Ord.isLTorEQ (Ord.LT)) .toEqual (true)
|
||||
expect (Ord.isLTorEQ (Ord.GT)) .toEqual (false)
|
||||
expect (Ord.isLTorEQ (Ord.EQ)) .toEqual (true)
|
||||
})
|
||||
|
||||
test ("toOrdering", () => {
|
||||
expect (Ord.toOrdering (1)) .toEqual (Ord.GT)
|
||||
expect (Ord.toOrdering (0)) .toEqual (Ord.EQ)
|
||||
expect (Ord.toOrdering (-1)) .toEqual (Ord.LT)
|
||||
})
|
||||
@@ -1,141 +0,0 @@
|
||||
import { bimap, curry, first, fromArray, fst, isTuple, Pair, second, snd, swap, toArray, Tuple, uncurry } from "../Tuple"
|
||||
|
||||
// CONSTRUCTOR
|
||||
|
||||
describe ("Tuple ()", () => {
|
||||
it ("returns a Pair", () => {
|
||||
const pair = Tuple (3, 1)
|
||||
expect (pair .values [0]) .toEqual (3)
|
||||
expect (pair .values [1]) .toEqual (1)
|
||||
expect (pair .length) .toEqual (2)
|
||||
expect (pair .isTuple) .toEqual (true)
|
||||
})
|
||||
|
||||
it ("returns a Triple", () => {
|
||||
const pair = Tuple (3, 1, 2)
|
||||
expect (pair .values [0]) .toEqual (3)
|
||||
expect (pair .values [1]) .toEqual (1)
|
||||
expect (pair .values [2]) .toEqual (2)
|
||||
expect (pair .length) .toEqual (3)
|
||||
expect (pair .isTuple) .toEqual (true)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("Pair x y", () => {
|
||||
it ("returns a Pair when curried", () => {
|
||||
const pair = Pair (3) (1)
|
||||
expect (pair .values [0]) .toEqual (3)
|
||||
expect (pair .values [1]) .toEqual (1)
|
||||
expect (pair .isTuple) .toEqual (true)
|
||||
})
|
||||
|
||||
it ("returns a Pair when not curried", () => {
|
||||
const pair = Pair (3, 1)
|
||||
expect (pair .values [0]) .toEqual (3)
|
||||
expect (pair .values [1]) .toEqual (1)
|
||||
expect (pair .isTuple) .toEqual (true)
|
||||
})
|
||||
})
|
||||
|
||||
// BIFUNCTOR
|
||||
|
||||
describe ("bimap", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (bimap ((a: number) => a + 2) ((b: number) => b + 3) (Tuple (3, 1)))
|
||||
.toEqual (Tuple (5, 4))
|
||||
})
|
||||
|
||||
it ("throws if input is not a Pair", () => {
|
||||
// @ts-ignore
|
||||
expect (() => bimap ((a: number) => a + 2) ((b: number) => b + 3) (Tuple (3, 1, 2))) .toThrow ()
|
||||
})
|
||||
})
|
||||
|
||||
describe ("first", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (first ((a: number) => a + 2) (Tuple (3, 1))) .toEqual (Tuple (5, 1))
|
||||
})
|
||||
|
||||
it ("throws if input is not a Pair", () => {
|
||||
// @ts-ignore
|
||||
expect (() => first ((a: number) => a + 2) (Tuple (3, 1, 2))) .toThrow ()
|
||||
})
|
||||
})
|
||||
|
||||
describe ("second", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (second ((b: number) => b + 3) (Tuple (3, 1))) .toEqual (Tuple (3, 4))
|
||||
})
|
||||
|
||||
it ("throws if input is not a Pair", () => {
|
||||
// @ts-ignore
|
||||
expect (() => second ((b: number) => b + 3) (Tuple (3, 1, 2))) .toThrow ()
|
||||
})
|
||||
})
|
||||
|
||||
// PAIR FUNCTIONS
|
||||
|
||||
describe ("fst", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (fst (Tuple (3, 1))) .toEqual (3)
|
||||
})
|
||||
|
||||
it ("throws if input is not a Pair", () => {
|
||||
// @ts-ignore
|
||||
expect (() => fst (Tuple (3, 1, 2))) .toThrow ()
|
||||
})
|
||||
})
|
||||
|
||||
describe ("snd", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (snd (Tuple (3, 1))) .toEqual (1)
|
||||
})
|
||||
|
||||
it ("throws if input is not a Pair", () => {
|
||||
// @ts-ignore
|
||||
expect (() => snd (Tuple (3, 1, 2))) .toThrow ()
|
||||
})
|
||||
})
|
||||
|
||||
describe ("curry", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (curry ((p: Pair<number, number>) => fst (p) + snd (p)) (2) (3)) .toEqual (5)
|
||||
})
|
||||
})
|
||||
|
||||
describe ("uncurry", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (uncurry ((a: number) => (b: number) => a + b) (Tuple (2, 3))) .toEqual (5)
|
||||
})
|
||||
|
||||
it ("throws if input is not a Pair", () => {
|
||||
// @ts-ignore
|
||||
expect (() => uncurry ((a: number) => (b: number) => a + b) (Tuple (2, 3, 4))) .toThrow ()
|
||||
})
|
||||
})
|
||||
|
||||
describe ("swap", () => {
|
||||
it ("returns a Pair", () => {
|
||||
expect (swap (Tuple (3, 1))) .toEqual (Tuple (1, 3))
|
||||
})
|
||||
|
||||
it ("throws if input is not a Pair", () => {
|
||||
// @ts-ignore
|
||||
expect (() => swap (Tuple (3, 1, 2))) .toThrow ()
|
||||
})
|
||||
})
|
||||
|
||||
// CUSTOM FUNCTIONS
|
||||
|
||||
test ("toArray", () => {
|
||||
expect (toArray (Tuple (3, 1))) .toEqual ([ 3, 1 ])
|
||||
})
|
||||
|
||||
test ("fromArray", () => {
|
||||
expect (fromArray ([ 3, 1 ])) .toEqual (Tuple (3, 1))
|
||||
})
|
||||
|
||||
test ("isTuple", () => {
|
||||
expect (isTuple (Tuple (3, 1))) .toEqual (true)
|
||||
expect (isTuple (2)) .toEqual (false)
|
||||
})
|
||||
Reference in New Issue
Block a user