Lambda calculus-like library written in TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
jlc/test/char.spec.ts

214 lines
5.1 KiB

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, show } from '../src/char';
import { toString as $s } from '../src/string';
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('\'-\'');
});
});
});