def test_braces(self): t = TruthTable('(((A <-> B) -> A) | B) & ~A') t.generate() expected = [(0, 0, 0), (0, 1, 1), (1, 0, 0), (1, 1, 0)] self.assertEqual(t.table, expected)
def test_operation_precedence(self): t = TruthTable('A <-> B -> A | B & ~A') t.generate() expected = [(0, 0, 0), (0, 1, 0), (1, 0, 1), (1, 1, 1)] self.assertEqual(t.table, expected)
def test_identity(self): t = TruthTable('A') t.generate() expected = [(0, 0), (1, 1)] self.assertEqual(t.table, expected)
def test_implication(self): t = TruthTable('A -> B') t.generate() expected = [(0, 0, 1), (0, 1, 1), (1, 0, 0), (1, 1, 1)] self.assertEqual(t.table, expected)
def test_equality(self): t = TruthTable('A <-> B') t.generate() expected = [(0, 0, 1), (0, 1, 0), (1, 0, 0), (1, 1, 1)] self.assertEqual(t.table, expected)
def test_disjunction(self): t = TruthTable('A | B') t.generate() expected = [(0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 1)] self.assertEqual(t.table, expected)
def test_negation(self): t = TruthTable('~A') t.generate() expected = [(0, 1), (1, 0)] self.assertEqual(t.table, expected)
def test_false(self): t = TruthTable('A & ~A') t.generate() expected = [(0, 0), (1, 0)] self.assertEqual(t.table, expected)
def test_true(self): t = TruthTable('A | ~A') t.generate() expected = [(0, 1), (1, 1)] self.assertEqual(t.table, expected)
from truthtable import TruthTable from sys import argv import fileinput lines = [] inp = fileinput.input(argv[1]) if len(argv) > 1 else fileinput.input() for line in inp: lines.append(line) lines = (x.strip().upper() for x in lines) lines = (x for x in lines if x) for line in lines: t = TruthTable(line) t.generate() print(t, '\n')