Exemplo n.º 1
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");
        }