Exemple #1
0
 public void ParseString(string input, bool valid, bool throwsMulti = false)
 {
     try
     {
         _ = MathExpression.Parse(input);
         Assert.True(valid, "Parser did not throw when it was supposed to");
     }
     catch (SyntaxException e)
     {
         _ = e.ToString();
         Assert.False(valid, "Parser threw when it was not supposed to");
         Assert.False(throwsMulti, "Parser threw one error when it should have thrown multiple");
     }
     catch (AggregateException e)
     {
         _ = e.ToString();
         Assert.True(throwsMulti, "Parser threw multiple errors when it should not have");
     }
 }
Exemple #2
0
 public void Parse(string expr, string result) =>
 Assert.Equal(result, MathExpression.Parse(expr));
        public void CompileCustomType(string expression, int ctorArg, int expect)
        {
            var del = ExpressionCompiler.Default.Compile <Func <CustomType, int> >(MathExpression.Parse(expression), "obj");

            Assert.Equal(expect, del(new CustomType(ctorArg)));
        }
        public void CompileXY(string expression, double arg1, double arg2, double expect)
        {
            var del = ExpressionCompiler.Default.Compile <Func <double, double, double> >(MathExpression.Parse(expression), optimize: false, "x", "y");

            Assert.Equal(expect, del(arg1, arg2));
        }