|
|
|
@ -1,5 +1,5 @@ |
|
|
|
import { describe, expect, it } from '@jest/globals'; |
|
|
|
import { describe, expect, it } from '@jest/globals'; |
|
|
|
import { toNative as $$, L, _, fromNative as __, undef } from '../src/core'; |
|
|
|
import { toNative as $$, L, _, fromNative as __, ___, undef } from '../src/core'; |
|
|
|
import { toNOrd as $o, NOrd } from '../src/ord'; |
|
|
|
import { toNOrd as $o, NOrd } from '../src/ord'; |
|
|
|
import { toBoolean as $b, iif } from '../src/bool'; |
|
|
|
import { toBoolean as $b, iif } from '../src/bool'; |
|
|
|
import { toNumber as $n, toNumber as $nn, Num, Succ, Zero, fromNumber as _n, fromNumber as _nn, cmp as cmpn, eq as eqn, even, gt as ngt, show as nshow, odd, succ, sum } from '../src/num'; |
|
|
|
import { toNumber as $n, toNumber as $nn, Num, Succ, Zero, fromNumber as _n, fromNumber as _nn, cmp as cmpn, eq as eqn, even, gt as ngt, show as nshow, odd, succ, sum } from '../src/num'; |
|
|
|
@ -8,13 +8,13 @@ import { toArray as $a, Cons, List, Nil, fromArray as _a, all, any, append, cmp, |
|
|
|
import { toString as $s } from '../src/string'; |
|
|
|
import { toString as $s } from '../src/string'; |
|
|
|
|
|
|
|
|
|
|
|
describe('List', () => { |
|
|
|
describe('List', () => { |
|
|
|
const infinite: List<Num> = iterate._(Succ)._(Zero); |
|
|
|
const infinite: List<Num> = iterate(Succ)(Zero); |
|
|
|
|
|
|
|
|
|
|
|
const _na: (xs: number[]) => List<Num> |
|
|
|
const _na: (xs: number[]) => List<Num> |
|
|
|
= xs => xs.length === 0 ? Nil : Cons._(_nn(xs[0]))._(new L(() => _na(xs.slice(1)).value)); |
|
|
|
= xs => xs.length === 0 ? Nil : Cons(_nn(xs[0]))(___(() => _na(xs.slice(1)).run())); |
|
|
|
|
|
|
|
|
|
|
|
const $na: (xs: List<Num>) => number[] |
|
|
|
const $na: (xs: List<Num>) => number[] |
|
|
|
= xs => $$(xs._(__([]))._(_(x => _(xs => __([$nn(x), ...$na(xs)]))))); |
|
|
|
= xs => $$(xs(__([]))(_(x => _(xs => __([$nn(x), ...$na(xs)]))))); |
|
|
|
|
|
|
|
|
|
|
|
describe('toArray', () => { |
|
|
|
describe('toArray', () => { |
|
|
|
it('converts []', () => { |
|
|
|
it('converts []', () => { |
|
|
|
@ -22,11 +22,11 @@ describe('List', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('converts [0]', () => { |
|
|
|
it('converts [0]', () => { |
|
|
|
expect($a(Cons._(_n(0))._(Nil)).map($n)).toEqual([0]); |
|
|
|
expect($a(Cons(_n(0))(Nil)).map($n)).toEqual([0]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('converts [0, 1]', () => { |
|
|
|
it('converts [0, 1]', () => { |
|
|
|
expect($a(Cons._(_n(0))._(Cons._(_n(1))._(Nil))).map($n)).toEqual([0, 1]); |
|
|
|
expect($a(Cons(_n(0))(Cons(_n(1))(Nil))).map($n)).toEqual([0, 1]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@ -46,669 +46,669 @@ describe('List', () => { |
|
|
|
|
|
|
|
|
|
|
|
describe('cons', () => { |
|
|
|
describe('cons', () => { |
|
|
|
it('0 cons Nil is [0]', () => { |
|
|
|
it('0 cons Nil is [0]', () => { |
|
|
|
expect($na(cons._(_n(0))._(Nil))).toEqual([0]); |
|
|
|
expect($na(cons(_n(0))(Nil))).toEqual([0]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('0 cons [1] is [0, 1]', () => { |
|
|
|
it('0 cons [1] is [0, 1]', () => { |
|
|
|
expect($na(cons._(_n(0))._(_na([1])))).toEqual([0, 1]); |
|
|
|
expect($na(cons(_n(0))(_na([1])))).toEqual([0, 1]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('0 cons [1, 2] is [0, 1, 2]', () => { |
|
|
|
it('0 cons [1, 2] is [0, 1, 2]', () => { |
|
|
|
expect($na(cons._(_n(0))._(_na([1, 2])))).toEqual([0, 1, 2]); |
|
|
|
expect($na(cons(_n(0))(_na([1, 2])))).toEqual([0, 1, 2]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(cons._(_n(0))._(infinite)._(undef)._(_(x => _(_xs => x))))).toBe(0); |
|
|
|
expect($n(cons(_n(0))(infinite)(undef)(_(x => _(_xs => x))))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('snoc', () => { |
|
|
|
describe('snoc', () => { |
|
|
|
it('Nil snoc 0 is [0]', () => { |
|
|
|
it('Nil snoc 0 is [0]', () => { |
|
|
|
expect($na(snoc._(Nil)._(_n(0)))).toEqual([0]); |
|
|
|
expect($na(snoc(Nil)(_n(0)))).toEqual([0]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1] snoc 0 is [1, 0]', () => { |
|
|
|
it('[1] snoc 0 is [1, 0]', () => { |
|
|
|
expect($na(snoc._(_na([1]))._(_n(0)))).toEqual([1, 0]); |
|
|
|
expect($na(snoc(_na([1]))(_n(0)))).toEqual([1, 0]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1, 2] snoc 0 is [1, 2, 0]', () => { |
|
|
|
it('[1, 2] snoc 0 is [1, 2, 0]', () => { |
|
|
|
expect($na(snoc._(_na([1, 2]))._(_n(0)))).toEqual([1, 2, 0]); |
|
|
|
expect($na(snoc(_na([1, 2]))(_n(0)))).toEqual([1, 2, 0]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(snoc._(infinite)._(_n(0))._(undef)._(_(x => _(_xs => x))))).toBe(0); |
|
|
|
expect($n(snoc(infinite)(_n(0))(undef)(_(x => _(_xs => x))))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('nul', () => { |
|
|
|
describe('nul', () => { |
|
|
|
it('nul Nil is True', () => { |
|
|
|
it('nul Nil is True', () => { |
|
|
|
expect($b(nul._(_na([])))).toEqual(true); |
|
|
|
expect($b(nul(_na([])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('nul [1] is False', () => { |
|
|
|
it('nul [1] is False', () => { |
|
|
|
expect($b(nul._(_na([1])))).toEqual(false); |
|
|
|
expect($b(nul(_na([1])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('nul [1, 2] is False', () => { |
|
|
|
it('nul [1, 2] is False', () => { |
|
|
|
expect($b(nul._(_na([1, 2])))).toEqual(false); |
|
|
|
expect($b(nul(_na([1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(nul._(infinite))).toEqual(false); |
|
|
|
expect($b(nul(infinite))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('len', () => { |
|
|
|
describe('len', () => { |
|
|
|
it('len Nil is 0', () => { |
|
|
|
it('len Nil is 0', () => { |
|
|
|
expect($n(len._(_na([])))).toEqual(0); |
|
|
|
expect($n(len(_na([])))).toEqual(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('len [1] is 1', () => { |
|
|
|
it('len [1] is 1', () => { |
|
|
|
expect($n(len._(_na([1])))).toEqual(1); |
|
|
|
expect($n(len(_na([1])))).toEqual(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('len [1, 2] is 2', () => { |
|
|
|
it('len [1, 2] is 2', () => { |
|
|
|
expect($n(len._(_na([1, 2])))).toEqual(2); |
|
|
|
expect($n(len(_na([1, 2])))).toEqual(2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(ngt._(len._(infinite))._(Zero))).toEqual(true); |
|
|
|
expect($b(ngt(len(infinite))(Zero))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('append', () => { |
|
|
|
describe('append', () => { |
|
|
|
it('Nil append Nil is Nil', () => { |
|
|
|
it('Nil append Nil is Nil', () => { |
|
|
|
expect($na(append._(Nil)._(Nil))).toEqual([]); |
|
|
|
expect($na(append(Nil)(Nil))).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0] append [1] is [0, 1]', () => { |
|
|
|
it('[0] append [1] is [0, 1]', () => { |
|
|
|
expect($na(append._(_na([0]))._(_na([1])))).toEqual([0, 1]); |
|
|
|
expect($na(append(_na([0]))(_na([1])))).toEqual([0, 1]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1] append [2, 3] is [0, 1, 2, 3]', () => { |
|
|
|
it('[0, 1] append [2, 3] is [0, 1, 2, 3]', () => { |
|
|
|
expect($na(append._(_na([0, 1]))._(_na([2, 3])))).toEqual([0, 1, 2, 3]); |
|
|
|
expect($na(append(_na([0, 1]))(_na([2, 3])))).toEqual([0, 1, 2, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(append._(infinite)._(infinite)._(undef)._(_(x => _(_xs => x))))).toBe(0); |
|
|
|
expect($n(append(infinite)(infinite)(undef)(_(x => _(_xs => x))))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('concat', () => { |
|
|
|
describe('concat', () => { |
|
|
|
it('concat [Nil, Nil, Nil] is Nil', () => { |
|
|
|
it('concat [Nil, Nil, Nil] is Nil', () => { |
|
|
|
expect($na(concat._(cons._(Nil)._(cons._(Nil)._(cons._(Nil)._(Nil)))))).toEqual([]); |
|
|
|
expect($na(concat(cons(Nil)(cons(Nil)(cons(Nil)(Nil)))))).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('concat [[0], [1], [2]] is [0, 1, 2]', () => { |
|
|
|
it('concat [[0], [1], [2]] is [0, 1, 2]', () => { |
|
|
|
expect($na(concat._(cons._(_na([0]))._(cons._(_na([1]))._(cons._(_na([2]))._(Nil)))))).toEqual([0, 1, 2]); |
|
|
|
expect($na(concat(cons(_na([0]))(cons(_na([1]))(cons(_na([2]))(Nil)))))).toEqual([0, 1, 2]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('concat [[0, 1], [2, 3], [4, 5]] is [0, 1, 2, 3, 4, 5]', () => { |
|
|
|
it('concat [[0, 1], [2, 3], [4, 5]] is [0, 1, 2, 3, 4, 5]', () => { |
|
|
|
expect($na(concat._(cons._(_na([0, 1]))._(cons._(_na([2, 3]))._(cons._(_na([4, 5]))._(Nil)))))).toEqual([0, 1, 2, 3, 4, 5]); |
|
|
|
expect($na(concat(cons(_na([0, 1]))(cons(_na([2, 3]))(cons(_na([4, 5]))(Nil)))))).toEqual([0, 1, 2, 3, 4, 5]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
const dinfinite: List<Num> = cons._(infinite)._(new L(() => dinfinite.value)); |
|
|
|
const dinfinite: List<Num> = cons(infinite)(___(() => dinfinite.run())); |
|
|
|
expect($n(concat._(dinfinite)._(undef)._(_(x => _(_xs => x))))).toBe(0); |
|
|
|
expect($n(concat(dinfinite)(undef)(_(x => _(_xs => x))))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// describe('repeat', () => {
|
|
|
|
// describe('repeat', () => {
|
|
|
|
// it('repeat 0 is [0, 0, 0, ...]', () => {
|
|
|
|
// it('repeat 0 is [0, 0, 0, ...]', () => {
|
|
|
|
// expect($na(
|
|
|
|
// expect($na(
|
|
|
|
// repeat._(_n(0))._<List<Num>>(_((x0: Num) => _((x1s: List<Num>) =>
|
|
|
|
// repeat(_n(0))<List<Num>>(_((x0: Num) => _((x1s: List<Num>) =>
|
|
|
|
// x1s._<List<Num>>(_((x1: Num) => _((x2s: List<Num>) =>
|
|
|
|
// x1s<List<Num>>(_((x1: Num) => _((x2s: List<Num>) =>
|
|
|
|
// x2s._<List<Num>>(_((x2: Num) => _((_xrs: List<Num>): List<Num> => cons._(x0)._(cons._(x1)._(cons._(x2)._(Nil)))))))))))))).toEqual([0, 0, 0]);
|
|
|
|
// x2s<List<Num>>(_((x2: Num) => _((_xrs: List<Num>): List<Num> => cons(x0)(cons(x1)(cons(x2)(Nil)))))))))))))).toEqual([0, 0, 0]);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
// describe('iterate', () => {
|
|
|
|
// describe('iterate', () => {
|
|
|
|
// it('iterate succ 0 is [0, 1, 2, ...]', () => {
|
|
|
|
// it('iterate succ 0 is [0, 1, 2, ...]', () => {
|
|
|
|
// expect($na(
|
|
|
|
// expect($na(
|
|
|
|
// iterate._(_n(0))._<List<Num>>(_((x0: Num) => _((x1s: List<Num>) =>
|
|
|
|
// iterate(_n(0))<List<Num>>(_((x0: Num) => _((x1s: List<Num>) =>
|
|
|
|
// x1s._<List<Num>>(_((x1: Num) => _((x2s: List<Num>) =>
|
|
|
|
// x1s<List<Num>>(_((x1: Num) => _((x2s: List<Num>) =>
|
|
|
|
// x2s._<List<Num>>(_((x2: Num) => _((_xrs: List<Num>): List<Num> => cons._(x0)._(cons._(x1)._(cons._(x2)._(Nil)))))))))))))).toEqual([0, 1, 2]);
|
|
|
|
// x2s<List<Num>>(_((x2: Num) => _((_xrs: List<Num>): List<Num> => cons(x0)(cons(x1)(cons(x2)(Nil)))))))))))))).toEqual([0, 1, 2]);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
describe('head', () => { |
|
|
|
describe('head', () => { |
|
|
|
it('returns nothing from Nil', () => { |
|
|
|
it('returns nothing from Nil', () => { |
|
|
|
expect(() => $$(head._(Nil))).toThrow(); |
|
|
|
expect(() => $$(head(Nil))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns only item', () => { |
|
|
|
it('returns only item', () => { |
|
|
|
expect($n(head._(_na([0])))).toBe(0); |
|
|
|
expect($n(head(_na([0])))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns first item', () => { |
|
|
|
it('returns first item', () => { |
|
|
|
expect($n(head._(_na([0, 1])))).toBe(0); |
|
|
|
expect($n(head(_na([0, 1])))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(head._(infinite))).toBe(0); |
|
|
|
expect($n(head(infinite))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('tail', () => { |
|
|
|
describe('tail', () => { |
|
|
|
it('drops nothing from Nil', () => { |
|
|
|
it('drops nothing from Nil', () => { |
|
|
|
expect(() => $na(tail._(Nil))).toThrow(); |
|
|
|
expect(() => $na(tail(Nil))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('drops only item', () => { |
|
|
|
it('drops only item', () => { |
|
|
|
expect($na(tail._(_na([0])))).toEqual([]); |
|
|
|
expect($na(tail(_na([0])))).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('drops first item', () => { |
|
|
|
it('drops first item', () => { |
|
|
|
expect($na(tail._(_na([0, 1])))).toEqual([1]); |
|
|
|
expect($na(tail(_na([0, 1])))).toEqual([1]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(head._(tail._(infinite)))).toBe(1); |
|
|
|
expect($n(head(tail(infinite)))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('foldl', () => { |
|
|
|
describe('foldl', () => { |
|
|
|
it('folds Nil', () => { |
|
|
|
it('folds Nil', () => { |
|
|
|
expect($n(foldl._(sum)._(Zero)._(_na([])))).toBe(0); |
|
|
|
expect($n(foldl(sum)(Zero)(_na([])))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('folds single item', () => { |
|
|
|
it('folds single item', () => { |
|
|
|
expect($n(foldl._(sum)._(Zero)._(_na([1])))).toBe(1); |
|
|
|
expect($n(foldl(sum)(Zero)(_na([1])))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('folds several items', () => { |
|
|
|
it('folds several items', () => { |
|
|
|
expect($n(foldl._(sum)._(Zero)._(_na([1, 2])))).toBe(3); |
|
|
|
expect($n(foldl(sum)(Zero)(_na([1, 2])))).toBe(3); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('foldlz', () => { |
|
|
|
describe('foldlz', () => { |
|
|
|
it('does not fold Nil', () => { |
|
|
|
it('does not fold Nil', () => { |
|
|
|
expect(() => $n(foldlz._(sum)._(Nil))).toThrow(); |
|
|
|
expect(() => $n(foldlz(sum)(Nil))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('folds single item', () => { |
|
|
|
it('folds single item', () => { |
|
|
|
expect($n(foldlz._(sum)._(_na([1])))).toBe(1); |
|
|
|
expect($n(foldlz(sum)(_na([1])))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('folds several items', () => { |
|
|
|
it('folds several items', () => { |
|
|
|
expect($n(foldlz._(sum)._(_na([1, 2])))).toBe(3); |
|
|
|
expect($n(foldlz(sum)(_na([1, 2])))).toBe(3); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('foldr', () => { |
|
|
|
describe('foldr', () => { |
|
|
|
it('folds Nil', () => { |
|
|
|
it('folds Nil', () => { |
|
|
|
expect($n(foldr._(sum)._(Zero)._(_na([])))).toBe(0); |
|
|
|
expect($n(foldr(sum)(Zero)(_na([])))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('folds single item', () => { |
|
|
|
it('folds single item', () => { |
|
|
|
expect($n(foldr._(sum)._(Zero)._(_na([1])))).toBe(1); |
|
|
|
expect($n(foldr(sum)(Zero)(_na([1])))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('folds several items', () => { |
|
|
|
it('folds several items', () => { |
|
|
|
expect($n(foldr._(sum)._(Zero)._(_na([1, 2])))).toBe(3); |
|
|
|
expect($n(foldr(sum)(Zero)(_na([1, 2])))).toBe(3); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n( |
|
|
|
expect($n( |
|
|
|
foldr |
|
|
|
foldr |
|
|
|
._(_(x => _(a => sum._(x)._(iif._(eqn._(_n(5))._(x))._(Zero)._(a))))) |
|
|
|
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a))))) |
|
|
|
._(Zero) |
|
|
|
(Zero) |
|
|
|
._(infinite))) |
|
|
|
(infinite))) |
|
|
|
.toBe(15); |
|
|
|
.toBe(15); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('foldrz', () => { |
|
|
|
describe('foldrz', () => { |
|
|
|
it('does not fold Nil', () => { |
|
|
|
it('does not fold Nil', () => { |
|
|
|
expect(() => $n(foldrz._(sum)._(Nil))).toThrow(); |
|
|
|
expect(() => $n(foldrz(sum)(Nil))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it.failing('folds single item', () => { |
|
|
|
it.failing('folds single item', () => { |
|
|
|
expect($n(foldrz._(sum)._(_na([1])))).toBe(1); |
|
|
|
expect($n(foldrz(sum)(_na([1])))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it.failing('folds several items', () => { |
|
|
|
it.failing('folds several items', () => { |
|
|
|
expect($n(foldrz._(sum)._(_na([1, 2])))).toBe(3); |
|
|
|
expect($n(foldrz(sum)(_na([1, 2])))).toBe(3); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it.failing('handles infinite lists', () => { |
|
|
|
it.failing('handles infinite lists', () => { |
|
|
|
expect($n( |
|
|
|
expect($n( |
|
|
|
foldrz |
|
|
|
foldrz |
|
|
|
._(_(x => _(a => sum._(x)._(iif._(eqn._(_n(5))._(x))._(Zero)._(a))))) |
|
|
|
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a))))) |
|
|
|
._(infinite))) |
|
|
|
(infinite))) |
|
|
|
.toBe(15); |
|
|
|
.toBe(15); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('cmp', () => { |
|
|
|
describe('cmp', () => { |
|
|
|
it('Nil cmp Nil is EQ', () => { |
|
|
|
it('Nil cmp Nil is EQ', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([]))._(_na([])))).toEqual(NOrd.EQ); |
|
|
|
expect($o(cmp(cmpn)(_na([]))(_na([])))).toEqual(NOrd.EQ); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Nil cmp [0, 1, 2] is LT', () => { |
|
|
|
it('Nil cmp [0, 1, 2] is LT', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([]))._(_na([0, 1, 2])))).toEqual(NOrd.LT); |
|
|
|
expect($o(cmp(cmpn)(_na([]))(_na([0, 1, 2])))).toEqual(NOrd.LT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] cmp Nil is GT', () => { |
|
|
|
it('[0, 1, 2] cmp Nil is GT', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([0, 1, 2]))._(_na([])))).toEqual(NOrd.GT); |
|
|
|
expect($o(cmp(cmpn)(_na([0, 1, 2]))(_na([])))).toEqual(NOrd.GT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0] cmp [0, 1, 2] is LT', () => { |
|
|
|
it('[0] cmp [0, 1, 2] is LT', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([0]))._(_na([0, 1, 2])))).toEqual(NOrd.LT); |
|
|
|
expect($o(cmp(cmpn)(_na([0]))(_na([0, 1, 2])))).toEqual(NOrd.LT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] cmp [0] is GT', () => { |
|
|
|
it('[0, 1, 2] cmp [0] is GT', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([0, 1, 2]))._(_na([0])))).toEqual(NOrd.GT); |
|
|
|
expect($o(cmp(cmpn)(_na([0, 1, 2]))(_na([0])))).toEqual(NOrd.GT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1, 2, 0] cmp [0, 1, 2] is GT', () => { |
|
|
|
it('[1, 2, 0] cmp [0, 1, 2] is GT', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([1, 2, 0]))._(_na([0, 1, 2])))).toEqual(NOrd.GT); |
|
|
|
expect($o(cmp(cmpn)(_na([1, 2, 0]))(_na([0, 1, 2])))).toEqual(NOrd.GT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] cmp [1, 2, 0] is LT', () => { |
|
|
|
it('[0, 1, 2] cmp [1, 2, 0] is LT', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([0, 1, 2]))._(_na([1, 2, 0])))).toEqual(NOrd.LT); |
|
|
|
expect($o(cmp(cmpn)(_na([0, 1, 2]))(_na([1, 2, 0])))).toEqual(NOrd.LT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] cmp [0, 1, 2] is EQ', () => { |
|
|
|
it('[0, 1, 2] cmp [0, 1, 2] is EQ', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([0, 1, 2]))._(_na([0, 1, 2])))).toEqual(NOrd.EQ); |
|
|
|
expect($o(cmp(cmpn)(_na([0, 1, 2]))(_na([0, 1, 2])))).toEqual(NOrd.EQ); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($o(cmp._(cmpn)._(_na([0, 1, 2]))._(infinite))).toEqual(NOrd.LT); |
|
|
|
expect($o(cmp(cmpn)(_na([0, 1, 2]))(infinite))).toEqual(NOrd.LT); |
|
|
|
expect($o(cmp._(cmpn)._(infinite)._(_na([0, 1, 2])))).toEqual(NOrd.GT); |
|
|
|
expect($o(cmp(cmpn)(infinite)(_na([0, 1, 2])))).toEqual(NOrd.GT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('lt', () => { |
|
|
|
describe('lt', () => { |
|
|
|
it('Nil lt Nil is False', () => { |
|
|
|
it('Nil lt Nil is False', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([]))._(_na([])))).toEqual(false); |
|
|
|
expect($b(lt(cmpn)(_na([]))(_na([])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Nil lt [0, 1, 2] is True', () => { |
|
|
|
it('Nil lt [0, 1, 2] is True', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(lt(cmpn)(_na([]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] lt Nil is False', () => { |
|
|
|
it('[0, 1, 2] lt Nil is False', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([0, 1, 2]))._(_na([])))).toEqual(false); |
|
|
|
expect($b(lt(cmpn)(_na([0, 1, 2]))(_na([])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0] lt [0, 1, 2] is True', () => { |
|
|
|
it('[0] lt [0, 1, 2] is True', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([0]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(lt(cmpn)(_na([0]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] lt [0] is False', () => { |
|
|
|
it('[0, 1, 2] lt [0] is False', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([0, 1, 2]))._(_na([0])))).toEqual(false); |
|
|
|
expect($b(lt(cmpn)(_na([0, 1, 2]))(_na([0])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1, 2, 0] lt [0, 1, 2] is False', () => { |
|
|
|
it('[1, 2, 0] lt [0, 1, 2] is False', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([1, 2, 0]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(lt(cmpn)(_na([1, 2, 0]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] lt [1, 2, 0] is True', () => { |
|
|
|
it('[0, 1, 2] lt [1, 2, 0] is True', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([0, 1, 2]))._(_na([1, 2, 0])))).toEqual(true); |
|
|
|
expect($b(lt(cmpn)(_na([0, 1, 2]))(_na([1, 2, 0])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] lt [0, 1, 2] is False', () => { |
|
|
|
it('[0, 1, 2] lt [0, 1, 2] is False', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([0, 1, 2]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(lt(cmpn)(_na([0, 1, 2]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(lt._(cmpn)._(_na([0, 1, 2]))._(infinite))).toEqual(true); |
|
|
|
expect($b(lt(cmpn)(_na([0, 1, 2]))(infinite))).toEqual(true); |
|
|
|
expect($b(lt._(cmpn)._(infinite)._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(lt(cmpn)(infinite)(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('le', () => { |
|
|
|
describe('le', () => { |
|
|
|
it('Nil le Nil is True', () => { |
|
|
|
it('Nil le Nil is True', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([]))._(_na([])))).toEqual(true); |
|
|
|
expect($b(le(cmpn)(_na([]))(_na([])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Nil le [0, 1, 2] is True', () => { |
|
|
|
it('Nil le [0, 1, 2] is True', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(le(cmpn)(_na([]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] le Nil is False', () => { |
|
|
|
it('[0, 1, 2] le Nil is False', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([0, 1, 2]))._(_na([])))).toEqual(false); |
|
|
|
expect($b(le(cmpn)(_na([0, 1, 2]))(_na([])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0] le [0, 1, 2] is True', () => { |
|
|
|
it('[0] le [0, 1, 2] is True', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([0]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(le(cmpn)(_na([0]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] le [0] is False', () => { |
|
|
|
it('[0, 1, 2] le [0] is False', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([0, 1, 2]))._(_na([0])))).toEqual(false); |
|
|
|
expect($b(le(cmpn)(_na([0, 1, 2]))(_na([0])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1, 2, 0] le [0, 1, 2] is False', () => { |
|
|
|
it('[1, 2, 0] le [0, 1, 2] is False', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([1, 2, 0]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(le(cmpn)(_na([1, 2, 0]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] le [1, 2, 0] is True', () => { |
|
|
|
it('[0, 1, 2] le [1, 2, 0] is True', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([0, 1, 2]))._(_na([1, 2, 0])))).toEqual(true); |
|
|
|
expect($b(le(cmpn)(_na([0, 1, 2]))(_na([1, 2, 0])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] le [0, 1, 2] is True', () => { |
|
|
|
it('[0, 1, 2] le [0, 1, 2] is True', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([0, 1, 2]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(le(cmpn)(_na([0, 1, 2]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(le._(cmpn)._(_na([0, 1, 2]))._(infinite))).toEqual(true); |
|
|
|
expect($b(le(cmpn)(_na([0, 1, 2]))(infinite))).toEqual(true); |
|
|
|
expect($b(le._(cmpn)._(infinite)._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(le(cmpn)(infinite)(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('eq', () => { |
|
|
|
describe('eq', () => { |
|
|
|
it('Nil eq Nil is True', () => { |
|
|
|
it('Nil eq Nil is True', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([]))._(_na([])))).toEqual(true); |
|
|
|
expect($b(eq(eqn)(_na([]))(_na([])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Nil eq [0, 1, 2] is False', () => { |
|
|
|
it('Nil eq [0, 1, 2] is False', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(_na([]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] eq Nil is False', () => { |
|
|
|
it('[0, 1, 2] eq Nil is False', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([0, 1, 2]))._(_na([])))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(_na([0, 1, 2]))(_na([])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0] eq [0, 1, 2] is False', () => { |
|
|
|
it('[0] eq [0, 1, 2] is False', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([0]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(_na([0]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] eq [0] is False', () => { |
|
|
|
it('[0, 1, 2] eq [0] is False', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([0, 1, 2]))._(_na([0])))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(_na([0, 1, 2]))(_na([0])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1, 2, 0] eq [0, 1, 2] is False', () => { |
|
|
|
it('[1, 2, 0] eq [0, 1, 2] is False', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([1, 2, 0]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(_na([1, 2, 0]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] eq [1, 2, 0] is False', () => { |
|
|
|
it('[0, 1, 2] eq [1, 2, 0] is False', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([0, 1, 2]))._(_na([1, 2, 0])))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(_na([0, 1, 2]))(_na([1, 2, 0])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] eq [0, 1, 2] is True', () => { |
|
|
|
it('[0, 1, 2] eq [0, 1, 2] is True', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([0, 1, 2]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(eq(eqn)(_na([0, 1, 2]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(eq._(eqn)._(_na([0, 1, 2]))._(infinite))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(_na([0, 1, 2]))(infinite))).toEqual(false); |
|
|
|
expect($b(eq._(eqn)._(infinite)._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(eq(eqn)(infinite)(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('ge', () => { |
|
|
|
describe('ge', () => { |
|
|
|
it('Nil ge Nil is True', () => { |
|
|
|
it('Nil ge Nil is True', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([]))._(_na([])))).toEqual(true); |
|
|
|
expect($b(ge(cmpn)(_na([]))(_na([])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Nil ge [0, 1, 2] is False', () => { |
|
|
|
it('Nil ge [0, 1, 2] is False', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(ge(cmpn)(_na([]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] ge Nil is True', () => { |
|
|
|
it('[0, 1, 2] ge Nil is True', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([0, 1, 2]))._(_na([])))).toEqual(true); |
|
|
|
expect($b(ge(cmpn)(_na([0, 1, 2]))(_na([])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0] ge [0, 1, 2] is False', () => { |
|
|
|
it('[0] ge [0, 1, 2] is False', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([0]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(ge(cmpn)(_na([0]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] ge [0] is True', () => { |
|
|
|
it('[0, 1, 2] ge [0] is True', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([0, 1, 2]))._(_na([0])))).toEqual(true); |
|
|
|
expect($b(ge(cmpn)(_na([0, 1, 2]))(_na([0])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1, 2, 0] ge [0, 1, 2] is True', () => { |
|
|
|
it('[1, 2, 0] ge [0, 1, 2] is True', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([1, 2, 0]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(ge(cmpn)(_na([1, 2, 0]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] ge [1, 2, 0] is False', () => { |
|
|
|
it('[0, 1, 2] ge [1, 2, 0] is False', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([0, 1, 2]))._(_na([1, 2, 0])))).toEqual(false); |
|
|
|
expect($b(ge(cmpn)(_na([0, 1, 2]))(_na([1, 2, 0])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] ge [0, 1, 2] is True', () => { |
|
|
|
it('[0, 1, 2] ge [0, 1, 2] is True', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([0, 1, 2]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(ge(cmpn)(_na([0, 1, 2]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(ge._(cmpn)._(_na([0, 1, 2]))._(infinite))).toEqual(false); |
|
|
|
expect($b(ge(cmpn)(_na([0, 1, 2]))(infinite))).toEqual(false); |
|
|
|
expect($b(ge._(cmpn)._(infinite)._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(ge(cmpn)(infinite)(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('gt', () => { |
|
|
|
describe('gt', () => { |
|
|
|
it('Nil gt Nil is False', () => { |
|
|
|
it('Nil gt Nil is False', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([]))._(_na([])))).toEqual(false); |
|
|
|
expect($b(gt(cmpn)(_na([]))(_na([])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Nil gt [0, 1, 2] is False', () => { |
|
|
|
it('Nil gt [0, 1, 2] is False', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(gt(cmpn)(_na([]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] gt Nil is True', () => { |
|
|
|
it('[0, 1, 2] gt Nil is True', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([0, 1, 2]))._(_na([])))).toEqual(true); |
|
|
|
expect($b(gt(cmpn)(_na([0, 1, 2]))(_na([])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0] gt [0, 1, 2] is False', () => { |
|
|
|
it('[0] gt [0, 1, 2] is False', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([0]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(gt(cmpn)(_na([0]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] gt [0] is True', () => { |
|
|
|
it('[0, 1, 2] gt [0] is True', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([0, 1, 2]))._(_na([0])))).toEqual(true); |
|
|
|
expect($b(gt(cmpn)(_na([0, 1, 2]))(_na([0])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[1, 2, 0] gt [0, 1, 2] is True', () => { |
|
|
|
it('[1, 2, 0] gt [0, 1, 2] is True', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([1, 2, 0]))._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(gt(cmpn)(_na([1, 2, 0]))(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] gt [1, 2, 0] is False', () => { |
|
|
|
it('[0, 1, 2] gt [1, 2, 0] is False', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([0, 1, 2]))._(_na([1, 2, 0])))).toEqual(false); |
|
|
|
expect($b(gt(cmpn)(_na([0, 1, 2]))(_na([1, 2, 0])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2] gt [0, 1, 2] is False', () => { |
|
|
|
it('[0, 1, 2] gt [0, 1, 2] is False', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([0, 1, 2]))._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(gt(cmpn)(_na([0, 1, 2]))(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(gt._(cmpn)._(_na([0, 1, 2]))._(infinite))).toEqual(false); |
|
|
|
expect($b(gt(cmpn)(_na([0, 1, 2]))(infinite))).toEqual(false); |
|
|
|
expect($b(gt._(cmpn)._(infinite)._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(gt(cmpn)(infinite)(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('map', () => { |
|
|
|
describe('map', () => { |
|
|
|
it('maps Nil', () => { |
|
|
|
it('maps Nil', () => { |
|
|
|
expect($na(map._(succ)._(_na([])))).toEqual([]); |
|
|
|
expect($na(map(succ)(_na([])))).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('maps only item', () => { |
|
|
|
it('maps only item', () => { |
|
|
|
expect($na(map._(succ)._(_na([0])))).toEqual([1]); |
|
|
|
expect($na(map(succ)(_na([0])))).toEqual([1]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('maps several items', () => { |
|
|
|
it('maps several items', () => { |
|
|
|
expect($na(map._(succ)._(_na([0, 1])))).toEqual([1, 2]); |
|
|
|
expect($na(map(succ)(_na([0, 1])))).toEqual([1, 2]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(head._(map._(succ)._(infinite)))).toBe(1); |
|
|
|
expect($n(head(map(succ)(infinite)))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('filter', () => { |
|
|
|
describe('filter', () => { |
|
|
|
it('filter Nil', () => { |
|
|
|
it('filter Nil', () => { |
|
|
|
expect($na(filter._(odd)._(_na([])))).toEqual([]); |
|
|
|
expect($na(filter(odd)(_na([])))).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('filters only item', () => { |
|
|
|
it('filters only item', () => { |
|
|
|
expect($na(filter._(odd)._(_na([])))).toEqual([]); |
|
|
|
expect($na(filter(odd)(_na([])))).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('filters several items', () => { |
|
|
|
it('filters several items', () => { |
|
|
|
expect($na(filter._(odd)._(_na([0, 1])))).toEqual([1]); |
|
|
|
expect($na(filter(odd)(_na([0, 1])))).toEqual([1]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(head._(filter._(odd)._(infinite)))).toBe(1); |
|
|
|
expect($n(head(filter(odd)(infinite)))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('any', () => { |
|
|
|
describe('any', () => { |
|
|
|
it('any Nil is False', () => { |
|
|
|
it('any Nil is False', () => { |
|
|
|
expect($b(any._(odd)._(_na([])))).toEqual(false); |
|
|
|
expect($b(any(odd)(_na([])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('any for no matching item is False', () => { |
|
|
|
it('any for no matching item is False', () => { |
|
|
|
expect($b(any._(odd)._(_na([0, 2])))).toEqual(false); |
|
|
|
expect($b(any(odd)(_na([0, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('any for matching item is True', () => { |
|
|
|
it('any for matching item is True', () => { |
|
|
|
expect($b(any._(odd)._(_na([0, 1, 2])))).toEqual(true); |
|
|
|
expect($b(any(odd)(_na([0, 1, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(any._(odd)._(infinite))).toEqual(true); |
|
|
|
expect($b(any(odd)(infinite))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('all', () => { |
|
|
|
describe('all', () => { |
|
|
|
it('all Nil is True', () => { |
|
|
|
it('all Nil is True', () => { |
|
|
|
expect($b(all._(even)._(_na([])))).toEqual(true); |
|
|
|
expect($b(all(even)(_na([])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('all for non-matching item is False', () => { |
|
|
|
it('all for non-matching item is False', () => { |
|
|
|
expect($b(all._(even)._(_na([0, 1, 2])))).toEqual(false); |
|
|
|
expect($b(all(even)(_na([0, 1, 2])))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('all for no non-matching item is True', () => { |
|
|
|
it('all for no non-matching item is True', () => { |
|
|
|
expect($b(all._(even)._(_na([0, 2])))).toEqual(true); |
|
|
|
expect($b(all(even)(_na([0, 2])))).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($b(all._(even)._(infinite))).toEqual(false); |
|
|
|
expect($b(all(even)(infinite))).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('get', () => { |
|
|
|
describe('get', () => { |
|
|
|
it('returns nothing from Nil', () => { |
|
|
|
it('returns nothing from Nil', () => { |
|
|
|
expect(() => $n(get._(_n(0))._(Nil))).toThrow(); |
|
|
|
expect(() => $n(get(_n(0))(Nil))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns nothing with out of bounds index', () => { |
|
|
|
it('returns nothing with out of bounds index', () => { |
|
|
|
expect(() => $n(get._(_n(100))._(_na([0, 1, 2, 3])))).toThrow(); |
|
|
|
expect(() => $n(get(_n(100))(_na([0, 1, 2, 3])))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][0] is 0', () => { |
|
|
|
it('[0, 1, 2, 3][0] is 0', () => { |
|
|
|
expect($n(get._(_n(0))._(_na([0, 1, 2, 3])))).toBe(0); |
|
|
|
expect($n(get(_n(0))(_na([0, 1, 2, 3])))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][1] is 1', () => { |
|
|
|
it('[0, 1, 2, 3][1] is 1', () => { |
|
|
|
expect($n(get._(_n(1))._(_na([0, 1, 2, 3])))).toBe(1); |
|
|
|
expect($n(get(_n(1))(_na([0, 1, 2, 3])))).toBe(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][2] is 2', () => { |
|
|
|
it('[0, 1, 2, 3][2] is 2', () => { |
|
|
|
expect($n(get._(_n(2))._(_na([0, 1, 2, 3])))).toBe(2); |
|
|
|
expect($n(get(_n(2))(_na([0, 1, 2, 3])))).toBe(2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][3] get 3 is 3', () => { |
|
|
|
it('[0, 1, 2, 3][3] get 3 is 3', () => { |
|
|
|
expect($n(get._(_n(3))._(_na([0, 1, 2, 3])))).toBe(3); |
|
|
|
expect($n(get(_n(3))(_na([0, 1, 2, 3])))).toBe(3); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(get._(_n(4))._(infinite))).toBe(4); |
|
|
|
expect($n(get(_n(4))(infinite))).toBe(4); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('set', () => { |
|
|
|
describe('set', () => { |
|
|
|
it('can not update Nil', () => { |
|
|
|
it('can not update Nil', () => { |
|
|
|
expect(() => $na(set._(_n(10))._(_n(0))._(Nil))).toThrow(); |
|
|
|
expect(() => $na(set(_n(10))(_n(0))(Nil))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('can not update out of bounds index', () => { |
|
|
|
it('can not update out of bounds index', () => { |
|
|
|
expect(() => $na(set._(_n(10))._(_n(100))._(_na([0, 1, 2, 3])))).toThrow(); |
|
|
|
expect(() => $na(set(_n(10))(_n(100))(_na([0, 1, 2, 3])))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][0] = 10 is [10, 1, 2, 3]', () => { |
|
|
|
it('[0, 1, 2, 3][0] = 10 is [10, 1, 2, 3]', () => { |
|
|
|
expect($na(set._(_n(10))._(_n(0))._(_na([0, 1, 2, 3])))).toEqual([10, 1, 2, 3]); |
|
|
|
expect($na(set(_n(10))(_n(0))(_na([0, 1, 2, 3])))).toEqual([10, 1, 2, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][1] = 10 is [0, 10, 2, 3]', () => { |
|
|
|
it('[0, 1, 2, 3][1] = 10 is [0, 10, 2, 3]', () => { |
|
|
|
expect($na(set._(_n(10))._(_n(1))._(_na([0, 1, 2, 3])))).toEqual([0, 10, 2, 3]); |
|
|
|
expect($na(set(_n(10))(_n(1))(_na([0, 1, 2, 3])))).toEqual([0, 10, 2, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][2] = 10 is [0, 1, 10, 3]', () => { |
|
|
|
it('[0, 1, 2, 3][2] = 10 is [0, 1, 10, 3]', () => { |
|
|
|
expect($na(set._(_n(10))._(_n(2))._(_na([0, 1, 2, 3])))).toEqual([0, 1, 10, 3]); |
|
|
|
expect($na(set(_n(10))(_n(2))(_na([0, 1, 2, 3])))).toEqual([0, 1, 10, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][3] = 10 is [0, 1, 2, 10]', () => { |
|
|
|
it('[0, 1, 2, 3][3] = 10 is [0, 1, 2, 10]', () => { |
|
|
|
expect($na(set._(_n(10))._(_n(3))._(_na([0, 1, 2, 3])))).toEqual([0, 1, 2, 10]); |
|
|
|
expect($na(set(_n(10))(_n(3))(_na([0, 1, 2, 3])))).toEqual([0, 1, 2, 10]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(get._(_n(4))._(set._(_n(10))._(_n(4))._(infinite)))).toBe(10); |
|
|
|
expect($n(get(_n(4))(set(_n(10))(_n(4))(infinite)))).toBe(10); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('update', () => { |
|
|
|
describe('update', () => { |
|
|
|
it('can not update Nil', () => { |
|
|
|
it('can not update Nil', () => { |
|
|
|
expect(() => $na(update._(succ)._(_n(0))._(Nil))).toThrow(); |
|
|
|
expect(() => $na(update(succ)(_n(0))(Nil))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('can not update out of bounds index', () => { |
|
|
|
it('can not update out of bounds index', () => { |
|
|
|
expect(() => $na(update._(succ)._(_n(100))._(_na([0, 1, 2, 3])))).toThrow(); |
|
|
|
expect(() => $na(update(succ)(_n(100))(_na([0, 1, 2, 3])))).toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][0]++ is [10, 1, 2, 3]', () => { |
|
|
|
it('[0, 1, 2, 3][0]++ is [10, 1, 2, 3]', () => { |
|
|
|
expect($na(update._(succ)._(_n(0))._(_na([0, 1, 2, 3])))).toEqual([1, 1, 2, 3]); |
|
|
|
expect($na(update(succ)(_n(0))(_na([0, 1, 2, 3])))).toEqual([1, 1, 2, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][1]++ is [0, 10, 2, 3]', () => { |
|
|
|
it('[0, 1, 2, 3][1]++ is [0, 10, 2, 3]', () => { |
|
|
|
expect($na(update._(succ)._(_n(1))._(_na([0, 1, 2, 3])))).toEqual([0, 2, 2, 3]); |
|
|
|
expect($na(update(succ)(_n(1))(_na([0, 1, 2, 3])))).toEqual([0, 2, 2, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][2]++ is [0, 1, 10, 3]', () => { |
|
|
|
it('[0, 1, 2, 3][2]++ is [0, 1, 10, 3]', () => { |
|
|
|
expect($na(update._(succ)._(_n(2))._(_na([0, 1, 2, 3])))).toEqual([0, 1, 3, 3]); |
|
|
|
expect($na(update(succ)(_n(2))(_na([0, 1, 2, 3])))).toEqual([0, 1, 3, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('[0, 1, 2, 3][3]++ is [0, 1, 2, 10]', () => { |
|
|
|
it('[0, 1, 2, 3][3]++ is [0, 1, 2, 10]', () => { |
|
|
|
expect($na(update._(succ)._(_n(3))._(_na([0, 1, 2, 3])))).toEqual([0, 1, 2, 4]); |
|
|
|
expect($na(update(succ)(_n(3))(_na([0, 1, 2, 3])))).toEqual([0, 1, 2, 4]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(get._(_n(4))._(update._(succ)._(_n(4))._(infinite)))).toBe(5); |
|
|
|
expect($n(get(_n(4))(update(succ)(_n(4))(infinite)))).toBe(5); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('intersperse', () => { |
|
|
|
describe('intersperse', () => { |
|
|
|
it('0 intersperse Nil is Nil', () => { |
|
|
|
it('0 intersperse Nil is Nil', () => { |
|
|
|
expect($na(intersperse._(_n(0))._(Nil))).toEqual([]); |
|
|
|
expect($na(intersperse(_n(0))(Nil))).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('0 intersperse [1] is [1]', () => { |
|
|
|
it('0 intersperse [1] is [1]', () => { |
|
|
|
expect($na(intersperse._(_n(0))._(_na([1])))).toEqual([1]); |
|
|
|
expect($na(intersperse(_n(0))(_na([1])))).toEqual([1]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('0 intersperse [1, 2, 3] is [1, 0, 2, 0, 3]', () => { |
|
|
|
it('0 intersperse [1, 2, 3] is [1, 0, 2, 0, 3]', () => { |
|
|
|
expect($na(intersperse._(_n(0))._(_na([1, 2, 3])))).toEqual([1, 0, 2, 0, 3]); |
|
|
|
expect($na(intersperse(_n(0))(_na([1, 2, 3])))).toEqual([1, 0, 2, 0, 3]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($n(head._(intersperse._(_n(0))._(infinite)))).toBe(0); |
|
|
|
expect($n(head(intersperse(_n(0))(infinite)))).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('show', () => { |
|
|
|
describe('show', () => { |
|
|
|
it('show Nil is "[]"', () => { |
|
|
|
it('show Nil is "[]"', () => { |
|
|
|
expect($s(show._(nshow)._(_na([])))).toBe('[]'); |
|
|
|
expect($s(show(nshow)(_na([])))).toBe('[]'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('show [0] is "[0]"', () => { |
|
|
|
it('show [0] is "[0]"', () => { |
|
|
|
expect($s(show._(nshow)._(_na([0])))).toBe('[0]'); |
|
|
|
expect($s(show(nshow)(_na([0])))).toBe('[0]'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('show [0, 1, 2] is "[0, 1, 2]"', () => { |
|
|
|
it('show [0, 1, 2] is "[0, 1, 2]"', () => { |
|
|
|
expect($s(show._(nshow)._(_na([0, 1, 2])))).toBe('[0, 1, 2]'); |
|
|
|
expect($s(show(nshow)(_na([0, 1, 2])))).toBe('[0, 1, 2]'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('handles infinite lists', () => { |
|
|
|
it('handles infinite lists', () => { |
|
|
|
expect($c(head._(show._(nshow)._(infinite)))).toBe('['); |
|
|
|
expect($c(head(show(nshow)(infinite)))).toBe('['); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|