-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogicTest.cpp
96 lines (74 loc) · 2.89 KB
/
LogicTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//LogicTest.cpp
#include "statementevaluator.h"
#include "LogicGate.h"
#include "expressionparser.h"
#include "Tree.h"
using namespace std;
#include "LogicGate.h"
void variableHeaderTest() {
cout << "---------- VARIABLE HEADER TEST ----------\n\n";
StatementEvaluator eval;
// Variable Header Test
StatementParser headerTest("A & B & C");
vector<string> varTruthValues;
varTruthValues.emplace_back("Red");
varTruthValues.emplace_back("Green");
varTruthValues.emplace_back("Blue");
eval.printTruthTable(headerTest, varTruthValues);
cout << endl;
}
void equivalenceTest() {
cout << "---------- EQUIVALENCE TEST ----------\n\n";
StatementEvaluator eval;
// Equivalence Test 1 (DeMorgan's : True)
StatementParser statement1("A & B");
cout << "\nTruth Table For " << "A & B" << ": " << endl;
eval.printTruthTable(statement1);
StatementParser statement2("~(~A | ~B)");
cout << "\nTruth Table For " << "~(~A | ~B)" << ": " << endl;
eval.printTruthTable(statement2);
cout << endl << "statement1 and statement2 are equal: " << boolalpha << eval.areLogicallyEquivalent(statement1, statement2) << endl << endl;
// Equivalence Test 2 (Complex : True)
StatementParser statement3("~(A | ~(B | (~C & D))) | (C & B) | ~A");
cout << "\nTruth Table For " << "~(A | ~(B | (~C & D))) | (C & B) | ~A" << ": " << endl;
eval.printTruthTable(statement3);
StatementParser statement4("~A | (C & B)");
cout << "\nTruth Table For " << "~A | (C & B)" << ": " << endl;
eval.printTruthTable(statement4);
cout << endl << "statement3 and statement4 are equal: " << boolalpha << eval.areLogicallyEquivalent(statement3, statement4) << endl << endl;
// Equivalence Test 3 (Basic : False)
StatementParser statement5("A & B");
cout << "\nTruth Table For " << "A & B" << ": " << endl;
eval.printTruthTable(statement5);
StatementParser statement6("A & ~B");
cout << "\nTruth Table For " << "A & ~B" << ": " << endl;
eval.printTruthTable(statement6);
cout << endl << "statement5 and statement6 are equal: " << boolalpha << eval.areLogicallyEquivalent(statement5, statement6) << endl << endl;
}
void memoryTest() {
cout << "---------- MEMORY TEST ----------\n\n";
StatementEvaluator eval;
StatementParser statement1("A & ~B");
StatementParser statement2("A & B");
// Assignment Operator
statement2 = statement1;
cout << "\nShould Be Truth Table For " << "A & ~B" << ": " << endl;
eval.printTruthTable(statement2);
// Copy Constructor
StatementParser statement3(statement2);
cout << "\nShould Be Truth Table For " << "A & ~B" << ": " << endl;
eval.printTruthTable(statement3);
// Join Constructor
StatementParser statement4("A");
StatementParser statement5("~B");
StatementParser statement6(statement4, statement5);
cout << "\nShould Be Truth Table For " << "A & ~B" << ": " << endl;
eval.printTruthTable(statement6);
cout << endl;
}
int main() {
variableHeaderTest();
equivalenceTest();
memoryTest();
return EXIT_SUCCESS;
}