Ejemplo n.º 1
0
        public void SelectsInverse()
        {
            var spec = new IntegerGreaterThanZero();
            var negatedSpec = new Negation<int>(spec);

            Assert.That(negatedSpec.IsSatisfiedBy(1), Is.False);
            Assert.That(negatedSpec.IsSatisfiedBy(0), Is.True);
            Assert.That(negatedSpec.IsSatisfiedBy(-1), Is.True);
        }
Ejemplo n.º 2
0
        public void NegatesCriteria()
        {
            var spec = new IntegerPredicate(i => i == 0);
            var criteria = spec.Criteria;
            var negatedSpec = new Negation<int>(spec);
            var negatedCriteria = negatedSpec.Criteria;

            Assert.That(negatedCriteria.Body, Is.TypeOf<UnaryExpression>());

            var unary = (UnaryExpression)negatedCriteria.Body;

            Assert.That(unary.NodeType, Is.EqualTo(ExpressionType.Not));
            Assert.That(unary.Operand, Is.EqualTo(criteria.Body));
            Assert.That(unary.Method, Is.Null);
            Assert.That(unary.IsLifted, Is.False);
            Assert.That(unary.IsLiftedToNull, Is.False);

            ExpressionWriter.Write(negatedCriteria);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Generates the text for a Negation builder.
 /// </summary>
 /// <param name="item">The Negation builder to generate the text for.</param>
 protected internal override void VisitNegation(Negation item)
 {
     writer.Write("-");
     bool wrapInParentheses = shouldWrapNegationInParentheses(item);
     if (wrapInParentheses)
     {
         writer.Write("(");
     }
     item.Item.Accept(forSubCommand());
     if (wrapInParentheses)
     {
         writer.Write(")");
     }
 }
Ejemplo n.º 4
0
 public double Satisfy (State currentState, Negation negation)
 {
     return 1 - Satisfy (currentState, negation.Enclosed);
 }
Ejemplo n.º 5
0
 protected override EP_VP1 Visit(Negation node)
 {
     node.Children[0].Visit(this);
     return(this);
 }
Ejemplo n.º 6
0
 protected internal virtual T Visit(Negation node)
 {
     return(Visit(node as Expression));
 }
Ejemplo n.º 7
0
 public void Visit(Negation visitable) => visitable.Data = !visitable.LeftNode.Data;
Ejemplo n.º 8
0
 public virtual T Visit(Negation negation)
 {
     return(VisitUnaryExpression(negation));
 }
Ejemplo n.º 9
0
        public static void NegationHasCorrectType()
        {
            var negation = new Negation(One);

            Assert.AreEqual(SymbolType.Negation, negation.Type);
        }
        //Methods
        public Proposition InsertInBinaryTree(ref string s)
        {
            Proposition root = null;

            switch (s[0])
            {
            case '>':
            {
                root = new Implication();
                s    = s.Substring(2);
                while (s[0] != ',')
                {
                    root.LeftNode = InsertInBinaryTree(ref s);
                    s             = s.Substring(1);
                }
                s = s.Substring(1);
                while (s[0] != ')')
                {
                    root.RightNode = InsertInBinaryTree(ref s);
                    s = s.Substring(1);
                }
                break;
            }

            case '=':
            {
                root = new BiImplication();
                s    = s.Substring(2);
                while (s[0] != ',')
                {
                    root.LeftNode = InsertInBinaryTree(ref s);
                    s             = s.Substring(1);
                }
                s = s.Substring(1);
                while (s[0] != ')')
                {
                    root.RightNode = InsertInBinaryTree(ref s);
                    s = s.Substring(1);
                }
                break;
            }

            case '&':
            {
                root = new And();
                s    = s.Substring(2);
                while (s[0] != ',')
                {
                    root.LeftNode = InsertInBinaryTree(ref s);
                    s             = s.Substring(1);
                }
                s = s.Substring(1);
                while (s[0] != ')')
                {
                    root.RightNode = InsertInBinaryTree(ref s);
                    s = s.Substring(1);
                }
                break;
            }

            case '|':
            {
                root = new Or();
                s    = s.Substring(2);
                while (s[0] != ',')
                {
                    root.LeftNode = InsertInBinaryTree(ref s);
                    s             = s.Substring(1);
                }
                s = s.Substring(1);
                while (s[0] != ')')
                {
                    root.RightNode = InsertInBinaryTree(ref s);
                    s = s.Substring(1);
                }
                break;
            }

            case '~':
            {
                root = new Negation();
                s    = s.Substring(2);
                while (s[0] != ')')
                {
                    root.LeftNode = InsertInBinaryTree(ref s);
                    s             = s.Substring(1);
                }
                break;
            }

            case '%':
            {
                root = new NAND();
                s    = s.Substring(2);
                while (s[0] != ',')
                {
                    root.LeftNode = InsertInBinaryTree(ref s);
                    s             = s.Substring(1);
                }
                s = s.Substring(1);
                while (s[0] != ')')
                {
                    root.RightNode = InsertInBinaryTree(ref s);
                    s = s.Substring(1);
                }
                break;
            }

            default:
            {
                root = new Pro();
                (root as Pro).Notation = s[0].ToString();
                break;
            }
            }
            return(root);
        }
 //-----------------------------------------------------------
 public string Visit(Negation node)
 {
     return("\t\tldc.i4.0\n"
            + Visit((dynamic)node[0])
            + "\t\tsub\n");
 }
Ejemplo n.º 12
0
        // 3rd step
        public static Step MoveNegationInwardsStep(Step step)
        {
            step.Title = "Moving  Negation Inwards";
            bool endConditional;

            do
            {
                endConditional = false;
                List <Symbol> symbols = step.Top.ReverseBFS();
                foreach (var symbol in symbols)
                {
                    if (symbol is Negation && symbol.Children[0].IsFinal == false)
                    {
                        var parentSymbol = symbol.Parent;
                        var childSymbol  = symbol.Children[0];

                        if (childSymbol is Negation) // Negation case
                        {
                            endConditional = true;
                            if (parentSymbol == null)
                            {
                                step.Top = childSymbol.Children[0];
                            }
                            else
                            {
                                parentSymbol.SetChild(symbol.IndexInParent, childSymbol.Children[0]);
                            }
                        }
                        else if (childSymbol is Operator) // AND and OR case
                        {
                            // setting end conditional to true
                            endConditional = true;

                            if (childSymbol.Name == "AND")
                            {
                                Symbol newOperatorSymbol = new Operator(name: "OR");

                                var leftChildSymbol  = childSymbol.Children[0];
                                var rightChildSymbol = childSymbol.Children[1];

                                Symbol newLeftChild  = new Negation();
                                Symbol newRightChild = new Negation();

                                newLeftChild.SetChild(0, leftChildSymbol.Clone());
                                newRightChild.SetChild(1, rightChildSymbol.Clone());

                                newOperatorSymbol.SetChild(0, newLeftChild);
                                newOperatorSymbol.SetChild(1, newRightChild);

                                if (parentSymbol == null)
                                {
                                    step.Top = newOperatorSymbol;
                                }
                                else
                                {
                                    parentSymbol.SetChild(symbol.IndexInParent, newOperatorSymbol);
                                }
                            }
                            else if (childSymbol.Name == "OR")
                            {
                                Symbol newOperatorSymbol = new Operator(name: "AND");

                                var leftChildSymbol  = childSymbol.Children[0];
                                var rightChildSymbol = childSymbol.Children[1];

                                Symbol newLeftChild  = new Negation();
                                Symbol newRightChild = new Negation();

                                newLeftChild.SetChild(0, leftChildSymbol.Clone());
                                newRightChild.SetChild(1, rightChildSymbol.Clone());

                                newOperatorSymbol.SetChild(0, newLeftChild);
                                newOperatorSymbol.SetChild(1, newRightChild);

                                if (parentSymbol == null)
                                {
                                    step.Top = newOperatorSymbol;
                                }
                                else
                                {
                                    parentSymbol.SetChild(symbol.IndexInParent, newOperatorSymbol);
                                }
                            }
                        }
                        else if (childSymbol is Quantifier) // FORALL and EXISTS case
                        {
                            // setting end conditional to true
                            endConditional = true;
                            if (childSymbol.Name == "FORALL")
                            {
                                Symbol newOperatorSymbol = new Operator(name: "EXISTS");

                                var leftChildSymbol  = childSymbol.Children[0];
                                var rightChildSymbol = childSymbol.Children[1];

                                Symbol newRightChild = new Negation();

                                newRightChild.SetChild(0, rightChildSymbol.Clone());

                                newOperatorSymbol.SetChild(0, leftChildSymbol);
                                newOperatorSymbol.SetChild(1, newRightChild);

                                if (parentSymbol == null)
                                {
                                    step.Top = newOperatorSymbol;
                                }
                                else
                                {
                                    parentSymbol.SetChild(symbol.IndexInParent, newOperatorSymbol);
                                }
                            }
                            else if (childSymbol.Name == "EXISTS")
                            {
                                Symbol newOperatorSymbol = new Operator(name: "FORALL");

                                var leftChildSymbol  = childSymbol.Children[0];
                                var rightChildSymbol = childSymbol.Children[1];

                                Symbol newRightChild = new Negation();

                                newRightChild.SetChild(0, rightChildSymbol.Clone());

                                newOperatorSymbol.SetChild(0, leftChildSymbol);
                                newOperatorSymbol.SetChild(1, newRightChild);

                                if (parentSymbol == null)
                                {
                                    step.Top = newOperatorSymbol;
                                }
                                else
                                {
                                    parentSymbol.SetChild(symbol.IndexInParent, newOperatorSymbol);
                                }
                            }
                        }
                    }
                }
            } while (endConditional);

            return(step);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Visits a Negation builder.
 /// </summary>
 /// <param name="item">The item to visit.</param>
 protected internal virtual void VisitNegation(Negation item)
 {
 }
 void NegationCanBeExplicitly()
 {
     var a = new Negation();
     var b = !a;
 }
Ejemplo n.º 15
0
 private bool shouldWrapNegationInParentheses(Negation item)
 {
     // if the item is a literal, we don't need to wrap it in parentheses
     ArithmeticExpression expression = item.Item as ArithmeticExpression;
     if (expression == null)
     {
         return false;
     }
     // if the item is an arithmetic expression, don't double wrap
     if (expression.WrapInParentheses ?? options.WrapArithmeticExpressionsInParentheses)
     {
         return false;
     }
     // otherwise, wrap to preserve precedence
     return true;
 }
 public override object Visit(Negation negation)
 {
     ValidateUnaryExpression(negation);
     return(base.Visit(negation));
 }
Ejemplo n.º 17
0
 DEFINE_STANDARD_OP(Negation, NEGATION)
Ejemplo n.º 18
0
 if (loop.Body is IfThen(Negation n1, BreakStatement))
 {