Пример #1
0
 private void GetDNF()
 {
     if (myTruthTable.GetDNF() != null)
     {
         tbDisjuncNormalInF.Text  = myTruthTable.GetDNF().Infix();
         tbDisjuncNormalPreF.Text = myTruthTable.GetDNF().Prefix();
     }
     else
     {
         tbDisjuncNormalInF.Text  = "No DNF for this formula";
         tbDisjuncNormalPreF.Text = "No DNF for this formula";
     }
 }
Пример #2
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, "");
            }
        }