Exemplo n.º 1
0
 public static bool IsMatch(string expression)
 {
     try
     {
         _compiler.SetFunction(expression);
         _compiler.Compile();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        public void Sign()
        {
            var compiler = new EquationCompiler("4 + -3");

            Assert.AreEqual(4 + -3, compiler.Calculate());

            compiler.SetFunction("4+-3");
            Assert.AreEqual(4 + -3, compiler.Calculate());

            compiler.SetFunction("4 - -3");
            Assert.AreEqual(4 - -3, compiler.Calculate());

            compiler.SetFunction("4--3");
            Assert.AreEqual(4 - -3, compiler.Calculate());
        }
Exemplo n.º 3
0
        public void MultipleFunctionsPerObject()
        {
            var compiler = new EquationCompiler("abs(-4)");

            Assert.AreEqual(Math.Abs(-4), compiler.Calculate());

            compiler.SetFunction("acos(10)");
            Assert.AreEqual(Math.Acos(10), compiler.Calculate());
        }
Exemplo n.º 4
0
        public void NotEqual(double a, double b)
        {
            var compiler = new EquationCompiler("a!=b");

            compiler.SetVariable("a", a);
            compiler.SetVariable("b", b);
            Assert.AreEqual(a != b, Convert.ToBoolean(compiler.Calculate()));

            compiler.SetFunction("a<>b");
            Assert.AreEqual(a != b, Convert.ToBoolean(compiler.Calculate()));
        }
Exemplo n.º 5
0
        public void IfWithEquation(string condition, bool result, double a, double b, double c)
        {
            var compiler = new EquationCompiler(string.Format("if({0},(a+b),c)", condition));

            compiler.SetVariable("a", a);
            compiler.SetVariable("b", b);
            compiler.SetVariable("c", c);
            Assert.AreEqual((result ? a + b : c), compiler.Calculate());

            compiler.SetFunction(string.Format("if({0},a,(b+c))", condition));
            Assert.AreEqual((result ? a : b + c), compiler.Calculate());
        }