コード例 #1
0
ファイル: ParserTests.cs プロジェクト: nike4613/MathExpr
 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");
     }
 }
コード例 #2
0
 public void Parse(string expr, string result) =>
 Assert.Equal(result, MathExpression.Parse(expr));
コード例 #3
0
        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)));
        }
コード例 #4
0
        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));
        }