Пример #1
0
        public void OP_a_or_b_CP_and_not_OP_c_CP()
        {
            string           expr       = "(a or b) and not (c)";
            List <ExprToken> listTokens = TestCommon.AddTokens("(", "a", "or", "b", ")");

            TestCommon.AddTokens(listTokens, "and", "not", "(");
            TestCommon.AddTokens(listTokens, "c", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            var dictOperators = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(dictOperators);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens (a and not b) should be decoded with success");

            // check the root node: bin expr
            ExprLogical binExpr = result.RootExpr as ExprLogical;

            Assert.IsNotNull(binExpr, "The root node type should be ExprLogical");
            // the operator is: and
            Assert.AreEqual(OperatorLogicalCode.And, binExpr.Operator, "The operator should be and");

            //----the left part is : (a or b)
            ExprLogical exprLeftLogical = binExpr.ExprLeft as ExprLogical;

            Assert.IsNotNull(exprLeftLogical, "The root node type should be exprLeftLogical");
            // the operator is: or
            Assert.AreEqual(OperatorLogicalCode.Or, exprLeftLogical.Operator, "The operator should be or");
            // a
            ExprFinalOperand exprLeftLogicalLeftOperand = exprLeftLogical.ExprLeft as ExprFinalOperand;

            Assert.AreEqual("a", exprLeftLogicalLeftOperand.Operand, "The left operand should be a");

            // b
            ExprFinalOperand exprLeftLogicalRightOperand = exprLeftLogical.ExprRight as ExprFinalOperand;

            Assert.AreEqual("b", exprLeftLogicalRightOperand.Operand, "The right operand should be b");


            //----the right part is: not(c)
            ExprLogicalNot notExpr = binExpr.ExprRight as ExprLogicalNot;

            Assert.IsNotNull(notExpr, "The expr type should be ExprLogicalNot");
            ExprFinalOperand notExprOperandFinal = notExpr.ExprBase as ExprFinalOperand;

            Assert.AreEqual("c", notExprOperandFinal.Operand, "The not operand should be c");
        }
Пример #2
0
        public void OP_not_OP_a_and_CP_CP_ok()
        {
            string           expr       = "(not (a and b))";
            List <ExprToken> listTokens = TestCommon.AddTokens("(", "not", "(");

            TestCommon.AddTokens(listTokens, "a", "and", "b");
            TestCommon.AddTokens(listTokens, ")", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            var dictOperators = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(dictOperators);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens (not a) should be decoded with success");

            // check the root node: Not expr
            ExprLogicalNot rootBinExpr = result.RootExpr as ExprLogicalNot;

            Assert.IsNotNull(rootBinExpr, "The root node type should be BoolBinExprNot");

            // the inner expr is a logical expr: (a and b)
            ExprLogical binExpr = rootBinExpr.ExprBase as ExprLogical;

            Assert.IsNotNull(binExpr, "The root node type should be BoolBinExpr");

            // a
            ExprFinalOperand exprOperandLeft = binExpr.ExprLeft as ExprFinalOperand;

            Assert.IsNotNull(exprOperandLeft, "The root node type should be BoolBinExprOperand");
            Assert.AreEqual("a", exprOperandLeft.Operand, "The left operand should be a");

            // b
            ExprFinalOperand exprOperandRight = binExpr.ExprRight as ExprFinalOperand;

            Assert.IsNotNull(exprOperandRight, "The root node type should be BoolBinExprOperand");
            Assert.AreEqual("b", exprOperandRight.Operand, "The right operand should be b");

            // check the operator
            Assert.AreEqual(OperatorLogicalCode.And, binExpr.Operator, "The operator should be and");
        }
Пример #3
0
        public void fct_OP_a_CP_And_b_ok()
        {
            string           expr       = "fct(a) And b";
            List <ExprToken> listTokens = TestCommon.AddTokens("fct", "(", "a", ")", "And");

            TestCommon.AddTokens(listTokens, "b");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            ExpressionEvalConfig config = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(config);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // get the root expression
            ExprLogical exprLogical = result.RootExpr as ExprLogical;

            Assert.IsNotNull(exprLogical, "The root node type should be Logical");


            //----check the left part of the comparison: the function call
            ExprFunctionCall exprFunction = exprLogical.ExprLeft as ExprFunctionCall;

            Assert.IsNotNull(exprFunction, "The root node type should be ExprFunctionCall");
            Assert.AreEqual("fct", exprFunction.FunctionName, "The function name should be: fct");
            Assert.AreEqual(1, exprFunction.ListExprParameters.Count, "The function call should have one parameter");

            // check the parameter: its a final operand
            ExprFinalOperand paraFunction = exprFunction.ListExprParameters[0] as ExprFinalOperand;

            Assert.AreEqual("a", paraFunction.Operand, "The parameter name should be: a");
            Assert.IsTrue(paraFunction.ContentType == OperandType.ObjectName, "The parameter type should be: ObjectName");

            //----check the right part of the root node
            ExprFinalOperand operandRight = exprLogical.ExprRight as ExprFinalOperand;

            Assert.IsNotNull(operandRight, "The left root node type should be BoolBinExprOperand");
            Assert.AreEqual(operandRight.Operand, "b", "The left operand should be A");
        }
        public void BRA_A_And_B_BRA()
        {
            string           expr       = "(A and B)";
            List <ExprToken> listTokens = TestCommon.AddTokens("(", "A", "and", "B", ")");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            var dictOperators = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(dictOperators);

            // decode the list of tokens
            ParseResult result = parser.Parse(expr, listTokens);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The expr should be decoded with success");

            // check the root node, its a binary expression
            ExprLogical rootBinExpr = result.RootExpr as ExprLogical;

            Assert.IsNotNull(rootBinExpr, "The root node type should be ExprLogical");

            // check the left part of the root node
            ExprFinalOperand operandLeft = rootBinExpr.ExprLeft as ExprFinalOperand;

            Assert.IsNotNull(operandLeft, "The left root node type should be BoolBinExprOperand");
            Assert.AreEqual(operandLeft.Operand, "A", "The left operand should be A");

            // check the right part of the root node
            ExprFinalOperand operandRight = rootBinExpr.ExprRight as ExprFinalOperand;

            Assert.IsNotNull(operandRight, "The left root node type should be BoolBinExprOperand");
            Assert.AreEqual(operandRight.Operand, "B", "The left operand should be B");

            // check the root node operator
            Assert.AreEqual(rootBinExpr.Operator, OperatorLogicalCode.And, "The root operator should be and");
        }