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