/// <summary>
        /// Expression: (A=B)
        /// A boolean expression using two variables.
        /// returns always a boolean value result.
        ///
        /// Particularity:
        /// Execute the same expression 2 times.
        /// The first time, both variables A and B are defined as integer.
        /// The second time, A and B are then defined as boolean.
        ///
        /// The execution finish successfully.
        /// </summary>
        public static void A_Eq_B_Exec2Times()
        {
            string expr = "(A = B)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            Console.WriteLine("Define variables: A=15; B=15 ");
            evaluator.DefineVarInt("a", 15);
            evaluator.DefineVarInt("b", 15);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result: " + execResult.ResultBool);

            //======================================================
            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            Console.WriteLine("\nExecute again the same provided expression but changes variables types and values:");
            Console.WriteLine("Define variables: A=false; B=false");
            evaluator.DefineVarBool("a", false);
            evaluator.DefineVarBool("b", false);

            //====3/execute l'expression booléenne
            execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result: " + execResult.ResultBool);
        }
        /// <summary>
        /// Execute a function call two times with different values.
        ///
        /// fct(a)  a:=8  ->return false
        /// fct(a)  a:=12  ->return true
        ///
        /// </summary>
        public static void CallFunctionWithIntParam_TwoTimes()
        {
            string expr = "fct(a)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            evaluator.Parse(expr);

            //====2/prepare the execution, attach function
            Console.WriteLine("Attach function code to Fct() and set value to param: a=8");
            evaluator.DefineVarInt("a", 8);
            evaluator.AttachFunction("fct", FctRetBool_Int);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result (should return false): " + execResult.ResultBool);

            //============================================================
            //====2/prepare the execution, attach function
            Console.WriteLine("Set value to param: a=12");
            evaluator.DefineVarInt("a", 12);
            evaluator.AttachFunction("fct", FctRetBool_Int);

            //====3/Execute the expression
            execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result (should return true): " + execResult.ResultBool);
        }
예제 #3
0
        public static void a_plus_b_mul_c_ret_14()
        {
            string expr = "a+b*c";

            Console.WriteLine("\n====The expression is: " + expr);
            Console.WriteLine("The component Apply operator priority: a+(b*c)");

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            Console.WriteLine("Define variables: a:=2, b:=3, c:= 4");
            evaluator.DefineVarInt("a", 2);
            evaluator.DefineVarInt("b", 3);
            evaluator.DefineVarInt("c", 4);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result is an int (true)?: " + execResult.IsResultInt);
            Console.WriteLine("Execution Result (should be 14): " + execResult.ResultInt);
        }
        /// <summary>
        /// Execute a function having 2 int parameters.
        /// </summary>
        public static void CallFunctionWith3IntParams_ret_10()
        {
            string expr = "fct(a,b,c)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            evaluator.Parse(expr);

            //====2/prepare the execution, attach function
            Console.WriteLine("Attach function code to Fct() and set value to param: a=2, b=3; c=5");
            evaluator.DefineVarInt("a", 2);
            evaluator.DefineVarInt("b", 3);
            evaluator.DefineVarInt("c", 5);

            // attach the 3 params function to the function call
            Func3ParamsRetIntMapper <int, int, int> func3ParamsRetIntMapper = new Func3ParamsRetIntMapper <int, int, int>();

            func3ParamsRetIntMapper.SetFunction(FctRetInt_Int_Int_Int);
            evaluator.AttachFunction("fct", func3ParamsRetIntMapper);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution has error? (should be false): " + execResult.HasError);
            Console.WriteLine("Execution Result is an int type?: " + execResult.IsResultInt);
            Console.WriteLine("Execution Result is (should be 10): " + execResult.ResultInt);
        }
예제 #5
0
        public void fct_OP_not_OP_a_CP_CP_retBool_true_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string      expr        = "fct(not (a))";
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables and functions
            evaluator.DefineVarBool("a", true);

            // link function body to function call
            evaluator.AttachFunction("Fct", Fct_RetNot);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value (is ExprExecFunctionCallBool override ExprExecValueBool)
            ExprExecValueBool valueBool = execResult.ExprExec as ExprExecValueBool;

            Assert.IsNotNull(execResult, "The result value should be a bool");
            Assert.AreEqual(true, valueBool.Value, "The result value should be: true");
        }
        /// <summary>
        /// Define a variable but the syntax name is wrong: has space.
        /// </summary>
        public static void DefineVarSyntaxName()
        {
            string expr = "Not(A)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            Console.WriteLine("Define variables: A=12");
            evaluator.DefineVarBool("a", false);
            Console.WriteLine("Define wrong variable name: 'a b c'  -> don't stop the execution of the evaluation of the expression!");
            evaluator.DefineVarInt("a b c", 12);

            List <ExprError> listConfigError = evaluator.GetListErrorExprConfig();

            Console.WriteLine("DefineVar failed, err (VarNameSyntaxWrong): " + listConfigError[0].Code);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result (true): " + execResult.ResultBool);
        }
        public static void Not_OP_A_CP_A_Int_Err()
        {
            string expr = "Not(A)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            Console.WriteLine("Define variables: A=12");
            evaluator.DefineVarInt("a", 12);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            if (execResult.HasError)
            {
                // error: VariableNotCreated
                Console.WriteLine("Execution Result failed, err: " + execResult.ListError[0].Code);

                // Key: VarName, Value: a
                Console.WriteLine("Execution Result failed, ParamKey: " + execResult.ListError[0].ListErrorParam[0].Key + ", ParamValue: " + execResult.ListError[0].ListErrorParam[0].Value);
                return;
            }

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result: " + execResult.ResultBool);
        }
        public void Double_Exposant_SepIsDot_false()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            //evaluator.SetDoubleDecimalSeparator(ExpressionEvalDef.DoubleDecimalSeparator.Dot);

            string      expr        = "(a = 12.45E3)";
            ParseResult parseResult = evaluator.Parse(expr);

            Assert.IsFalse(parseResult.HasError, "the parse should finish successfully");

            //====2/prepare the execution, provide all used variables: type and value
            //ExprExecResult execResult = evaluator.InitExec();

            evaluator.DefineVarDouble("a", 1345);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value
            Assert.IsFalse(execResult.ResultBool, "The result value should be false");
        }
        /// <summary>
        /// error, the variables types mismatch.
        /// Can't compare an integer and a boolean.
        ///
        /// ====The expression is: (a=b)
        /// The expr '(a=b)' has errors, nb = 1
        /// Error code: ExprComparisonOperandsTypeMismatchIntExpected
        /// Error param: Position= 3
        ///
        /// </summary>
        public static void A_Eq_B_TypeMismatch()
        {
            string expr = "(a=b)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            // 1-decode the expression
            evaluator.Parse(expr);

            // 2-set variables
            evaluator.DefineVarInt("a", 12);
            evaluator.DefineVarBool("b", true);

            // 3-execute the expression
            ExecResult execResult = evaluator.Exec();

            // 4-check error
            if (execResult.HasError)
            {
                // display the error code
                Console.WriteLine("The expr '" + expr + "' has errors, nb=" + execResult.ListError.Count);
                ExprError error = execResult.ListError[0];
                Console.WriteLine("Error code: " + error.Code);

                // display the error parameter (the position of the wrong token)
                Console.WriteLine("Error param: " + error.ListErrorParam[0].Key + "= " + error.ListErrorParam[0].Value);

                return;
            }

            Console.WriteLine("The expr " + expr + " parse finished sucessfully!");
        }
        public void fct_OP_false_Sep_false_CP_retBool_true_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string expr = "fct(true, true, true)";

            evaluator.Parse(expr);

            // link function body to function call
            var funcMapper = new Func3ParamsRetBoolMapper <bool, bool, bool>();

            funcMapper.SetFunction(Fct3ParamsBool);
            evaluator.AttachFunction("Fct", funcMapper);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value (is ExprExecFunctionCallBool override ExprExecValueBool)
            ExprExecValueBool valueBool = execResult.ExprExec as ExprExecValueBool;

            Assert.IsNotNull(execResult, "The result value should be a bool");
            Assert.AreEqual(true, valueBool.Value, "The result value should be: true");
        }
예제 #11
0
        public void fct_OP_CP_retBool_false_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string      expr        = "fct()";
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value
            //ExprExecResult execResult = evaluator.InitExec();

            // attach the function code FctFalse() to the function call: Fct()
            evaluator.AttachFunction("Fct", FctFalse);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value (is ExprExecFunctionCallBool override ExprExecValueBool)
            ExprExecValueBool valueBool = execResult.ExprExec as ExprExecValueBool;

            Assert.IsNotNull(execResult, "The result value should be a bool");
            Assert.AreEqual(false, valueBool.Value, "The result value should be: false");
        }
        public void fct_OP_12_Sep_bonjour_8dot5_CP_retInt_21_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string expr = "fct(4, \"bonjour\", 8.5)";

            evaluator.Parse(expr);

            // link function body to function call
            var funcMapper = new Func3ParamsRetIntMapper <int, string, double>();

            funcMapper.SetFunction(FctP1Int_P2String_P3Double);
            evaluator.AttachFunction("Fct", funcMapper);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value (is ExprExecFunctionCallBool override ExprExecValueBool)
            ExprExecValueInt valueInt = execResult.ExprExec as ExprExecValueInt;

            Assert.IsNotNull(execResult, "The result value should be a bool");
            Assert.AreEqual(21, valueInt.Value, "The result value should be: 18");
        }
예제 #13
0
        public void fct_OP_a_CP_retDouble_P1String_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string      expr        = "fct(a)";
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value
            //ExprExecResult execResult = evaluator.InitExec();

            // 3 letters -> return 3x1.5=4.5
            evaluator.DefineVarString("a", "abc");

            // link function body to function call
            evaluator.AttachFunction("Fct", FctDouble_String);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value (is ExprExecFunctionCallBool override ExprExecValueBool)
            ExprExecValueDouble valueDouble = execResult.ExprExec as ExprExecValueDouble;

            Assert.IsNotNull(valueDouble, "The result value should be a double");
            Assert.AreEqual(4.5, valueDouble.Value, "The result value should be: true");
        }
예제 #14
0
        public static void OP_A_Ou_b_CP_true()
        {
            string expr = "(a Ou b)";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            // set the tool in french
            evaluator.SetLang(Language.Fr);

            //====1/decode the expression
            evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            Console.WriteLine("Define variables: a:=false, b=true");
            evaluator.DefineVarBool("a", false);
            evaluator.DefineVarBool("b", true);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result: " + execResult.ResultBool);
        }
예제 #15
0
        public void fct_3Params_FunctionCall_OneMissing_err()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string expr = "fct(true, true)";

            evaluator.Parse(expr);

            // link function body to function call
            Func3ParamsRetBoolMapper <bool, bool, bool> func3ParamsRetBoolMapper = new Pierlam.ExpressionEval.Func3ParamsRetBoolMapper <bool, bool, bool>();

            func3ParamsRetBoolMapper.SetFunction(Fct3ParamsBool);
            evaluator.AttachFunction("fct", func3ParamsRetBoolMapper);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.IsTrue(execResult.HasError, "The exec of the expression should finish with error");

            Assert.AreEqual(ErrorCode.FunctionCallParamCountWrong, execResult.ListError[0].Code, "The exec of the expression should finish with success");
            Assert.AreEqual("FunctionCallName", execResult.ListError[0].ListErrorParam[0].Key, "The exec of the expression should finish with success");
            Assert.AreEqual("fct", execResult.ListError[0].ListErrorParam[0].Value, "The exec of the expression should finish with success");
        }
        public void fct_OP_10_Sep_bonjour_CP_retBool_true_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);
            evaluator.SetStringTagCode(StringTagCode.Quote);

            string expr = "fct(10, 'bonjour')";

            evaluator.Parse(expr);

            // link function body to function call
            evaluator.AttachFunction("Fct", FctP1Int_P2String);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value (is ExprExecFunctionCallBool override ExprExecValueBool)
            ExprExecValueBool valueBool = execResult.ExprExec as ExprExecValueBool;

            Assert.IsNotNull(execResult, "The result value should be a bool");
            Assert.AreEqual(true, valueBool.Value, "The result value should be: true");
        }
예제 #17
0
        public void fct_OP_CP_retBool_paramMissing_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string      expr        = "fct()";
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value
            //ExprExecResult execResult = evaluator.InitExec();

            // link function body to function call
            evaluator.AttachFunction("fct", FctRetBool_P1Bool);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.IsTrue(execResult.HasError, "The exec of the expression should finish with error");

            Assert.AreEqual(ErrorCode.FunctionCallParamCountWrong, execResult.ListError[0].Code, "The exec of the expression should finish with success");
            Assert.AreEqual("FunctionCallName", execResult.ListError[0].ListErrorParam[0].Key, "The exec of the expression should finish with success");
            Assert.AreEqual("fct", execResult.ListError[0].ListErrorParam[0].Value, "The exec of the expression should finish with success");
        }
        public void Exec_Not_OP_a_CP_VarTypeWrong()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string      expr        = "Not(A)";
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value
            //ExprExecResult execResult = evaluator.InitExec();

            // define the var a as an int in place of a bool!!!
            evaluator.DefineVarInt("a", 12);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(true, execResult.HasError, "The exec of the expression should finish with success");

            // get the error
            ExprError error = execResult.ListError[0];

            Assert.AreEqual(ErrorType.Exec, error.ErrorType, "The errorType should be: Exec");
            Assert.AreEqual(ErrorCode.ExprLogicalNotOperator_InnerOperandBoolTypeExpected, error.Code, "The errCode should be: VariableNotCreated");
            ErrorParam errParam = error.ListErrorParam[0];

            Assert.AreEqual("Token", errParam.Key, "The errParam key should be: VarName");
            Assert.AreEqual("A", errParam.Value, "The errParam value should be: a");
            ErrorParam errParam2 = error.ListErrorParam[1];

            Assert.AreEqual("Position", errParam2.Key, "The errParam key should be: VarName");
            Assert.AreEqual("4", errParam2.Value, "The errParam value should be: a");
        }
예제 #19
0
        public void Double_and_OneVarTypeWrong_err()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            //evaluator.SetDoubleDecimalSeparator(ExpressionEvalDef.DoubleDecimalSeparator.Dot);

            string      expr        = "a and b";
            ParseResult parseResult = evaluator.Parse(expr);

            Assert.IsFalse(parseResult.HasError, "the parse should finish successfully");

            //====2/prepare the execution, provide all used variables: type and value
            evaluator.DefineVarInt("a", 12);
            evaluator.DefineVarBool("b", true);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.IsTrue(execResult.HasError, "The exec of the expression should finish with error");

            // todo: pas bon!! corriger
            Assert.AreEqual(ErrorCode.ExprLogicalOperandTypeNotAllowed, execResult.ListError[0].Code, "The exec of the expression should finish with success");
        }
예제 #20
0
        public void Exec_A_Diff_B_Bool_True_Ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string      expr        = "(A<>B)";
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value
            //ExprExecResult execResult = evaluator.InitExec();

            evaluator.DefineVarBool("a", false);
            evaluator.DefineVarBool("b", true);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value
            ExprExecValueBool valueBool = execResult.ExprExec as ExprExecValueBool;

            Assert.IsNotNull(valueBool, "The result value should be a bool");
            Assert.AreEqual(true, valueBool.Value, "The result value should be: true");
        }
예제 #21
0
        /// <summary>
        /// A dev!!
        /// </summary>
        static void TestExprLogicalSeveralOperands()
        {
            string expr = "(A and B or C)";

            ExpressionEval evaluator = new ExpressionEval();

            //====1/décode l'expression booléenne
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            //ExprExecResult execResult = evaluator.InitExec();

            evaluator.DefineVarBool("a", true);
            evaluator.DefineVarBool("b", true);
            evaluator.DefineVarBool("c", false);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            //====4/get the result
            if (execResult.HasError)
            {
                Console.WriteLine("Execution Result: error!");
            }

            if (execResult.IsResultBool)
            {
                Console.WriteLine("Execution Result: " + execResult.ResultBool);
            }
        }
        public void Double_a_xor_b_false_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            //evaluator.SetDoubleDecimalSeparator(ExpressionEvalDef.DoubleDecimalSeparator.Dot);

            string      expr        = "a xor b";
            ParseResult parseResult = evaluator.Parse(expr);

            Assert.IsFalse(parseResult.HasError, "the parse should finish successfully");

            //====2/prepare the execution, provide all used variables: type and value
            evaluator.DefineVarBool("a", false);
            evaluator.DefineVarBool("b", true);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.AreEqual(false, execResult.HasError, "The exec of the expression should finish with success");

            // check the final result value
            Assert.IsTrue(execResult.IsResultBool, "The result should be a bool");
            Assert.IsTrue(execResult.ResultBool, "The result value should be true");
        }
예제 #23
0
        /// <summary>
        /// Get variables used in the expression.
        ///
        /// The execution will displays:
        /// Var #1, Name=a
        /// Var #2, Name=b
        /// </summary>
        public static void GetVariableOfExpression()
        {
            string expr = "a=b";

            Console.WriteLine("\n====The expression is: " + expr);

            ExpressionEval evaluator = new ExpressionEval();

            //====1/decode the expression
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            // scan all variables found in the expression (found the variable named 'a')
            int i = 0;

            foreach (ExprVarUsed exprVar in parseResult.ListExprVarUsed)
            {
                i++;
                Console.WriteLine("Var #" + i + ", Name=" + exprVar.Name);
            }

            Console.WriteLine("Define variables: a:=12, b:=12");
            evaluator.DefineVarInt("a", 12);
            evaluator.DefineVarInt("b", 12);

            //====3/Execute the expression
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            Console.WriteLine("Execution Result (should be true): " + execResult.ResultBool);
        }
예제 #24
0
        public void ParseMissing_err()
        {
            ExpressionEval evaluator = new ExpressionEval();

            //====2/prepare the execution, provide all used variables: type and value

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.IsTrue(execResult.HasError, "The init exec of the expression should failed");
            Assert.AreEqual(ErrorCode.ParsedExpressionMissing, execResult.ListError[0].Code, "the error should be ParsedExpressionMissing");
        }
        public void ParseOk_InitExec_Exec_InitExec2_Exec2_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            string      expr        = "a";
            ParseResult parseResult = evaluator.Parse(expr);

            Assert.IsFalse(parseResult.HasError, "The parse of the expression should finish with success");

            //====2/prepare the execution, provide all used variables: type and value
            //ExprExecResult execResult = evaluator.InitExec();
            //Assert.IsFalse(execResult.HasError, "The parse of the expression should finish with success");

            //=====2.1/Init var
            evaluator.DefineVarBool("a", true);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.IsFalse(execResult.HasError, "The init exec of the expression should failed");
            Assert.IsTrue(execResult.IsResultBool, "The exec result be a bool");
            Assert.IsTrue(execResult.ResultBool, "The exec result be true");

            //====4/prepare the execution, provide all used variables: type and value
            //execResult = evaluator.InitExec();
            Assert.IsFalse(execResult.HasError, "The parse of the expression should finish with success");

            //=====2.1/Init var
            evaluator.DefineVarInt("a", 14);

            //====3/execute l'expression booléenne
            execResult = evaluator.Exec();
            Assert.IsFalse(execResult.HasError, "The init exec of the expression should failed");
            Assert.IsTrue(execResult.IsResultInt, "The exec result be an int");
            Assert.AreEqual(14, execResult.ResultInt, "The exec result be 14");

            //====5/execute l'expression booléenne
            execResult = evaluator.Exec();
            Assert.IsFalse(execResult.HasError, "The init exec of the expression should failed");
        }
예제 #26
0
        static void OP_A_Eq_B_CP_Exec2Times()
        {
            string expr = "(A = B)";

            ExpressionEval evaluator = new ExpressionEval();

            //====1/décode l'expression booléenne
            ParseResult parseResult = evaluator.Parse(expr);

            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            //ExprExecResult execResult = evaluator.InitExec();

            evaluator.DefineVarInt("a", 15);
            evaluator.DefineVarInt("b", 15);

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            ExprExecValueBool valueBool = execResult.ExprExec as ExprExecValueBool;

            Console.WriteLine("Execution Result: " + valueBool.Value.ToString());

            //======================================================
            //====2/prepare the execution, provide all used variables: type and value, remove the previous result
            //execResult = evaluator.InitExec();

            evaluator.DefineVarBool("a", false);
            evaluator.DefineVarBool("b", false);

            //====3/execute l'expression booléenne
            execResult = evaluator.Exec();

            //====4/get the result, its a bool value
            valueBool = execResult.ExprExec as ExprExecValueBool;

            Console.WriteLine("Execution Result: " + valueBool.Value.ToString());
        }
예제 #27
0
        public void ParseOk_InitExec_Exec_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            string      expr        = "12";
            ParseResult parseResult = evaluator.Parse(expr);

            Assert.IsFalse(parseResult.HasError, "The parse of the expression should finish with success");

            //====execute l'expression booléenne
            ExecResult execResult = execResult = evaluator.Exec();

            Assert.IsFalse(execResult.HasError, "The init exec of the expression should failed");
        }
        public void ParseOk__DefVarMissing_InitExec_Exec_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            string      expr        = "a";
            ParseResult parseResult = evaluator.Parse(expr);

            Assert.IsFalse(parseResult.HasError, "The parse of the expression should finish with success");

            //====execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.IsTrue(execResult.HasError, "The init exec of the expression should failed");
            Assert.AreEqual(ErrorCode.VariableNotDefined, execResult.ListError[0].Code, "the error should be VariableNotCreated");
        }
예제 #29
0
        public void Exec_aBool_plus_5_err()
        {
            ExpressionEval evaluator = new ExpressionEval();

            // definir langue: fr ou en, sert pour les opérateurs: ET/AND, OU/OR, NON/NOT.
            evaluator.SetLang(Language.En);

            string      expr        = "a + 5";
            ParseResult parseResult = evaluator.Parse(expr);

            evaluator.DefineVarBool("a", true);
            ExecResult execResult = evaluator.Exec();

            Assert.IsTrue(execResult.HasError, "The exec of the expression should failed");
            Assert.AreEqual(ErrorCode.ExprCalculationOperandTypeUnExcepted, execResult.ListError[0].Code, "the error should be ParsedExpressionMissing");
        }
예제 #30
0
        public void ParseOk_InitExec_Exec_InitExec2_Exec2_ok()
        {
            ExpressionEval evaluator = new ExpressionEval();

            string      expr        = "12";
            ParseResult parseResult = evaluator.Parse(expr);

            Assert.IsFalse(parseResult.HasError, "The parse of the expression should finish with success");

            //====2/prepare the execution, provide all used variables: type and value

            //====3/execute l'expression booléenne
            ExecResult execResult = evaluator.Exec();

            Assert.IsFalse(execResult.HasError, "The init exec of the expression should failed");
        }