Esempio n. 1
0
        public void TestSimplifiedTruthTableDNF(string formula)
        {
            BinaryTree tree  = new BinaryTree(formula);
            TruthTable table = new TruthTable(tree);
            var        dnf   = table.GetDNF(table.SimplifiedTable);

            if (table.GetHashCode(table.OriginalTable) != 0 && Convert.ToString(table.GetHashCode(table.OriginalTable), 2).Contains('0'))
            {
                BinaryTree treeFromDnf  = new BinaryTree(dnf.PrefixFormat);
                TruthTable tableFromDnf = new TruthTable(treeFromDnf);
                Assert.AreEqual(table.GetHashCode(table.OriginalTable), tableFromDnf.GetHashCode(tableFromDnf.OriginalTable));
                string formulaWithoutBrackets = treeFromDnf.PrintParsedFormula().Replace("(", "");
                formulaWithoutBrackets = formulaWithoutBrackets.Replace(")", "");
                formulaWithoutBrackets = formulaWithoutBrackets.Replace(" ", "");
                string infixWithoutBrackets = dnf.InfixFormat.Replace("(", "");
                infixWithoutBrackets = infixWithoutBrackets.Replace(")", "");
                infixWithoutBrackets = infixWithoutBrackets.Replace(" ", "");
                Assert.AreEqual(formulaWithoutBrackets, infixWithoutBrackets);
            }
            else
            {
                Assert.AreEqual(dnf.PrefixFormat, "");
                string infixWithoutBrackets = dnf.InfixFormat.Replace("(", "");
                infixWithoutBrackets = infixWithoutBrackets.Replace(")", "");
                infixWithoutBrackets = infixWithoutBrackets.Replace(" ", "");
                Assert.AreEqual(infixWithoutBrackets, "");
            }
        }
Esempio n. 2
0
        public void TestSimplifiedTruthTableCreation(string formula, string expectedHashCode)
        {
            int        hashCodeInBinary = Convert.ToInt32(expectedHashCode, 2);
            BinaryTree tree             = new BinaryTree(formula);
            TruthTable table            = new TruthTable(tree);

            Assert.AreEqual(table.GetHashCode(table.SimplifiedTable), hashCodeInBinary);
        }