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.
118 lines
3.6 KiB
118 lines
3.6 KiB
import { describe, expect, it } from '@jest/globals';
|
|
import { _ } 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).toDeferEvaluationOf(True);
|
|
expect(toBoolean(True)).toEvaluateTo(true);
|
|
});
|
|
|
|
it('converts False', () => {
|
|
expect(toBoolean).toDeferEvaluationOf(False);
|
|
expect(toBoolean(False)).toEvaluateTo(false);
|
|
});
|
|
});
|
|
|
|
describe('fromBoolean', () => {
|
|
it('converts true', () => {
|
|
expect(toBoolean(fromBoolean(true))).toEvaluateTo(true);
|
|
});
|
|
|
|
it('converts false', () => {
|
|
expect(toBoolean(fromBoolean(false))).toEvaluateTo(false);
|
|
});
|
|
});
|
|
|
|
describe('iif', () => {
|
|
it('returns true argument', () => {
|
|
expect(iif).toDeferEvaluationOf(False, expect.skipped(true), false);
|
|
expect(iif(True)(_(true))(_(false))).toEvaluateTo(true);
|
|
});
|
|
|
|
it('returns false argument', () => {
|
|
expect(iif).toDeferEvaluationOf(True, true, expect.skipped(false));
|
|
expect(iif(False)(_(true))(_(false))).toEvaluateTo(false);
|
|
});
|
|
});
|
|
|
|
describe('not', () => {
|
|
it('not False is True', () => {
|
|
expect(not).toDeferEvaluationOf(False);
|
|
expect(toBoolean(not(False))).toEvaluateTo(true);
|
|
|
|
});
|
|
|
|
it('not True is False', () => {
|
|
expect(not).toDeferEvaluationOf(True);
|
|
expect(toBoolean(not(True))).toEvaluateTo(false);
|
|
});
|
|
});
|
|
|
|
describe('and', () => {
|
|
it('False and False is False', () => {
|
|
expect(and).toDeferEvaluationOf(False, expect.skipped(False));
|
|
expect(toBoolean(and(False)(False))).toEvaluateTo(false);
|
|
});
|
|
|
|
it('False and True is False', () => {
|
|
expect(and).toDeferEvaluationOf(False, expect.skipped(True));
|
|
expect(toBoolean(and(False)(True))).toEvaluateTo(false);
|
|
});
|
|
|
|
it('True and False is False', () => {
|
|
expect(and).toDeferEvaluationOf(True, False);
|
|
expect(toBoolean(and(True)(False))).toEvaluateTo(false);
|
|
});
|
|
|
|
it('True and True is True', () => {
|
|
expect(and).toDeferEvaluationOf(True, True);
|
|
expect(toBoolean(and(True)(True))).toEvaluateTo(true);
|
|
});
|
|
});
|
|
|
|
describe('or', () => {
|
|
it('False or False is False', () => {
|
|
expect(or).toDeferEvaluationOf(False, False);
|
|
expect(toBoolean(or(False)(False))).toEvaluateTo(false);
|
|
});
|
|
|
|
it('False or True is True', () => {
|
|
expect(or).toDeferEvaluationOf(False, True);
|
|
expect(toBoolean(or(False)(True))).toEvaluateTo(true);
|
|
});
|
|
|
|
it('True or False is True', () => {
|
|
expect(or).toDeferEvaluationOf(True, expect.skipped(False));
|
|
expect(toBoolean(or(True)(False))).toEvaluateTo(true);
|
|
});
|
|
|
|
it('True or True is True', () => {
|
|
expect(or).toDeferEvaluationOf(True, expect.skipped(True));
|
|
expect(toBoolean(or(True)(True))).toEvaluateTo(true);
|
|
});
|
|
});
|
|
|
|
describe('xor', () => {
|
|
it('False xor False is False', () => {
|
|
expect(xor).toDeferEvaluationOf(False, False);
|
|
expect(toBoolean(xor(False)(False))).toEvaluateTo(false);
|
|
});
|
|
|
|
it('False xor True is True', () => {
|
|
expect(xor).toDeferEvaluationOf(False, True);
|
|
expect(toBoolean(xor(False)(True))).toEvaluateTo(true);
|
|
});
|
|
|
|
it('True xor False is True', () => {
|
|
expect(xor).toDeferEvaluationOf(True, False);
|
|
expect(toBoolean(xor(True)(False))).toEvaluateTo(true);
|
|
});
|
|
|
|
it('True xor True is False', () => {
|
|
expect(xor).toDeferEvaluationOf(True, True);
|
|
expect(toBoolean(xor(True)(True))).toEvaluateTo(false);
|
|
});
|
|
});
|
|
});
|
|
|