Native syntax
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { _ } from '../src/core';
|
||||
import { fromChar as _c } from '../src/char';
|
||||
import { toString as $s, fromString as _s } from '../src/string';
|
||||
import { run } from '../src/bf';
|
||||
|
||||
describe('BF', () => {
|
||||
describe('run', () => {
|
||||
it('handles output command', () => {
|
||||
expect($s(run._(_s('.'))._(_s('')))).toBe(String.fromCharCode(0));
|
||||
});
|
||||
|
||||
it('handles input command', () => {
|
||||
expect($s(run._(_s(',.'))._(_s('a')))).toBe('a');
|
||||
});
|
||||
|
||||
it('handles inc command', () => {
|
||||
expect($s(run._(_s('+.'))._(_s('')))).toBe(String.fromCharCode(1));
|
||||
});
|
||||
|
||||
it('handles dec command', () => {
|
||||
expect($s(run._(_s('-.'))._(_s('')))).toBe(String.fromCharCode(255));
|
||||
});
|
||||
|
||||
it('handles next command', () => {
|
||||
expect($s(run._(_s('+++++>++.'))._(_s('')))).toBe(String.fromCharCode(2));
|
||||
});
|
||||
|
||||
it('handles prev command', () => {
|
||||
expect($s(run._(_s('+++++>++<+++++.'))._(_s('')))).toBe(String.fromCharCode(10));
|
||||
});
|
||||
|
||||
it('skips loop block on zero', () => {
|
||||
expect($s(run._(_s('[+++++].'))._(_s('')))).toBe(String.fromCharCode(0));
|
||||
});
|
||||
|
||||
it('repeats loop block while not zero', () => {
|
||||
expect($s(run._(_s('+++++[-].'))._(_s('')))).toBe(String.fromCharCode(0));
|
||||
});
|
||||
|
||||
it('prints "Hello World!"', () => {
|
||||
expect($s(run
|
||||
._(_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'))
|
||||
._(_s(''))))
|
||||
.toBe('Hello World!\n');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,249 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { undef } from '../src/core';
|
||||
import { toNOrd as $o, NOrd } from '../src/ord';
|
||||
import { toBoolean as $b, False, True, fromBoolean as _b, and, cmp, eq, ge, gt, iif, le, lt, not, or, xor } from '../src/bool';
|
||||
import { toString as $s } from '../src/string';
|
||||
import { show } from '../src/bool.show';
|
||||
|
||||
describe('Bool', () => {
|
||||
describe('toBoolean', () => {
|
||||
it('converts True', () => {
|
||||
expect($b(True)).toBe(true);
|
||||
});
|
||||
|
||||
it('converts False', () => {
|
||||
expect($b(False)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fromBoolean', () => {
|
||||
it('converts true', () => {
|
||||
expect($b(_b(true))).toBe(true);
|
||||
});
|
||||
|
||||
it('converts false', () => {
|
||||
expect($b(_b(false))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('iif', () => {
|
||||
it('returns true argument', () => {
|
||||
expect($b(iif._(True)._(True)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false argument', () => {
|
||||
expect($b(iif._(False)._(True)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores other argument', () => {
|
||||
expect($b(iif._(True)._(True)._(undef))).toBe(true);
|
||||
expect($b(iif._(False)._(undef)._(False))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('not', () => {
|
||||
it('not False is True', () => {
|
||||
expect($b(not._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('not True is False', () => {
|
||||
expect($b(not._(True))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lt', () => {
|
||||
it('False lt False is False', () => {
|
||||
expect($b(lt._(False)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('False lt True is True', () => {
|
||||
expect($b(lt._(False)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('True lt False is False', () => {
|
||||
expect($b(lt._(True)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('True lt True is False', () => {
|
||||
expect($b(lt._(True)._(True))).toBe(false);
|
||||
});
|
||||
|
||||
it('True lt ignores second argument', () => {
|
||||
expect($b(lt._(True)._(undef))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('le', () => {
|
||||
it('False le False is True', () => {
|
||||
expect($b(le._(False)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('False le True is True', () => {
|
||||
expect($b(le._(False)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('True le False is False', () => {
|
||||
expect($b(le._(True)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('True le True is True', () => {
|
||||
expect($b(le._(True)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('False le ignores second argument', () => {
|
||||
expect($b(le._(False)._(undef))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eq', () => {
|
||||
it('False eq False is True', () => {
|
||||
expect($b(eq._(False)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('False eq True is False', () => {
|
||||
expect($b(eq._(False)._(True))).toBe(false);
|
||||
});
|
||||
|
||||
it('True eq False is False', () => {
|
||||
expect($b(eq._(True)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('True eq True is True', () => {
|
||||
expect($b(eq._(True)._(True))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ge', () => {
|
||||
it('False ge False is True', () => {
|
||||
expect($b(ge._(False)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('False ge True is False', () => {
|
||||
expect($b(ge._(False)._(True))).toBe(false);
|
||||
});
|
||||
|
||||
it('True ge False is True', () => {
|
||||
expect($b(ge._(True)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('True ge True is True', () => {
|
||||
expect($b(ge._(True)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('True ge ignores second argument', () => {
|
||||
expect($b(ge._(True)._(undef))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gt', () => {
|
||||
it('False gt False is False', () => {
|
||||
expect($b(gt._(False)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('False gt True is False', () => {
|
||||
expect($b(gt._(False)._(True))).toBe(false);
|
||||
});
|
||||
|
||||
it('True gt False is True', () => {
|
||||
expect($b(gt._(True)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('True gt True is False', () => {
|
||||
expect($b(gt._(True)._(True))).toBe(false);
|
||||
});
|
||||
|
||||
it('False gt ignores second argument', () => {
|
||||
expect($b(gt._(False)._(undef))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cmp', () => {
|
||||
it('False cmp False is EQ', () => {
|
||||
expect($o(cmp._(False)._(False))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('False cmp True is LT', () => {
|
||||
expect($o(cmp._(False)._(True))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('True cmp False is GT', () => {
|
||||
expect($o(cmp._(True)._(False))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('True cmp True is EQ', () => {
|
||||
expect($o(cmp._(True)._(True))).toBe(NOrd.EQ);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and', () => {
|
||||
it('False and False is False', () => {
|
||||
expect($b(and._(False)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('False and True is False', () => {
|
||||
expect($b(and._(False)._(True))).toBe(false);
|
||||
});
|
||||
|
||||
it('True and False is False', () => {
|
||||
expect($b(and._(True)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('True and True is True', () => {
|
||||
expect($b(and._(True)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('False and ignores other argument', () => {
|
||||
expect($b(and._(False)._(undef))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('or', () => {
|
||||
it('False or False is False', () => {
|
||||
expect($b(or._(False)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('False or True is True', () => {
|
||||
expect($b(or._(False)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('True or False is True', () => {
|
||||
expect($b(or._(True)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('True or True is True', () => {
|
||||
expect($b(or._(True)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('True or ignores other argument', () => {
|
||||
expect($b(or._(True)._(undef))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('xor', () => {
|
||||
it('False xor False is False', () => {
|
||||
expect($b(xor._(False)._(False))).toBe(false);
|
||||
});
|
||||
|
||||
it('False xor True is True', () => {
|
||||
expect($b(xor._(False)._(True))).toBe(true);
|
||||
});
|
||||
|
||||
it('True xor False is True', () => {
|
||||
expect($b(xor._(True)._(False))).toBe(true);
|
||||
});
|
||||
|
||||
it('True xor True is False', () => {
|
||||
expect($b(xor._(True)._(True))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('show', () => {
|
||||
it('show False is "False"', () => {
|
||||
expect($s(show._(False))).toBe('False');
|
||||
});
|
||||
|
||||
it('show True is "True"', () => {
|
||||
expect($s(show._(True))).toBe('True');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,476 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { undef } from '../src/core';
|
||||
import { toNOrd as $o, NOrd } from '../src/ord';
|
||||
import { toBoolean as $b, fromBoolean as _b } from '../src/bool';
|
||||
import { toNumber as $n, Inc, fromNumber as _n, cmp, dec, div, eq, ge, gt, ifz, inc, le, lt, mod, mul, sub, sum, x00 } from '../src/byte';
|
||||
import { toString as $s } from '../src/string';
|
||||
import { show } from '../src/byte.show';
|
||||
|
||||
describe('Byte', () => {
|
||||
describe('toNumber', () => {
|
||||
it('converts 0', () => {
|
||||
expect($n(x00)).toBe(0);
|
||||
});
|
||||
|
||||
it('converts 1', () => {
|
||||
expect($n(Inc._(x00))).toBe(1);
|
||||
});
|
||||
|
||||
it('converts 2', () => {
|
||||
expect($n(Inc._(Inc._(x00)))).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fromNumber', () => {
|
||||
it('converts 0', () => {
|
||||
expect($n(_n(0))).toBe(0);
|
||||
});
|
||||
|
||||
it('converts 1', () => {
|
||||
expect($n(_n(1))).toBe(1);
|
||||
});
|
||||
|
||||
it('converts 2', () => {
|
||||
expect($n(_n(2))).toBe(2);
|
||||
});
|
||||
|
||||
it('converts 300', () => {
|
||||
expect($n(_n(300))).toBe(44);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ifz', () => {
|
||||
it('returns zero branch', () => {
|
||||
expect($b(ifz._(_n(0))._(_b(true))._(_b(false)))).toBe(true);
|
||||
});
|
||||
|
||||
it('returns non-zero branch', () => {
|
||||
expect($b(ifz._(_n(1))._(_b(true))._(_b(false)))).toBe(false);
|
||||
});
|
||||
|
||||
it('returns non-zero branch', () => {
|
||||
expect($b(ifz._(_n(10))._(_b(true))._(_b(false)))).toBe(false);
|
||||
});
|
||||
|
||||
it('skips other branch', () => {
|
||||
expect($b(ifz._(_n(0))._(_b(true))._(undef))).toBe(true);
|
||||
expect($b(ifz._(_n(1))._(undef)._(_b(false)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('inc', () => {
|
||||
it('inc 0 is 1', () => {
|
||||
expect($n(inc._(_n(0)))).toBe(1);
|
||||
});
|
||||
|
||||
it('inc 1 is 2', () => {
|
||||
expect($n(inc._(_n(1)))).toBe(2);
|
||||
});
|
||||
|
||||
it('inc 10 is 11', () => {
|
||||
expect($n(inc._(_n(10)))).toBe(11);
|
||||
});
|
||||
|
||||
it('inc 255 is 0', () => {
|
||||
expect($n(inc._(_n(255)))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dec', () => {
|
||||
it('dec 0 is 255', () => {
|
||||
expect($n(dec._(_n(0)))).toBe(255);
|
||||
});
|
||||
|
||||
it('dec 1 is 0', () => {
|
||||
expect($n(dec._(_n(1)))).toBe(0);
|
||||
});
|
||||
|
||||
it('dec 10 is 9', () => {
|
||||
expect($n(dec._(_n(10)))).toBe(9);
|
||||
});
|
||||
|
||||
it('dec 255 is 254', () => {
|
||||
expect($n(dec._(_n(255)))).toBe(254);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cmp', () => {
|
||||
it('0 cmp 0 is EQ', () => {
|
||||
expect($o(cmp._(_n(0))._(_n(0)))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('0 cmp 1 is LT', () => {
|
||||
expect($o(cmp._(_n(0))._(_n(1)))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('1 cmp 0 is GT', () => {
|
||||
expect($o(cmp._(_n(1))._(_n(0)))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('3 cmp 3 is EQ', () => {
|
||||
expect($o(cmp._(_n(3))._(_n(3)))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('3 cmp 7 is LT', () => {
|
||||
expect($o(cmp._(_n(3))._(_n(7)))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('7 cmp 3 is GT', () => {
|
||||
expect($o(cmp._(_n(7))._(_n(3)))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('0 cmp 255 is LT', () => {
|
||||
expect($o(cmp._(_n(0))._(_n(255)))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('255 cmp 0 is GT', () => {
|
||||
expect($o(cmp._(_n(255))._(_n(0)))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('255 cmp 255 is EQ', () => {
|
||||
expect($o(cmp._(_n(255))._(_n(255)))).toBe(NOrd.EQ);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lt', () => {
|
||||
it('0 lt 0 is False', () => {
|
||||
expect($b(lt._(_n(0))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('0 lt 1 is True', () => {
|
||||
expect($b(lt._(_n(0))._(_n(1)))).toBe(true);
|
||||
});
|
||||
|
||||
it('1 lt 0 is False', () => {
|
||||
expect($b(lt._(_n(1))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 lt 3 is False', () => {
|
||||
expect($b(lt._(_n(3))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 lt 7 is True', () => {
|
||||
expect($b(lt._(_n(3))._(_n(7)))).toBe(true);
|
||||
});
|
||||
|
||||
it('7 lt 3 is False', () => {
|
||||
expect($b(lt._(_n(7))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('0 lt 255 is True', () => {
|
||||
expect($b(lt._(_n(0))._(_n(255)))).toBe(true);
|
||||
});
|
||||
|
||||
it('255 lt 0 is False', () => {
|
||||
expect($b(lt._(_n(255))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('255 lt 255 is False', () => {
|
||||
expect($b(lt._(_n(255))._(_n(255)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('le', () => {
|
||||
it('0 le 0 is True', () => {
|
||||
expect($b(le._(_n(0))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 le 1 is True', () => {
|
||||
expect($b(le._(_n(0))._(_n(1)))).toBe(true);
|
||||
});
|
||||
|
||||
it('1 le 0 is False', () => {
|
||||
expect($b(le._(_n(1))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 le 3 is True', () => {
|
||||
expect($b(le._(_n(3))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 le 7 is True', () => {
|
||||
expect($b(le._(_n(3))._(_n(7)))).toBe(true);
|
||||
});
|
||||
|
||||
it('7 le 3 is False', () => {
|
||||
expect($b(le._(_n(7))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('0 le 255 is True', () => {
|
||||
expect($b(le._(_n(0))._(_n(255)))).toBe(true);
|
||||
});
|
||||
|
||||
it('255 le 0 is False', () => {
|
||||
expect($b(le._(_n(255))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('255 le 255 is True', () => {
|
||||
expect($b(le._(_n(255))._(_n(255)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 le skips second argument', () => {
|
||||
expect($b(le._(_n(0))._(undef))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eq', () => {
|
||||
it('0 eq 0 is True', () => {
|
||||
expect($b(eq._(_n(0))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 eq 1 is False', () => {
|
||||
expect($b(eq._(_n(0))._(_n(1)))).toBe(false);
|
||||
});
|
||||
|
||||
it('1 eq 0 is False', () => {
|
||||
expect($b(eq._(_n(1))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 eq 3 is True', () => {
|
||||
expect($b(eq._(_n(3))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 eq 7 is False', () => {
|
||||
expect($b(eq._(_n(3))._(_n(7)))).toBe(false);
|
||||
});
|
||||
|
||||
it('7 eq 3 is False', () => {
|
||||
expect($b(eq._(_n(7))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('0 eq 255 is False', () => {
|
||||
expect($b(eq._(_n(0))._(_n(255)))).toBe(false);
|
||||
});
|
||||
|
||||
it('255 eq 0 is False', () => {
|
||||
expect($b(eq._(_n(255))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('255 eq 255 is True', () => {
|
||||
expect($b(eq._(_n(255))._(_n(255)))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ge', () => {
|
||||
it('0 ge 0 is True', () => {
|
||||
expect($b(ge._(_n(0))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 ge 1 is False', () => {
|
||||
expect($b(ge._(_n(0))._(_n(1)))).toBe(false);
|
||||
});
|
||||
|
||||
it('1 ge 0 is True', () => {
|
||||
expect($b(ge._(_n(1))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 ge 3 is True', () => {
|
||||
expect($b(ge._(_n(3))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 ge 7 is False', () => {
|
||||
expect($b(ge._(_n(3))._(_n(7)))).toBe(false);
|
||||
});
|
||||
|
||||
it('7 ge 3 is True', () => {
|
||||
expect($b(ge._(_n(7))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 ge 255 is False', () => {
|
||||
expect($b(ge._(_n(0))._(_n(255)))).toBe(false);
|
||||
});
|
||||
|
||||
it('255 ge 0 is True', () => {
|
||||
expect($b(ge._(_n(255))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('255 ge 255 is True', () => {
|
||||
expect($b(ge._(_n(255))._(_n(255)))).toBe(true);
|
||||
});
|
||||
|
||||
it('ge 0 skips first argument', () => {
|
||||
expect($b(ge._(undef)._(_n(0)))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gt', () => {
|
||||
it('0 gt 0 is False', () => {
|
||||
expect($b(gt._(_n(0))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('0 gt 1 is False', () => {
|
||||
expect($b(gt._(_n(0))._(_n(1)))).toBe(false);
|
||||
});
|
||||
|
||||
it('1 gt 0 is True', () => {
|
||||
expect($b(gt._(_n(1))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 gt 3 is False', () => {
|
||||
expect($b(gt._(_n(3))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 gt 7 is False', () => {
|
||||
expect($b(gt._(_n(3))._(_n(7)))).toBe(false);
|
||||
});
|
||||
|
||||
it('7 gt 3 is True', () => {
|
||||
expect($b(gt._(_n(7))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 gt 255 is False', () => {
|
||||
expect($b(gt._(_n(0))._(_n(255)))).toBe(false);
|
||||
});
|
||||
|
||||
it('255 gt 0 is True', () => {
|
||||
expect($b(gt._(_n(255))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('255 gt 255 is False', () => {
|
||||
expect($b(gt._(_n(255))._(_n(255)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sum', () => {
|
||||
it('0 sum 0 is 0', () => {
|
||||
expect($n(sum._(_n(0))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('0 sum 1 is 1', () => {
|
||||
expect($n(sum._(_n(0))._(_n(1)))).toBe(1);
|
||||
});
|
||||
|
||||
it('1 sum 0 is 1', () => {
|
||||
expect($n(sum._(_n(1))._(_n(0)))).toBe(1);
|
||||
});
|
||||
|
||||
it('3 sum 4 is 7', () => {
|
||||
expect($n(sum._(_n(3))._(_n(4)))).toBe(7);
|
||||
});
|
||||
|
||||
it('200 sum 200 is 144', () => {
|
||||
expect($n(sum._(_n(200))._(_n(200)))).toBe(144);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sub', () => {
|
||||
it('0 sub 0 is 0', () => {
|
||||
expect($n(sub._(_n(0))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('0 sub 1 is 255', () => {
|
||||
expect($n(sub._(_n(0))._(_n(1)))).toBe(255);
|
||||
});
|
||||
|
||||
it('1 sub 0 is 1', () => {
|
||||
expect($n(sub._(_n(1))._(_n(0)))).toBe(1);
|
||||
});
|
||||
|
||||
it('7 sub 4 is 3', () => {
|
||||
expect($n(sub._(_n(7))._(_n(4)))).toBe(3);
|
||||
});
|
||||
|
||||
it('4 sub 7 is 253', () => {
|
||||
expect($n(sub._(_n(4))._(_n(7)))).toBe(253);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mul', () => {
|
||||
it('0 mul 0 is 0', () => {
|
||||
expect($n(mul._(_n(0))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('0 mul 10 is 0', () => {
|
||||
expect($n(mul._(_n(0))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 mul 0 is 0', () => {
|
||||
expect($n(mul._(_n(1))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('1 mul 10 is 10', () => {
|
||||
expect($n(mul._(_n(1))._(_n(10)))).toBe(10);
|
||||
});
|
||||
|
||||
it('10 mul 1 is 10', () => {
|
||||
expect($n(mul._(_n(10))._(_n(1)))).toBe(10);
|
||||
});
|
||||
|
||||
it('3 mul 4 is 12', () => {
|
||||
expect($n(mul._(_n(3))._(_n(4)))).toBe(12);
|
||||
});
|
||||
|
||||
it('100 mul 100 is 12', () => {
|
||||
expect($n(mul._(_n(3))._(_n(4)))).toBe(12);
|
||||
});
|
||||
|
||||
it('0 mul ignores second argument', () => {
|
||||
expect($n(mul._(_n(0))._(undef))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('div', () => {
|
||||
it('0 div 10 is 0', () => {
|
||||
expect($n(div._(_n(0))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('1 div 10 is 0', () => {
|
||||
expect($n(div._(_n(1))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 div 1 is 10', () => {
|
||||
expect($n(div._(_n(10))._(_n(1)))).toBe(10);
|
||||
});
|
||||
|
||||
it('10 div 5 is 2', () => {
|
||||
expect($n(div._(_n(10))._(_n(5)))).toBe(2);
|
||||
});
|
||||
|
||||
it('10 div 3 is 3', () => {
|
||||
expect($n(div._(_n(10))._(_n(3)))).toBe(3);
|
||||
});
|
||||
|
||||
it.failing('0 div ignores second argument', () => {
|
||||
expect($n(div._(_n(0))._(undef))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mod', () => {
|
||||
it('0 mod 10 is 0', () => {
|
||||
expect($n(mod._(_n(0))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('1 mod 10 is 1', () => {
|
||||
expect($n(mod._(_n(1))._(_n(10)))).toBe(1);
|
||||
});
|
||||
|
||||
it('10 mod 1 is 0', () => {
|
||||
expect($n(mod._(_n(10))._(_n(1)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 mod 5 is 0', () => {
|
||||
expect($n(mod._(_n(10))._(_n(5)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 mod 3 is 1', () => {
|
||||
expect($n(mod._(_n(10))._(_n(3)))).toBe(1);
|
||||
});
|
||||
|
||||
it.failing('0 mod ignores second argument', () => {
|
||||
expect($n(mod._(_n(0))._(undef))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('show', () => {
|
||||
it('show 0 is "0"', () => {
|
||||
expect($s(show._(_n(0)))).toBe('0');
|
||||
});
|
||||
|
||||
it('show 1 is "1"', () => {
|
||||
expect($s(show._(_n(1)))).toBe('1');
|
||||
});
|
||||
|
||||
it('show 255 is "255"', () => {
|
||||
expect($s(show._(_n(255)))).toBe('255');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,215 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { toNOrd as $o, NOrd } from '../src/ord';
|
||||
import { toBoolean as $b, fromBoolean as _b } from '../src/bool';
|
||||
import { fromNumber as _n } from '../src/byte';
|
||||
import { toChar as $c, fromChar as _c, cmp, eq, ge, gt, le, lt } from '../src/char';
|
||||
import { toString as $s } from '../src/string';
|
||||
import { show } from '../src/char.show';
|
||||
|
||||
describe('Char', () => {
|
||||
describe('toChar', () => {
|
||||
it('converts "0"', () => {
|
||||
expect($c(_n(48))).toBe('0');
|
||||
});
|
||||
|
||||
it('converts "a"', () => {
|
||||
expect($c(_n(97))).toBe('a');
|
||||
});
|
||||
|
||||
it('converts "Z"', () => {
|
||||
expect($c(_n(90))).toBe('Z');
|
||||
});
|
||||
|
||||
it('converts "-"', () => {
|
||||
expect($c(_n(45))).toBe('-');
|
||||
});
|
||||
});
|
||||
|
||||
describe('fromChar', () => {
|
||||
it('converts "0"', () => {
|
||||
expect($c(_c('0'))).toBe('0');
|
||||
});
|
||||
|
||||
it('converts "a"', () => {
|
||||
expect($c(_c('a'))).toBe('a');
|
||||
});
|
||||
|
||||
it('converts "Z"', () => {
|
||||
expect($c(_c('Z'))).toBe('Z');
|
||||
});
|
||||
|
||||
it('converts "-"', () => {
|
||||
expect($c(_c('-'))).toBe('-');
|
||||
});
|
||||
});
|
||||
|
||||
describe('cmp', () => {
|
||||
it('"0" cmp "0" is EQ', () => {
|
||||
expect($o(cmp._(_c('0'))._(_c('0')))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('"0" cmp "a" is LT', () => {
|
||||
expect($o(cmp._(_c('0'))._(_c('a')))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('"a" cmp "0" is GT', () => {
|
||||
expect($o(cmp._(_c('a'))._(_c('0')))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('"z" cmp "z" is EQ', () => {
|
||||
expect($o(cmp._(_c('z'))._(_c('z')))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('"z" cmp "-" is GT', () => {
|
||||
expect($o(cmp._(_c('z'))._(_c('-')))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('"-" cmp "z" is LT', () => {
|
||||
expect($o(cmp._(_c('-'))._(_c('z')))).toBe(NOrd.LT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lt', () => {
|
||||
it('"0" lt "0" is False', () => {
|
||||
expect($b(lt._(_c('0'))._(_c('0')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"0" lt "a" is True', () => {
|
||||
expect($b(lt._(_c('0'))._(_c('a')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"a" lt "0" is False', () => {
|
||||
expect($b(lt._(_c('a'))._(_c('0')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"z" lt "z" is False', () => {
|
||||
expect($b(lt._(_c('z'))._(_c('z')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"z" lt "-" is False', () => {
|
||||
expect($b(lt._(_c('z'))._(_c('-')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"-" lt "z" is True', () => {
|
||||
expect($b(lt._(_c('-'))._(_c('z')))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('le', () => {
|
||||
it('"0" le "0" is True', () => {
|
||||
expect($b(le._(_c('0'))._(_c('0')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"0" le "a" is True', () => {
|
||||
expect($b(le._(_c('0'))._(_c('a')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"a" le "0" is False', () => {
|
||||
expect($b(le._(_c('a'))._(_c('0')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"z" le "z" is True', () => {
|
||||
expect($b(le._(_c('z'))._(_c('z')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"z" le "-" is False', () => {
|
||||
expect($b(le._(_c('z'))._(_c('-')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"-" le "z" is True', () => {
|
||||
expect($b(le._(_c('-'))._(_c('z')))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eq', () => {
|
||||
it('"0" eq "0" is True', () => {
|
||||
expect($b(eq._(_c('0'))._(_c('0')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"0" eq "a" is False', () => {
|
||||
expect($b(eq._(_c('0'))._(_c('a')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"a" eq "0" is False', () => {
|
||||
expect($b(eq._(_c('a'))._(_c('0')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"z" eq "z" is True', () => {
|
||||
expect($b(eq._(_c('z'))._(_c('z')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"z" eq "-" is False', () => {
|
||||
expect($b(eq._(_c('z'))._(_c('-')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"-" eq "z" is False', () => {
|
||||
expect($b(eq._(_c('-'))._(_c('z')))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ge', () => {
|
||||
it('"0" ge "0" is True', () => {
|
||||
expect($b(ge._(_c('0'))._(_c('0')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"0" ge "a" is False', () => {
|
||||
expect($b(ge._(_c('0'))._(_c('a')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"a" ge "0" is True', () => {
|
||||
expect($b(ge._(_c('a'))._(_c('0')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"z" ge "z" is True', () => {
|
||||
expect($b(ge._(_c('z'))._(_c('z')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"z" ge "-" is True', () => {
|
||||
expect($b(ge._(_c('z'))._(_c('-')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"-" ge "z" is False', () => {
|
||||
expect($b(ge._(_c('-'))._(_c('z')))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gt', () => {
|
||||
it('"0" gt "0" is False', () => {
|
||||
expect($b(gt._(_c('0'))._(_c('0')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"0" gt "a" is False', () => {
|
||||
expect($b(gt._(_c('0'))._(_c('a')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"a" gt "0" is True', () => {
|
||||
expect($b(gt._(_c('a'))._(_c('0')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"z" gt "z" is False', () => {
|
||||
expect($b(gt._(_c('z'))._(_c('z')))).toBe(false);
|
||||
});
|
||||
|
||||
it('"z" gt "-" is True', () => {
|
||||
expect($b(gt._(_c('z'))._(_c('-')))).toBe(true);
|
||||
});
|
||||
|
||||
it('"-" gt "z" is False', () => {
|
||||
expect($b(gt._(_c('-'))._(_c('z')))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('show', () => {
|
||||
it('show "0" is "\'0\'"', () => {
|
||||
expect($s(show._(_c('0')))).toBe('\'0\'');
|
||||
});
|
||||
|
||||
it('show "a" is "\'a\'"', () => {
|
||||
expect($s(show._(_c('a')))).toBe('\'a\'');
|
||||
});
|
||||
|
||||
it('show "-" is "\'-\'"', () => {
|
||||
expect($s(show._(_c('-')))).toBe('\'-\'');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,24 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { $, _, cnst, id, undef } from '../src/core';
|
||||
|
||||
describe('id', () => {
|
||||
it('returns first argument', () => {
|
||||
expect($(id._(_('first')))).toBe('first');
|
||||
});
|
||||
});
|
||||
|
||||
describe('cnst', () => {
|
||||
it('returns first argument after receiving second', () => {
|
||||
expect($(cnst._(_('first'))._(_('second')))).toBe('first');
|
||||
});
|
||||
|
||||
it('ignores second argument', () => {
|
||||
expect($(cnst._(_('first'))._(undef))).toBe('first');
|
||||
});
|
||||
});
|
||||
|
||||
describe('pipe', () => {
|
||||
it.failing('applies both functions in order', () => {
|
||||
expect('Not implemented').toBe('Implemented');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { GroupQueue, QueueItem } from '../src/data/group-queue';
|
||||
import { List } from '../src/data/list';
|
||||
|
||||
describe('GroupQueue', () => {
|
||||
function json<T>(list: List<QueueItem<T>>): T[] {
|
||||
return [...list].map(({ value }) => value);
|
||||
}
|
||||
|
||||
describe('from array', () => {
|
||||
it('[]', () => expect([...new GroupQueue([])].map(json)).toEqual([]));
|
||||
it('[1]', () => expect([...new GroupQueue([1])].map(json)).toEqual([[1]]));
|
||||
it('["b", "c", "b", "c"]', () => expect([...new GroupQueue(['b', 'c', 'b', 'c'])].map(json)).toEqual([['b', 'b'], ['c', 'c']]));
|
||||
});
|
||||
|
||||
describe('length', () => {
|
||||
it('[]', () => expect(new GroupQueue([]).length).toEqual(0));
|
||||
it('[1]', () => expect(new GroupQueue([1]).length).toEqual(1));
|
||||
it('["b", "c", "b", "c"]', () => expect(new GroupQueue(['b', 'c', 'b', 'c']).length).toEqual(2));
|
||||
});
|
||||
|
||||
describe('insert', () => {
|
||||
function insert<T>(queue: GroupQueue<T>, value: T): T[][] {
|
||||
queue.insert(value);
|
||||
return [...queue].map(json);
|
||||
}
|
||||
it('0 -> []', () => expect([...insert(new GroupQueue<number>([]), 0)]).toEqual([[0]]));
|
||||
it('0 -> [1]', () => expect([...insert(new GroupQueue([1]), 0)]).toEqual([[1], [0]]));
|
||||
it('1 -> [1]', () => expect([...insert(new GroupQueue([1]), 1)]).toEqual([[1, 1]]));
|
||||
it('"d" -> ["b", "c", "b", "c"]', () => expect([...insert(new GroupQueue(['b', 'c', 'b', 'c']), 'd')]).toEqual([['b', 'b'], ['c', 'c'], ['d']]));
|
||||
it('"b" -> ["b", "c", "b", "c"]', () => expect([...insert(new GroupQueue(['b', 'c', 'b', 'c']), 'b')]).toEqual([['b', 'b', 'b'], ['c', 'c']]));
|
||||
});
|
||||
|
||||
describe('itemOf / remove', () => {
|
||||
function remove<T>(queue: GroupQueue<T>, value: T): T[][] {
|
||||
const item = queue.itemOf(value);
|
||||
if (item) {
|
||||
queue.remove(item);
|
||||
}
|
||||
return [...queue].map(json);
|
||||
}
|
||||
it('[] - 0', () => expect([...remove(new GroupQueue<number>([]), 0)]).toEqual([]));
|
||||
it('[1] - 0', () => expect([...remove(new GroupQueue([1]), 0)]).toEqual([[1]]));
|
||||
it('[1] - 1', () => expect([...remove(new GroupQueue([1]), 1)]).toEqual([]));
|
||||
it('["b", "c", "b", "c"] - "d"', () => expect([...remove(new GroupQueue(['b', 'c', 'b', 'c']), 'd')]).toEqual([['b', 'b'], ['c', 'c']]));
|
||||
it('["b", "c", "b", "c"] - "b"', () => expect([...remove(new GroupQueue(['b', 'c', 'b', 'c']), 'b')]).toEqual([['c', 'c'], ['b']]));
|
||||
});
|
||||
|
||||
describe('pop', () => {
|
||||
function pop<T>(queue: GroupQueue<T>): [T[], T[][]] {
|
||||
return [[...queue.pop() ?? []].map(({ value }) => value), [...queue].map(json)];
|
||||
}
|
||||
it('[]', () => expect([...pop(new GroupQueue<number>([]))]).toEqual([[], []]));
|
||||
it('[1]', () => expect([...pop(new GroupQueue([1]))]).toEqual([[1], []]));
|
||||
it('["b", "c", "b", "c"]', () => expect([...pop(new GroupQueue(['b', 'c', 'b', 'c']))]).toEqual([['b', 'b'], [['c', 'c']]]));
|
||||
});
|
||||
});
|
||||
+65
-703
@@ -1,726 +1,88 @@
|
||||
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');
|
||||
import { List, ListItem } from '../src/data/list';
|
||||
|
||||
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._(_([]))._(_l(x => _l(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('from / to array', () => {
|
||||
it('[]', () => expect([...new List([])]).toEqual([]));
|
||||
it('[1]', () => expect([...new List([1])]).toEqual([1]));
|
||||
it('["b", "c", "b", "c"]', () => expect([...new List(['b', 'c', 'b', 'c'])]).toEqual(['b', 'c', 'b', 'c']));
|
||||
});
|
||||
|
||||
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('length', () => {
|
||||
it('[]', () => expect(new List([]).length).toEqual(0));
|
||||
it('[1]', () => expect(new List([1]).length).toEqual(1));
|
||||
it('["b", "c", "b", "c"]', () => expect(new List(['b', 'c', 'b', 'c']).length).toEqual(4));
|
||||
});
|
||||
|
||||
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)._(_l(x => _l(_ => x))))).toBe(0);
|
||||
});
|
||||
describe('first', () => {
|
||||
it('[]', () => expect(new List([]).first).toBeUndefined());
|
||||
it('[1]', () => expect(new List([1]).first).toEqual(1));
|
||||
it('["b", "c", "b", "c"]', () => expect(new List(['b', 'c', 'b', 'c']).first).toEqual('b'));
|
||||
});
|
||||
|
||||
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)._(_l(x => _l(_ => x))))).toBe(0);
|
||||
});
|
||||
describe('last', () => {
|
||||
it('[]', () => expect(new List([]).last).toBeUndefined());
|
||||
it('[1]', () => expect(new List([1]).last).toEqual(1));
|
||||
it('["b", "c", "b", "c"]', () => expect(new List(['b', 'c', 'b', 'c']).last).toEqual('c'));
|
||||
});
|
||||
|
||||
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('prepend', () => {
|
||||
function prepend<T>(list: List<T>, value: T): List<T> {
|
||||
list.prepend(value);
|
||||
return list;
|
||||
}
|
||||
it('0 -> []', () => expect([...prepend(new List<number>([]), 0)]).toEqual([0]));
|
||||
it('0 -> [1]', () => expect([...prepend(new List([1]), 0)]).toEqual([0, 1]));
|
||||
it('"d" -> ["b", "c", "b", "c"]', () => expect([...prepend(new List(['b', 'c', 'b', 'c']), 'd')]).toEqual(['d', 'b', 'c', 'b', 'c']));
|
||||
});
|
||||
|
||||
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)._(_l(x => _l(_ => x))))).toBe(0);
|
||||
});
|
||||
function append<T>(list: List<T>, value: T): List<T> {
|
||||
list.append(value);
|
||||
return list;
|
||||
}
|
||||
it('[] <- 0', () => expect([...append(new List<number>([]), 0)]).toEqual([0]));
|
||||
it('[1] <- 0', () => expect([...append(new List([1]), 0)]).toEqual([1, 0]));
|
||||
it('["b", "c", "b", "c"] <- "d"', () => expect([...append(new List(['b', 'c', 'b', 'c']), 'd')]).toEqual(['b', 'c', 'b', 'c', 'd']));
|
||||
});
|
||||
|
||||
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)._(_l(x => _l(_ => x))))).toBe(0);
|
||||
});
|
||||
describe('includes', () => {
|
||||
it('[] not includes 0', () => expect(new List<number>([]).includes(0)).toBe(false));
|
||||
it('[1] not includes 0', () => expect(new List([1]).includes(0)).toBe(false));
|
||||
it('[1] includes 1', () => expect(new List([1]).includes(1)).toBe(true));
|
||||
it('["b", "c", "b", "c"] not includes "d"', () => expect(new List(['b', 'c', 'b', 'c']).includes('d')).toBe(false));
|
||||
it('["b", "c", "b", "c"] includes "b"', () => expect(new List(['b', 'c', 'b', 'c']).includes('b')).toBe(true));
|
||||
});
|
||||
|
||||
// describe('repeat', () => {
|
||||
// it('repeat 0 is [0, 0, 0, ...]', () => {
|
||||
// expect($na(
|
||||
// repeat._(_n(0))<List<Num>>(l((x0: Num) => l((x1s: List<Num>) =>
|
||||
// x1s<List<Num>>(l((x1: Num) => l((x2s: List<Num>) =>
|
||||
// x2s<List<Num>>(l((x2: Num) => l((_xrs: List<Num>): List<Num> => cons._(x0)._(cons._(x1)._(cons._(x2)._(Nil)))))))))))))).toEqual([0, 0, 0]);
|
||||
// });
|
||||
// });
|
||||
describe('itemOf / set', () => {
|
||||
function update<T>(list: List<T>, from: T, to: T): List<T> {
|
||||
const item: ListItem<T> | undefined = list.itemOf(from);
|
||||
if (item) {
|
||||
list.set(item, to);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// describe('iterate', () => {
|
||||
// it('iterate succ 0 is [0, 1, 2, ...]', () => {
|
||||
// expect($na(
|
||||
// iterate._(_n(0))<List<Num>>(l((x0: Num) => l((x1s: List<Num>) =>
|
||||
// x1s<List<Num>>(l((x1: Num) => l((x2s: List<Num>) =>
|
||||
// x2s<List<Num>>(l((x2: Num) => l((_xrs: List<Num>): List<Num> => 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);
|
||||
});
|
||||
it('[]: 0 -> 1', () => expect([...update(new List<number>([]), 0, 1)]).toEqual([]));
|
||||
it('[1]: 0 -> 1', () => expect([...update(new List([1]), 0, 1)]).toEqual([1]));
|
||||
it('[1]: 1 -> 0', () => expect([...update(new List([1]), 1, 0)]).toEqual([0]));
|
||||
it('["b", "c", "b", "c"]: "b" -> "d"', () => expect([...update(new List(['b', 'c', 'b', 'c']), 'b', 'd')]).toEqual(['d', 'c', 'b', 'c']));
|
||||
it('["b", "c", "b", "c"]: "d" -> "b"', () => expect([...update(new List(['b', 'c', 'b', 'c']), 'd', 'b')]).toEqual(['b', 'c', 'b', 'c']));
|
||||
});
|
||||
|
||||
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
|
||||
._(_l(x => _l(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
|
||||
._(_l(x => _l(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('[');
|
||||
});
|
||||
describe('itemOf / delete', () => {
|
||||
function remove<T>(list: List<T>, value: T): List<T> {
|
||||
const item: ListItem<T> | undefined = list.itemOf(value);
|
||||
if (item) {
|
||||
list.delete(item);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
it('[] - 0', () => expect([...remove(new List<number>([]), 0)]).toEqual([]));
|
||||
it('[1] - 0', () => expect([...remove(new List([1]), 0)]).toEqual([1]));
|
||||
it('[1] - 1', () => expect([...remove(new List([1]), 1)]).toEqual([]));
|
||||
it('["b", "c", "b", "c"] - "b"', () => expect([...remove(new List(['b', 'c', 'b', 'c']), 'b')]).toEqual(['c', 'b', 'c']));
|
||||
it('["b", "c", "b", "c"] - "d"', () => expect([...remove(new List(['b', 'c', 'b', 'c']), 'd')]).toEqual(['b', 'c', 'b', 'c']));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,409 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { Term, _, g, n, undef } from '../src/core';
|
||||
import { toNOrd as $o, NOrd } from '../src/ord';
|
||||
import { toBoolean as $b, fromBoolean as _b } from '../src/bool';
|
||||
import { toNumber as $n, Succ, Zero, fromNumber as _n, cmp, div, eq, ge, gt, ifz, le, lt, mod, mul, pred, sub, succ, sum } from '../src/num';
|
||||
import { toString as $s } from '../src/string';
|
||||
import { show } from '../src/num.show';
|
||||
|
||||
n('num.spec');
|
||||
|
||||
describe('Num', () => {
|
||||
const infinity: Term = g('infinity', _(() => Succ._(infinity)));
|
||||
|
||||
describe('toNumber', () => {
|
||||
it('converts 0', () => {
|
||||
expect($n(Zero)).toBe(0);
|
||||
});
|
||||
|
||||
it('converts 1', () => {
|
||||
expect($n(Succ._(Zero))).toBe(1);
|
||||
});
|
||||
|
||||
it('converts 2', () => {
|
||||
expect($n(Succ._(Succ._(Zero)))).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fromNumber', () => {
|
||||
it('converts 0', () => {
|
||||
expect($n(_n(0))).toBe(0);
|
||||
});
|
||||
|
||||
it('converts 1', () => {
|
||||
expect($n(_n(1))).toBe(1);
|
||||
});
|
||||
|
||||
it('converts 2', () => {
|
||||
expect($n(_n(2))).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ifz', () => {
|
||||
it('returns zero branch', () => {
|
||||
expect($b(ifz._(_n(0))._(_b(true))._(_b(false)))).toBe(true);
|
||||
});
|
||||
|
||||
it('returns non-zero branch', () => {
|
||||
expect($b(ifz._(_n(1))._(_b(true))._(_b(false)))).toBe(false);
|
||||
});
|
||||
|
||||
it('returns non-zero branch', () => {
|
||||
expect($b(ifz._(_n(10))._(_b(true))._(_b(false)))).toBe(false);
|
||||
});
|
||||
|
||||
it('handles infinity', () => {
|
||||
expect($b(ifz._(infinity)._(_b(true))._(_b(false)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('succ', () => {
|
||||
it('succ 0 is 1', () => {
|
||||
expect($n(succ._(_n(0)))).toBe(1);
|
||||
});
|
||||
|
||||
it('succ 1 is 2', () => {
|
||||
expect($n(succ._(_n(1)))).toBe(2);
|
||||
});
|
||||
|
||||
it('succ 10 is 11', () => {
|
||||
expect($n(succ._(_n(10)))).toBe(11);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pred', () => {
|
||||
it('pred 0 is 0', () => {
|
||||
expect($n(pred._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('pred 1 is 0', () => {
|
||||
expect($n(pred._(_n(1)))).toBe(0);
|
||||
});
|
||||
|
||||
it('pred 10 is 9', () => {
|
||||
expect($n(pred._(_n(10)))).toBe(9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cmp', () => {
|
||||
it('0 cmp 0 is EQ', () => {
|
||||
expect($o(cmp._(_n(0))._(_n(0)))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('0 cmp 1 is LT', () => {
|
||||
expect($o(cmp._(_n(0))._(_n(1)))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('1 cmp 0 is GT', () => {
|
||||
expect($o(cmp._(_n(1))._(_n(0)))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('3 cmp 3 is EQ', () => {
|
||||
expect($o(cmp._(_n(3))._(_n(3)))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('3 cmp 7 is LT', () => {
|
||||
expect($o(cmp._(_n(3))._(_n(7)))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('7 cmp 3 is GT', () => {
|
||||
expect($o(cmp._(_n(7))._(_n(3)))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('handles infinity', () => {
|
||||
expect($o(cmp._(_n(7))._(infinity))).toBe(NOrd.LT);
|
||||
expect($o(cmp._(infinity)._(_n(7)))).toBe(NOrd.GT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lt', () => {
|
||||
it('0 lt 0 is False', () => {
|
||||
expect($b(lt._(_n(0))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('0 lt 1 is True', () => {
|
||||
expect($b(lt._(_n(0))._(_n(1)))).toBe(true);
|
||||
});
|
||||
|
||||
it('1 lt 0 is False', () => {
|
||||
expect($b(lt._(_n(1))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 lt 3 is False', () => {
|
||||
expect($b(lt._(_n(3))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 lt 7 is True', () => {
|
||||
expect($b(lt._(_n(3))._(_n(7)))).toBe(true);
|
||||
});
|
||||
|
||||
it('7 lt 3 is False', () => {
|
||||
expect($b(lt._(_n(7))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('handles infinity', () => {
|
||||
expect($b(lt._(_n(7))._(infinity))).toBe(true);
|
||||
expect($b(lt._(infinity)._(_n(7)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('le', () => {
|
||||
it('0 le 0 is True', () => {
|
||||
expect($b(le._(_n(0))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 le 1 is True', () => {
|
||||
expect($b(le._(_n(0))._(_n(1)))).toBe(true);
|
||||
});
|
||||
|
||||
it('1 le 0 is False', () => {
|
||||
expect($b(le._(_n(1))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 le 3 is True', () => {
|
||||
expect($b(le._(_n(3))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 le 7 is True', () => {
|
||||
expect($b(le._(_n(3))._(_n(7)))).toBe(true);
|
||||
});
|
||||
|
||||
it('7 le 3 is False', () => {
|
||||
expect($b(le._(_n(7))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('handles infinity', () => {
|
||||
expect($b(le._(_n(7))._(infinity))).toBe(true);
|
||||
expect($b(le._(infinity)._(_n(7)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eq', () => {
|
||||
it('0 eq 0 is True', () => {
|
||||
expect($b(eq._(_n(0))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 eq 1 is False', () => {
|
||||
expect($b(eq._(_n(0))._(_n(1)))).toBe(false);
|
||||
});
|
||||
|
||||
it('1 eq 0 is False', () => {
|
||||
expect($b(eq._(_n(1))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 eq 3 is True', () => {
|
||||
expect($b(eq._(_n(3))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 eq 7 is False', () => {
|
||||
expect($b(eq._(_n(3))._(_n(7)))).toBe(false);
|
||||
});
|
||||
|
||||
it('7 eq 3 is False', () => {
|
||||
expect($b(eq._(_n(7))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('handles infinity', () => {
|
||||
expect($b(eq._(_n(7))._(infinity))).toBe(false);
|
||||
expect($b(eq._(infinity)._(_n(7)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ge', () => {
|
||||
it('0 ge 0 is True', () => {
|
||||
expect($b(ge._(_n(0))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('0 ge 1 is False', () => {
|
||||
expect($b(ge._(_n(0))._(_n(1)))).toBe(false);
|
||||
});
|
||||
|
||||
it('1 ge 0 is True', () => {
|
||||
expect($b(ge._(_n(1))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 ge 3 is True', () => {
|
||||
expect($b(ge._(_n(3))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 ge 7 is False', () => {
|
||||
expect($b(ge._(_n(3))._(_n(7)))).toBe(false);
|
||||
});
|
||||
|
||||
it('7 ge 3 is True', () => {
|
||||
expect($b(ge._(_n(7))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('handles infinity', () => {
|
||||
expect($b(ge._(_n(7))._(infinity))).toBe(false);
|
||||
expect($b(ge._(infinity)._(_n(7)))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gt', () => {
|
||||
it('0 gt 0 is False', () => {
|
||||
expect($b(gt._(_n(0))._(_n(0)))).toBe(false);
|
||||
});
|
||||
|
||||
it('0 gt 1 is False', () => {
|
||||
expect($b(gt._(_n(0))._(_n(1)))).toBe(false);
|
||||
});
|
||||
|
||||
it('1 gt 0 is True', () => {
|
||||
expect($b(gt._(_n(1))._(_n(0)))).toBe(true);
|
||||
});
|
||||
|
||||
it('3 gt 3 is False', () => {
|
||||
expect($b(gt._(_n(3))._(_n(3)))).toBe(false);
|
||||
});
|
||||
|
||||
it('3 gt 7 is False', () => {
|
||||
expect($b(gt._(_n(3))._(_n(7)))).toBe(false);
|
||||
});
|
||||
|
||||
it('7 gt 3 is True', () => {
|
||||
expect($b(gt._(_n(7))._(_n(3)))).toBe(true);
|
||||
});
|
||||
|
||||
it('handles infinity', () => {
|
||||
expect($b(gt._(_n(7))._(infinity))).toBe(false);
|
||||
expect($b(gt._(infinity)._(_n(7)))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sum', () => {
|
||||
it('0 sum 0 is 0', () => {
|
||||
expect($n(sum._(_n(0))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('0 sum 1 is 1', () => {
|
||||
expect($n(sum._(_n(0))._(_n(1)))).toBe(1);
|
||||
});
|
||||
|
||||
it('1 sum 0 is 1', () => {
|
||||
expect($n(sum._(_n(1))._(_n(0)))).toBe(1);
|
||||
});
|
||||
|
||||
it('3 sum 4 is 7', () => {
|
||||
expect($n(sum._(_n(3))._(_n(4)))).toBe(7);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sub', () => {
|
||||
it('0 sub 0 is 0', () => {
|
||||
expect($n(sub._(_n(0))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('0 sub 1 is 0', () => {
|
||||
expect($n(sub._(_n(0))._(_n(1)))).toBe(0);
|
||||
});
|
||||
|
||||
it('1 sub 0 is 1', () => {
|
||||
expect($n(sub._(_n(1))._(_n(0)))).toBe(1);
|
||||
});
|
||||
|
||||
it('7 sub 4 is 3', () => {
|
||||
expect($n(sub._(_n(7))._(_n(4)))).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mul', () => {
|
||||
it('0 mul 0 is 0', () => {
|
||||
expect($n(mul._(_n(0))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('0 mul 10 is 0', () => {
|
||||
expect($n(mul._(_n(0))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 mul 0 is 0', () => {
|
||||
expect($n(mul._(_n(1))._(_n(0)))).toBe(0);
|
||||
});
|
||||
|
||||
it('1 mul 10 is 10', () => {
|
||||
expect($n(mul._(_n(1))._(_n(10)))).toBe(10);
|
||||
});
|
||||
|
||||
it('10 mul 1 is 10', () => {
|
||||
expect($n(mul._(_n(10))._(_n(1)))).toBe(10);
|
||||
});
|
||||
|
||||
it('3 mul 4 is 12', () => {
|
||||
expect($n(mul._(_n(3))._(_n(4)))).toBe(12);
|
||||
});
|
||||
|
||||
it('0 mul ignores second argument', () => {
|
||||
expect($n(mul._(_n(0))._(undef))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('div', () => {
|
||||
it('0 div 10 is 0', () => {
|
||||
expect($n(div._(_n(0))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('1 div 10 is 0', () => {
|
||||
expect($n(div._(_n(1))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 div 1 is 10', () => {
|
||||
expect($n(div._(_n(10))._(_n(1)))).toBe(10);
|
||||
});
|
||||
|
||||
it('10 div 5 is 2', () => {
|
||||
expect($n(div._(_n(10))._(_n(5)))).toBe(2);
|
||||
});
|
||||
|
||||
it('10 div 3 is 3', () => {
|
||||
expect($n(div._(_n(10))._(_n(3)))).toBe(3);
|
||||
});
|
||||
|
||||
it.failing('0 div ignores second argument', () => {
|
||||
expect($n(div._(_n(0))._(undef))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mod', () => {
|
||||
it('0 mod 10 is 0', () => {
|
||||
expect($n(mod._(_n(0))._(_n(10)))).toBe(0);
|
||||
});
|
||||
|
||||
it('1 mod 10 is 1', () => {
|
||||
expect($n(mod._(_n(1))._(_n(10)))).toBe(1);
|
||||
});
|
||||
|
||||
it('10 mod 1 is 0', () => {
|
||||
expect($n(mod._(_n(10))._(_n(1)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 mod 5 is 0', () => {
|
||||
expect($n(mod._(_n(10))._(_n(5)))).toBe(0);
|
||||
});
|
||||
|
||||
it('10 mod 3 is 1', () => {
|
||||
expect($n(mod._(_n(10))._(_n(3)))).toBe(1);
|
||||
});
|
||||
|
||||
it.failing('0 mod ignores second argument', () => {
|
||||
expect($n(mod._(_n(0))._(undef))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('show', () => {
|
||||
it('show 0 is "0"', () => {
|
||||
expect($s(show._(_n(0)))).toBe('0');
|
||||
});
|
||||
|
||||
it('show 1 is "1"', () => {
|
||||
expect($s(show._(_n(1)))).toBe('1');
|
||||
});
|
||||
|
||||
it('show 255 is "255"', () => {
|
||||
expect($s(show._(_n(255)))).toBe('255');
|
||||
});
|
||||
|
||||
it('show 1000 is "1000"', () => {
|
||||
expect($s(show._(_n(1000)))).toBe('1000');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,233 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { undef } from '../src/core';
|
||||
import { toNOrd as $o, NOrd } from '../src/ord';
|
||||
import { toBoolean as $b, fromBoolean as _b, cmp as bcmp, eq as beq, not } from '../src/bool';
|
||||
import { toNumber as $n, fromNumber as _n, cmp as ncmp, eq as neq, succ } from '../src/num';
|
||||
import { Pair, both, cmp, eq, first, fst, ge, gt, le, lt, second, snd } from '../src/pair';
|
||||
import { toString } from '../src/string';
|
||||
import { show as bshow } from '../src/bool.show';
|
||||
import { show as nshow } from '../src/num.show';
|
||||
import { show } from '../src/pair.show';
|
||||
|
||||
describe('Pair', () => {
|
||||
describe('fst', () => {
|
||||
it('returns first', () => {
|
||||
expect($b(fst._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores second', () => {
|
||||
expect($b(fst._(Pair._(_b(false))._(undef)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('snd', () => {
|
||||
it('returns second', () => {
|
||||
expect($n(snd._(Pair._(_b(false))._(_n(0))))).toBe(0);
|
||||
});
|
||||
|
||||
it('ignores first', () => {
|
||||
expect($n(snd._(Pair._(undef)._(_n(0))))).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('first', () => {
|
||||
it('updates first', () => {
|
||||
expect($b(fst._(first._(not)._(Pair._(_b(false))._(_n(0)))))).toBe(true);
|
||||
});
|
||||
|
||||
it('ignores second', () => {
|
||||
expect($b(fst._(first._(not)._(Pair._(_b(false))._(undef))))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('second', () => {
|
||||
it('updates second', () => {
|
||||
expect($n(snd._(second._(succ)._(Pair._(_b(false))._(_n(0)))))).toBe(1);
|
||||
});
|
||||
|
||||
it('ignores first', () => {
|
||||
expect($n(snd._(second._(succ)._(Pair._(undef)._(_n(0)))))).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('both', () => {
|
||||
it('updates both', () => {
|
||||
expect($b(fst._(both._(not)._(succ)._(Pair._(_b(false))._(_n(0)))))).toBe(true);
|
||||
expect($n(snd._(both._(not)._(succ)._(Pair._(_b(false))._(_n(0)))))).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cmp', () => {
|
||||
it('(False, 0) cmp (False, 0) is EQ', () => {
|
||||
expect($o(cmp._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('(False, 0) cmp (False, 1) is LT', () => {
|
||||
expect($o(cmp._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(1))))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('(False, 1) cmp (False, 0) is GT', () => {
|
||||
expect($o(cmp._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(1)))._(Pair._(_b(false))._(_n(0))))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('(False, 0) cmp (True, 0) is LT', () => {
|
||||
expect($o(cmp._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(true))._(_n(0))))).toBe(NOrd.LT);
|
||||
});
|
||||
|
||||
it('(True, 0) cmp (False, 0) is GT', () => {
|
||||
expect($o(cmp._(bcmp)._(ncmp)._(Pair._(_b(true))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(NOrd.GT);
|
||||
});
|
||||
|
||||
it('ignores second if first not equal', () => {
|
||||
expect($o(cmp._(bcmp)._(undef)._(Pair._(_b(false))._(undef))._(Pair._(_b(true))._(undef)))).toBe(NOrd.LT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lt', () => {
|
||||
it('(False, 0) lt (False, 0) is False', () => {
|
||||
expect($b(lt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 0) lt (False, 1) is True', () => {
|
||||
expect($b(lt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(1))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(False, 1) lt (False, 0) is False', () => {
|
||||
expect($b(lt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(1)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 0) lt (True, 0) is True', () => {
|
||||
expect($b(lt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(true))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(True, 0) lt (False, 0) is False', () => {
|
||||
expect($b(lt._(bcmp)._(ncmp)._(Pair._(_b(true))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores second if first not equal', () => {
|
||||
expect($b(lt._(bcmp)._(undef)._(Pair._(_b(false))._(undef))._(Pair._(_b(true))._(undef)))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('le', () => {
|
||||
it('(False, 0) le (False, 0) is True', () => {
|
||||
expect($b(le._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(False, 0) le (False, 1) is True', () => {
|
||||
expect($b(le._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(1))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(False, 1) le (False, 0) is False', () => {
|
||||
expect($b(le._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(1)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 0) le (True, 0) is True', () => {
|
||||
expect($b(le._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(true))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(True, 0) le (False, 0) is False', () => {
|
||||
expect($b(le._(bcmp)._(ncmp)._(Pair._(_b(true))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores second if first not equal', () => {
|
||||
expect($b(le._(bcmp)._(undef)._(Pair._(_b(false))._(undef))._(Pair._(_b(true))._(undef)))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eq', () => {
|
||||
it('(False, 0) eq (False, 0) is True', () => {
|
||||
expect($b(eq._(beq)._(neq)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(False, 0) eq (False, 1) is False', () => {
|
||||
expect($b(eq._(beq)._(neq)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(1))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 1) eq (False, 0) is False', () => {
|
||||
expect($b(eq._(beq)._(neq)._(Pair._(_b(false))._(_n(1)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 0) eq (True, 0) is True', () => {
|
||||
expect($b(eq._(beq)._(neq)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(true))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(True, 0) eq (False, 0) is True', () => {
|
||||
expect($b(eq._(beq)._(neq)._(Pair._(_b(true))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('ignores second if first not equal', () => {
|
||||
expect($b(eq._(beq)._(undef)._(Pair._(_b(false))._(undef))._(Pair._(_b(true))._(undef)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ge', () => {
|
||||
it('(False, 0) ge (False, 0) is True', () => {
|
||||
expect($b(ge._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(False, 0) ge (False, 1) is False', () => {
|
||||
expect($b(ge._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(1))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 1) ge (False, 0) is True', () => {
|
||||
expect($b(ge._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(1)))._(Pair._(_b(false))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(False, 0) ge (True, 0) is False', () => {
|
||||
expect($b(ge._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(true))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(True, 0) ge (False, 0) is True', () => {
|
||||
expect($b(ge._(bcmp)._(ncmp)._(Pair._(_b(true))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('ignores second if first not equal', () => {
|
||||
expect($b(ge._(bcmp)._(undef)._(Pair._(_b(false))._(undef))._(Pair._(_b(true))._(undef)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gt', () => {
|
||||
it('(False, 0) gt (False, 0) is False', () => {
|
||||
expect($b(gt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 0) gt (False, 1) is False', () => {
|
||||
expect($b(gt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(false))._(_n(1))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(False, 1) gt (False, 0) is True', () => {
|
||||
expect($b(gt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(1)))._(Pair._(_b(false))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('(False, 0) gt (True, 0) is False', () => {
|
||||
expect($b(gt._(bcmp)._(ncmp)._(Pair._(_b(false))._(_n(0)))._(Pair._(_b(true))._(_n(0))))).toBe(false);
|
||||
});
|
||||
|
||||
it('(True, 0) gt (False, 0) is True', () => {
|
||||
expect($b(gt._(bcmp)._(ncmp)._(Pair._(_b(true))._(_n(0)))._(Pair._(_b(false))._(_n(0))))).toBe(true);
|
||||
});
|
||||
|
||||
it('ignores second if first not equal', () => {
|
||||
expect($b(gt._(bcmp)._(undef)._(Pair._(_b(false))._(undef))._(Pair._(_b(true))._(undef)))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('show', () => {
|
||||
it('show (False, 0) is "(False, 0)"', () => {
|
||||
expect(toString(show._(bshow)._(nshow)._(Pair._(_b(false))._(_n(0))))).toBe('(False, 0)');
|
||||
});
|
||||
|
||||
it('show (False, 1) is "(False, 1)"', () => {
|
||||
expect(toString(show._(bshow)._(nshow)._(Pair._(_b(false))._(_n(1))))).toBe('(False, 1)');
|
||||
});
|
||||
|
||||
it('show (True, 0) is "(True, 0)"', () => {
|
||||
expect(toString(show._(bshow)._(nshow)._(Pair._(_b(true))._(_n(0))))).toBe('(True, 0)');
|
||||
});
|
||||
|
||||
it('show (True, 1) is "(True, 1)"', () => {
|
||||
expect(toString(show._(bshow)._(nshow)._(Pair._(_b(true))._(_n(1))))).toBe('(True, 1)');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,376 +0,0 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { Term, _, _l, g, n, undef } from '../src/core';
|
||||
import { NOrd, toNOrd } from '../src/ord';
|
||||
import { toBoolean as $b } from '../src/bool';
|
||||
import { toNumber as $n, Zero, gt as ngt } from '../src/num';
|
||||
import { toChar as $c, fromChar as _c } from '../src/char';
|
||||
import { toString as $s, Cons, Empty, fromString as _s, append, cmp, empty, eq, ge, gt, le, len, lt, wrap } from '../src/string';
|
||||
import { show } from '../src/string.show';
|
||||
|
||||
n('string.spec');
|
||||
|
||||
describe('String', () => {
|
||||
const infinite: Term = g('infinite', _(() => Cons._(_c('a'))._(infinite)));
|
||||
|
||||
describe('toString', () => {
|
||||
it('converts ""', () => {
|
||||
expect($s(Empty)).toBe('');
|
||||
});
|
||||
|
||||
it('converts "a"', () => {
|
||||
expect($s(Cons._(_c('a'))._(Empty))).toBe('a');
|
||||
});
|
||||
|
||||
it('converts "abc"', () => {
|
||||
expect($s(Cons._(_c('a'))._(Cons._(_c('b'))._(Cons._(_c('c'))._(Empty))))).toBe('abc');
|
||||
});
|
||||
});
|
||||
|
||||
describe('fromString', () => {
|
||||
it('converts ""', () => {
|
||||
expect($s(_s(''))).toBe('');
|
||||
});
|
||||
|
||||
it('converts "a"', () => {
|
||||
expect($s(_s('a'))).toBe('a');
|
||||
});
|
||||
|
||||
it('converts "2"', () => {
|
||||
expect($s(_s('abc'))).toBe('abc');
|
||||
});
|
||||
});
|
||||
|
||||
// describe('repeat', () => {
|
||||
// it('repeat "a" is "aaa..."', () => {
|
||||
// expect($na(
|
||||
// repeat(_s('a'))<String>(_((x0: Char) => _((x1s: String) =>
|
||||
// x1s<String>(_((x1: Char) => _((x2s: String) =>
|
||||
// x2s<String>(_((x2: Char) => _((_xrs: String): String => cons(x0)._(cons(x1)._(cons(x2)._(Nil)))))))))))))).toEqual('aaa');
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('iterate', () => {
|
||||
// it('iterate succ "a" is "abc..."', () => {
|
||||
// expect($na(
|
||||
// iterate(_s('a'))<String>(_((x0: Char) => _((x1s: String) =>
|
||||
// x1s<String>(_((x1: Char) => _((x2s: String) =>
|
||||
// x2s<String>(_((x2: Char) => _((_xrs: String): String => cons(x0)._(cons(x1)._(cons(x2)._(Nil)))))))))))))).toEqual('abc');
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('empty', () => {
|
||||
it('empty "" is True', () => {
|
||||
expect($b(empty._(_s('')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('empty "a" is False', () => {
|
||||
expect($b(empty._(_s('a')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('empty "ab" is False', () => {
|
||||
expect($b(empty._(_s('ab')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('handles infinite lists', () => {
|
||||
expect($b(empty._(infinite))).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('len', () => {
|
||||
it('len "" is 0', () => {
|
||||
expect($n(len._(_s('')))).toEqual(0);
|
||||
});
|
||||
|
||||
it('len "a" is 1', () => {
|
||||
expect($n(len._(_s('a')))).toEqual(1);
|
||||
});
|
||||
|
||||
it('len "ab" is 2', () => {
|
||||
expect($n(len._(_s('ab')))).toEqual(2);
|
||||
});
|
||||
|
||||
it('handles infinite lists', () => {
|
||||
expect($b(ngt._(len._(infinite))._(Zero))).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('append', () => {
|
||||
it('"" append "" is ""', () => {
|
||||
expect($s(append._(Empty)._(Empty))).toBe('');
|
||||
});
|
||||
|
||||
it('"a" append "b" is "ab"', () => {
|
||||
expect($s(append._(_s('a'))._(_s('b')))).toBe('ab');
|
||||
});
|
||||
|
||||
it('"abc" append "def" is "abcdef"', () => {
|
||||
expect($s(append._(_s('abc'))._(_s('def')))).toBe('abcdef');
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect($c(append._(infinite)._(infinite)._(undef)._(_l(x => _l(_ => x))))).toBe('a');
|
||||
});
|
||||
});
|
||||
|
||||
describe('wrap', () => {
|
||||
it('"" wrap "" is ""', () => {
|
||||
expect($s(wrap._(Empty)._(Empty))).toBe('');
|
||||
});
|
||||
|
||||
it('"a" wrap "b" is "aba"', () => {
|
||||
expect($s(wrap._(_s('a'))._(_s('b')))).toBe('aba');
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect($c(wrap._(infinite)._(infinite)._(undef)._(_l(x => _l(_ => x))))).toBe('a');
|
||||
});
|
||||
});
|
||||
|
||||
describe('cmp', () => {
|
||||
it('"" cmp "" is EQ', () => {
|
||||
expect(toNOrd(cmp._(_s(''))._(_s('')))).toEqual(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('"" cmp "abc" is LT', () => {
|
||||
expect(toNOrd(cmp._(_s(''))._(_s('abc')))).toEqual(NOrd.LT);
|
||||
});
|
||||
|
||||
it('"abc" cmp "" is GT', () => {
|
||||
expect(toNOrd(cmp._(_s('abc'))._(_s('')))).toEqual(NOrd.GT);
|
||||
});
|
||||
|
||||
it('"a" cmp "abc" is LT', () => {
|
||||
expect(toNOrd(cmp._(_s('a'))._(_s('abc')))).toEqual(NOrd.LT);
|
||||
});
|
||||
|
||||
it('"abc" cmp "a" is GT', () => {
|
||||
expect(toNOrd(cmp._(_s('abc'))._(_s('a')))).toEqual(NOrd.GT);
|
||||
});
|
||||
|
||||
it('"bca" cmp "abc" is GT', () => {
|
||||
expect(toNOrd(cmp._(_s('bca'))._(_s('abc')))).toEqual(NOrd.GT);
|
||||
});
|
||||
|
||||
it('"abc" cmp "bca" is LT', () => {
|
||||
expect(toNOrd(cmp._(_s('abc'))._(_s('bca')))).toEqual(NOrd.LT);
|
||||
});
|
||||
|
||||
it('"abc" cmp "abc" is EQ', () => {
|
||||
expect(toNOrd(cmp._(_s('abc'))._(_s('abc')))).toEqual(NOrd.EQ);
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect(toNOrd(cmp._(_s('abc'))._(infinite))).toEqual(NOrd.GT);
|
||||
expect(toNOrd(cmp._(infinite)._(_s('abc')))).toEqual(NOrd.LT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lt', () => {
|
||||
it('"" lt "" is False', () => {
|
||||
expect($b(lt._(_s(''))._(_s('')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"" lt "abc" is True', () => {
|
||||
expect($b(lt._(_s(''))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" lt "" is False', () => {
|
||||
expect($b(lt._(_s('abc'))._(_s('')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"a" lt "abc" is True', () => {
|
||||
expect($b(lt._(_s('a'))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" lt "a" is False', () => {
|
||||
expect($b(lt._(_s('abc'))._(_s('a')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"bca" lt "abc" is False', () => {
|
||||
expect($b(lt._(_s('bca'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" lt "bca" is True', () => {
|
||||
expect($b(lt._(_s('abc'))._(_s('bca')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" lt "abc" is False', () => {
|
||||
expect($b(lt._(_s('abc'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect($b(lt._(_s('abc'))._(infinite))).toEqual(false);
|
||||
expect($b(lt._(infinite)._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('le', () => {
|
||||
it('"" le "" is True', () => {
|
||||
expect($b(le._(_s(''))._(_s('')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"" le "abc" is True', () => {
|
||||
expect($b(le._(_s(''))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" le "" is False', () => {
|
||||
expect($b(le._(_s('abc'))._(_s('')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"a" le "abc" is True', () => {
|
||||
expect($b(le._(_s('a'))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" le "a" is False', () => {
|
||||
expect($b(le._(_s('abc'))._(_s('a')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"bca" le "abc" is False', () => {
|
||||
expect($b(le._(_s('bca'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" le "bca" is True', () => {
|
||||
expect($b(le._(_s('abc'))._(_s('bca')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" le "abc" is True', () => {
|
||||
expect($b(le._(_s('abc'))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect($b(le._(_s('abc'))._(infinite))).toEqual(false);
|
||||
expect($b(le._(infinite)._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eq', () => {
|
||||
it('"" eq "" is True', () => {
|
||||
expect($b(eq._(_s(''))._(_s('')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"" eq "abc" is False', () => {
|
||||
expect($b(eq._(_s(''))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" eq "" is False', () => {
|
||||
expect($b(eq._(_s('abc'))._(_s('')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"a" eq "abc" is False', () => {
|
||||
expect($b(eq._(_s('a'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" eq "a" is False', () => {
|
||||
expect($b(eq._(_s('abc'))._(_s('a')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"bca" eq "abc" is False', () => {
|
||||
expect($b(eq._(_s('bca'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" eq "bca" is False', () => {
|
||||
expect($b(eq._(_s('abc'))._(_s('bca')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" eq "abc" is True', () => {
|
||||
expect($b(eq._(_s('abc'))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect($b(eq._(_s('abc'))._(infinite))).toEqual(false);
|
||||
expect($b(eq._(infinite)._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ge', () => {
|
||||
it('"" ge "" is True', () => {
|
||||
expect($b(ge._(_s(''))._(_s('')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"" ge "abc" is False', () => {
|
||||
expect($b(ge._(_s(''))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" ge "" is True', () => {
|
||||
expect($b(ge._(_s('abc'))._(_s('')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"a" ge "abc" is False', () => {
|
||||
expect($b(ge._(_s('a'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" ge "a" is True', () => {
|
||||
expect($b(ge._(_s('abc'))._(_s('a')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"bca" ge "abc" is True', () => {
|
||||
expect($b(ge._(_s('bca'))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" ge "bca" is False', () => {
|
||||
expect($b(ge._(_s('abc'))._(_s('bca')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" ge "abc" is True', () => {
|
||||
expect($b(ge._(_s('abc'))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect($b(ge._(_s('abc'))._(infinite))).toEqual(true);
|
||||
expect($b(ge._(infinite)._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gt', () => {
|
||||
it('"" gt "" is False', () => {
|
||||
expect($b(gt._(_s(''))._(_s('')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"" gt "abc" is False', () => {
|
||||
expect($b(gt._(_s(''))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" gt "" is True', () => {
|
||||
expect($b(gt._(_s('abc'))._(_s('')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"a" gt "abc" is False', () => {
|
||||
expect($b(gt._(_s('a'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" gt "a" is True', () => {
|
||||
expect($b(gt._(_s('abc'))._(_s('a')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"bca" gt "abc" is True', () => {
|
||||
expect($b(gt._(_s('bca'))._(_s('abc')))).toEqual(true);
|
||||
});
|
||||
|
||||
it('"abc" gt "bca" is False', () => {
|
||||
expect($b(gt._(_s('abc'))._(_s('bca')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('"abc" gt "abc" is False', () => {
|
||||
expect($b(gt._(_s('abc'))._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
|
||||
it('handles infinite strings', () => {
|
||||
expect($b(gt._(_s('abc'))._(infinite))).toEqual(true);
|
||||
expect($b(gt._(infinite)._(_s('abc')))).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('show', () => {
|
||||
it('show "" is """"', () => {
|
||||
expect($s(show._(_s('')))).toBe('""');
|
||||
});
|
||||
|
||||
it('show "a" is ""a""', () => {
|
||||
expect($s(show._(_s('a')))).toBe('"a"');
|
||||
});
|
||||
|
||||
it('show "abc" is ""abc""', () => {
|
||||
expect($s(show._(_s('abc')))).toBe('"abc"');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user