Exemple #1
0
        public void GetHashTest()
        {
            // test 01
            AbstractionSyntaxTree ast = new AbstractionSyntaxTree("=(a,b)");
            TruthTable            tb  = new TruthTable(ast);

            Assert.AreEqual("9", tb.GetHash());

            // test 02
            ast = new AbstractionSyntaxTree("=(>(a,b),b)");
            tb  = new TruthTable(ast);

            Assert.AreEqual("E", tb.GetHash());


            // test 03
            ast = new AbstractionSyntaxTree("|(a,&(b,%(c,>(d,=(e,~(f))))))");
            tb  = new TruthTable(ast);

            Assert.AreEqual("FFFFFFFF90FF0000", tb.GetHash());
        }
Exemple #2
0
        public void ToNandTest()
        {
            // test 01
            string expression         = "&(~(%(p,q)), |(p, q))";
            AbstractionSyntaxTree ast = new AbstractionSyntaxTree(expression);

            ast.Build();

            Symbol s = ast.ToNand();

            Assert.AreEqual("((((p % q) % (p % q)) % ((p % p) % (q % q))) % (((p % q) % (p % q)) % ((p % p) % (q % q))))", ast.ToNand().ToString());

            TruthTable            tb       = new TruthTable(ast);
            string                oriHash  = tb.GetHash();
            AbstractionSyntaxTree nandTree = ObjectExtensions.Copy(ast);

            nandTree.Root = nandTree.Root.toNand();
            TruthTable nandTB   = new TruthTable(nandTree);
            string     nandHash = nandTB.GetHash();

            // test 02
            expression = "=(p,q)";
            ast        = new AbstractionSyntaxTree(expression);
            ast.Build();

            s = ast.ToNand();
            Assert.AreEqual("(((p % p) % (q % q)) % (p % q))", ast.ToNand().ToString());

            tb            = new TruthTable(ast);
            oriHash       = tb.GetHash();
            nandTree      = ObjectExtensions.Copy(ast);
            nandTree.Root = nandTree.Root.toNand();
            nandTB        = new TruthTable(nandTree);
            nandHash      = nandTB.GetHash();

            // test 03
            expression = ">(p, q)";
            ast        = new AbstractionSyntaxTree(expression);
            ast.Build();

            s = ast.ToNand();
            Assert.AreEqual("(p % (q % q))", ast.ToNand().ToString());

            tb            = new TruthTable(ast);
            oriHash       = tb.GetHash();
            nandTree      = ObjectExtensions.Copy(ast);
            nandTree.Root = nandTree.Root.toNand();
            nandTB        = new TruthTable(nandTree);
            nandHash      = nandTB.GetHash();

            // test 04
            expression = "!x.(@y.(&(P(x, x), Q(y, x))))";
            ast        = new AbstractionSyntaxTree(expression);
            ast.Build();

            s = ast.ToNand();
            Assert.AreEqual("!x.(@y.(((P(x,x) % Q(y,x)) % (P(x,x) % Q(y,x)))))", ast.ToNand().ToString());

            tb            = new TruthTable(ast);
            oriHash       = tb.GetHash();
            nandTree      = ObjectExtensions.Copy(ast);
            nandTree.Root = nandTree.Root.toNand();
            nandTB        = new TruthTable(nandTree);
            nandHash      = nandTB.GetHash();

            // test 05
            expression = "!x.(@y.(&(P(x, x, y, x), Q(y, x))))";
            ast        = new AbstractionSyntaxTree(expression);
            ast.Build();

            s = ast.ToNand();
            Assert.AreEqual("!x.(@y.(((P(x,x,y,x) % Q(y,x)) % (P(x,x,y,x) % Q(y,x)))))", ast.ToNand().ToString());

            tb            = new TruthTable(ast);
            oriHash       = tb.GetHash();
            nandTree      = ObjectExtensions.Copy(ast);
            nandTree.Root = nandTree.Root.toNand();
            nandTB        = new TruthTable(nandTree);
            nandHash      = nandTB.GetHash();
        }