boolean-expressions
Version:
Boolean expression parser and evaluator. Makes use of the Ohm grammar package with grammar rules found [here](https://github.com/avadavat/boolean-expressions/blob/master/src/grammar/grammarRules.ts).
408 lines (407 loc) • 12.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var operators_1 = require("./operators");
function generateTestCases() {
var testCases = [
{
expression: "p and notq",
variableNames: ["p", "notq"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "not p and q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "p and not q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "p or not q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "not p or q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "not p xor q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "not p and not q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "p and q and s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "p and q and not s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "p and not q and s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "p and not (q and s)",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "not p and q and s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "p",
variableNames: ["p"],
truthTable: [
[],
[]
]
},
{
expression: "p and q or s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "(p and q) or s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "if p then q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "p and q -> s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "p -> q and s",
variableNames: ["p", "q", "s"],
truthTable: [
[],
[],
[],
[],
[],
[],
[],
[]
]
},
{
expression: "p and q and true",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "p and false and q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
},
{
expression: "true or p and q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
}
];
// AND operators:
operators_1.andOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// OR operators:
operators_1.orOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// XOR operators:
operators_1.xorOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// NOT operators:
operators_1.notOperators.forEach(function (op) {
testCases.push({
expression: op + " p",
variableNames: ["p"],
truthTable: [
[],
[]
]
});
});
// IF operators:
operators_1.ifOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// BICONDITIONAL operators:
operators_1.biconditionalOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// CONVERSE operators:
operators_1.converseOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// NONIMPLICATION operators:
operators_1.nonimplicationOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// CONVERSE NONIMPLICATION operators:
operators_1.converseNonimplicationOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// NAND operators:
operators_1.nandOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// NOR operators:
operators_1.norOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
// XNOR operators:
operators_1.xnorOperators.forEach(function (op) {
testCases.push({
expression: "p " + op + " q",
variableNames: ["p", "q"],
truthTable: [
[],
[],
[],
[]
]
});
});
return testCases;
}
exports.default = generateTestCases;