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.
116 lines
3.7 KiB
116 lines
3.7 KiB
import { describe, expect, it } from '@jest/globals';
|
|
import { _, Q } from '../src/core';
|
|
import { True, False, iif, and, not, or, xor, toBoolean, fromBoolean } from '../src/bool';
|
|
|
|
describe('Bool', () => {
|
|
describe('toBoolean', () => {
|
|
it('converts True', () => {
|
|
expect(toBoolean(True)).toBe(true);
|
|
});
|
|
|
|
it('converts False', () => {
|
|
expect(toBoolean(False)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('fromBoolean', () => {
|
|
it('converts true', () => {
|
|
expect(toBoolean(fromBoolean(true))).toBe(true);
|
|
});
|
|
|
|
it('converts false', () => {
|
|
expect(toBoolean(fromBoolean(false))).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('iif', () => {
|
|
it('returns true argument', () => {
|
|
expect(iif).toDeferEvaluationOf(False, expect.skipped(_(true as unknown as Q)), _(false as unknown as Q));
|
|
expect(iif(True).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(true);
|
|
});
|
|
|
|
it('returns false argument', () => {
|
|
expect(iif).toDeferEvaluationOf(True, _(true as unknown as Q), expect.skipped(_(false as unknown as Q)));
|
|
expect(iif(False).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(false);
|
|
});
|
|
});
|
|
|
|
describe('not', () => {
|
|
it('not False is True', () => {
|
|
expect(not).toDeferEvaluationOf(False);
|
|
expect(toBoolean(not(False))).toBe(true);
|
|
|
|
});
|
|
|
|
it('not True is False', () => {
|
|
expect(not).toDeferEvaluationOf(True);
|
|
expect(toBoolean(not(True))).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('and', () => {
|
|
it('False and False is False', () => {
|
|
expect(and).toDeferEvaluationOf(False, expect.skipped(False));
|
|
expect(toBoolean(and(False).then(e => e(False)))).toBe(false);
|
|
});
|
|
|
|
it('False and True is False', () => {
|
|
expect(and).toDeferEvaluationOf(False, expect.skipped(True));
|
|
expect(toBoolean(and(False).then(e => e(True)))).toBe(false);
|
|
});
|
|
|
|
it('True and False is False', () => {
|
|
expect(and).toDeferEvaluationOf(True, False);
|
|
expect(toBoolean(and(True).then(e => e(False)))).toBe(false);
|
|
});
|
|
|
|
it('True and True is True', () => {
|
|
expect(and).toDeferEvaluationOf(True, True);
|
|
expect(toBoolean(and(True).then(e => e(True)))).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('or', () => {
|
|
it('False or False is False', () => {
|
|
expect(or).toDeferEvaluationOf(False, False);
|
|
expect(toBoolean(or(False).then(e => e(False)))).toBe(false);
|
|
});
|
|
|
|
it('False or True is True', () => {
|
|
expect(or).toDeferEvaluationOf(False, True);
|
|
expect(toBoolean(or(False).then(e => e(True)))).toBe(true);
|
|
});
|
|
|
|
it('True or False is True', () => {
|
|
expect(or).toDeferEvaluationOf(True, expect.skipped(False));
|
|
expect(toBoolean(or(True).then(e => e(False)))).toBe(true);
|
|
});
|
|
|
|
it('True or True is True', () => {
|
|
expect(or).toDeferEvaluationOf(True, expect.skipped(True));
|
|
expect(toBoolean(or(True).then(e => e(True)))).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('xor', () => {
|
|
it('False xor False is False', () => {
|
|
expect(xor).toDeferEvaluationOf(False, False);
|
|
expect(toBoolean(xor(False).then(e => e(False)))).toBe(false);
|
|
});
|
|
|
|
it('False xor True is True', () => {
|
|
expect(xor).toDeferEvaluationOf(False, True);
|
|
expect(toBoolean(xor(False).then(e => e(True)))).toBe(true);
|
|
});
|
|
|
|
it('True xor False is True', () => {
|
|
expect(xor).toDeferEvaluationOf(True, False);
|
|
expect(toBoolean(xor(True).then(e => e(False)))).toBe(true);
|
|
});
|
|
|
|
it('True xor True is False', () => {
|
|
expect(xor).toDeferEvaluationOf(True, True);
|
|
expect(toBoolean(xor(True).then(e => e(True)))).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|