Beispiel #1
0
        /// <summary>
        /// The base constructor
        /// </summary>
        /// <param name="type">A logical operation's type</param>
        /// <param name="firstOp">The operand stores an integer value</param>
        /// <param name="secondOp">The operand is needed when modulo comparison is used (stores 1 or 0)</param>

        public CLambdaPredicateASTNode(E_LOGIC_OP_TYPE type, IValueASTNode firstOp, IValueASTNode secondOp) :
            base(E_NODE_TYPE.NT_LAMBDA_PREDICATE)
        {
            mLogicOpType = type;

            IASTNode firstOpNode  = firstOp as IASTNode;
            IASTNode secondOpNode = secondOp as IASTNode;

            firstOpNode.Parent = this;

            firstOpNode.NodeId = 0;

            mChildren.Add(firstOpNode);

            if (secondOpNode != null)
            {
                secondOpNode.Parent = this;

                secondOpNode.NodeId = 1;

                mChildren.Add(secondOpNode);
            }

            mAttributes = E_NODE_ATTRIBUTES.NA_IS_LEAF_NODE;
        }
Beispiel #2
0
        public void TestVisitLambdaPredicateNode_CheckLambdaPredicateGeneration_ReturnsLambdaPredicate(E_LOGIC_OP_TYPE type, int x, int value, bool res)
        {
            IVisitor <Object> interpreter = new CInterpreter();

            Func <int, bool> lambdaPredicate = null;

            Assert.DoesNotThrow(() => {
                lambdaPredicate = (Func <int, bool>)interpreter.VisitLambdaPredicateNode(
                    new CLambdaPredicateASTNode(type, new CValueASTNode(new int[] { value }), null));
            });

            Assert.AreEqual(res, lambdaPredicate(x));
        }