Ejemplo n.º 1
0
        public void AlterationTest()
        {
            // Create inital combination
            ExpressionBool expression = _expression1.Combine(_expression2, ExpressionOperator.And) as ExpressionBool;

            Assert.IsTrue(expression.Result);

            // Alter combined object
            _expression2 = _expression2.Combine(_expression3, ExpressionOperator.And) as ExpressionBool;
            Assert.IsTrue(expression.Result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses (AST)Node recursively
        /// </summary>
        /// <param name="node">Node to parse</param>
        /// <param name="condition">Base condition, optional</param>
        /// <returns>Collection of widgets</returns>
        public static ElementManager ParseChildNode(Node node, ElementManagerController elementManagerController, ElementManagerCollection parent, ExpressionBool condition = null)
        {
            switch (node.Type)
            {
            case NodeType.CONDITIONAL:
                ExpressionFactory expressionFactory = new ExpressionFactory(elementManagerController);
                // Parse condition
                ExpressionBool newCondition = expressionFactory.GetCondition(node as ConditionalNode);

                newCondition = (condition == null) ? newCondition : condition.Combine(newCondition, ExpressionOperator.And) as ExpressionBool;

                // Add children with new condition
                parent.AddChildren(node.Children.Select(o => ParseChildNode(o, elementManagerController, parent, newCondition)).Where(o => o != null));

                // return parent
                return(null);

            case NodeType.FORM:
                throw new InvalidOperationException("Cannot stack form nodes");

            case NodeType.QUESTION:
                return(CreateElementManager(node as QuestionNode, condition, parent, elementManagerController));

            case NodeType.COMPUTED:
                return(CreateComputedWidget(node as ComputedNode, condition, parent, elementManagerController));
            }

            throw new NotImplementedException();
        }
        /// <summary>
        /// Parses Node recursively
        /// </summary>
        /// <param name="node">Node to parse</param>
        /// <param name="condition">Base condition, optional</param>
        /// <returns>Collection of widgets</returns>
        public static ElementManager ParseChildNode(QLNode node, ElementManagerController elementManagerController, ElementManagerCollection parent, ExpressionBool condition = null)
        {
            ExpressionFactory expressionFactory = new ExpressionFactory(elementManagerController);

            switch (node)
            {
            case ConditionalNode conditionalNode:
                // Parse condition
                ExpressionBool newCondition = expressionFactory.GetCondition(conditionalNode);

                newCondition = (condition == null) ? newCondition : condition.Combine(newCondition, ExpressionOperator.And) as ExpressionBool;

                // Add children with new condition
                parent.AddChildren(conditionalNode.Children.Select(o => ParseChildNode(o, elementManagerController, parent, newCondition)).Where(o => o != null));
                return(null);

            case QuestionNode questionNode:
                return(CreateElementManager(questionNode, condition, parent, elementManagerController, null));

            case ComputedNode computedNode:
                ExpressionValue expression = expressionFactory.ParseExpressionNode(computedNode.Expression);
                return(CreateElementManager(computedNode, condition, parent, elementManagerController, expression));
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 4
0
        public void EqualsTest()
        {
            // true == true
            ExpressionBool expression = _expression1.Combine(_expression2, ExpressionOperator.Equals) as ExpressionBool;

            Assert.IsTrue(expression.Result);

            // (true == true) == false
            expression = expression.Combine(_expression3, ExpressionOperator.Equals) as ExpressionBool;
            Assert.IsFalse(expression.Result);
        }
Ejemplo n.º 5
0
        public void OrTest()
        {
            // true || true
            ExpressionBool expression = _expression1.Combine(_expression2, ExpressionOperator.Or) as ExpressionBool;

            Assert.IsTrue(expression.Result);

            // true || true || false
            expression = expression.Combine(_expression3, ExpressionOperator.Or) as ExpressionBool;
            Assert.IsTrue(expression.Result);
        }
Ejemplo n.º 6
0
        public void AndTest()
        {
            // true && true
            ExpressionBool expression = _expression1.Combine(_expression2, ExpressionOperator.And) as ExpressionBool;

            Assert.IsTrue(expression.Result);

            // true && true && false
            expression = expression.Combine(_expression3, ExpressionOperator.And) as ExpressionBool;
            Assert.IsFalse(expression.Result);
        }