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, show, sub, sum, x00 } from '../src/byte'; import { toString as $s } from '../src/string'; 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'); }); }); });