import "mocha"; import { expect } from "chai"; import { is } from "../helpers"; describe('Thunk factory "is.natural"', () => { it("recognizes natural numbers", () => { const thunk = is.natural(); const naturals = Array.from({ length: 10 }, (_, i) => i); // 0, 1, ... const invalid = naturals.map(n => ~n); // -1, -2, ... for (const value of naturals) expect(thunk(value)).to.be.true; for (const value of invalid) expect(thunk(value)).to.be.false; }); it("accepts optional flag, indicating naturalness of the zero", () => { expect(is.natural()(0)).to.be.true; expect(is.natural(true)(0)).to.be.true; expect(is.natural(false)(0)).to.be.false; }); });