import "mocha"; import { expect } from "chai"; import { is, infs } from '../helpers'; describe('Thunk factory "is.inRange"', () => { it("recognizes numbers within given range (inclusively)", () => { const thunk = is.inRange([ 0, 100 ]); const inside = [ 42, 17, 0, 100 ]; const outside = [ -42, -17, ...infs ]; for (const value of inside) expect(thunk(value)).to.be.true; for (const value of outside) expect(thunk(value)).to.be.false; }); it("recognizes numbers within given range (exclusively)", () => { const thunk = is.inRange([ 0, 1 ], false); const inside = [ .5, ...Array.from({ length: 5 }, Math.random) ]; const outside = [ 0, 1, ...infs ]; for (const value of inside) expect(thunk(value)).to.be.true; for (const value of outside) expect(thunk(value)).to.be.false; }); it("recognizes numbers within given range (using complex inclusiveness pattern)", () => { const range = [ 1, 4 ]; const lower = 1; const upper = 4; expect(is.inRange(range, [ true, true ])(lower)).to.be.true; expect(is.inRange(range, [ false, true ])(lower)).to.be.false; expect(is.inRange(range, [ true, true ])(upper)).to.be.true; expect(is.inRange(range, [ true, false ])(upper)).to.be.false; }); });