Ejemplo n.º 1
0
 public void ExpressionAdvancedTests()
 {
     var tests = new Tuple<string, double>[]
     {
         new Tuple<string, double>("2+-2", 0),
         new Tuple<string, double>("-1*2", -2),
         new Tuple<string, double>("-1*-2", 2),
         new Tuple<string, double>("-3*(2+2)", -12),
         new Tuple<string, double>("-(1-2)", 1)
     };
     foreach (var test in tests)
     {
         var exp = new Algex(test.Item1, null, true);
         Assert.AreEqual(test.Item2, exp.Value);
     }
 }
Ejemplo n.º 2
0
 public void ExpressionBasicTests()
 {
     var tests = new Tuple<string, double>[]
     {
         new Tuple<string, double>("3", 3),
         new Tuple<string, double>("2+2", 4),
         new Tuple<string, double>("2/2", 1),
         new Tuple<string, double>("(2+2)", 4),
         new Tuple<string, double>("2*2", 4),
         new Tuple<string, double>("2+2*2", 6),
         new Tuple<string, double>("(2+2)*2", 8),
         new Tuple<string, double>("(2+2)*(2+2)", 16),
         new Tuple<string, double>("(20+2)/11", 2)
     };
     foreach (var test in tests)
     {
         var exp = new Algex(test.Item1, null, true);
         Assert.AreEqual(test.Item2, exp.Value);
     }
 }
Ejemplo n.º 3
0
 public void ExpressionVariableContextTests()
 {
     var var = new Dictionary<string, double>();
     var.Add("a1", 2);
     var.Add("b", -1);
     var.Add("cd", 2);
     var.Add("zero", 0);
     var tests = new Tuple<string, double>[]
     {
         new Tuple<string, double>("{a1}+-2", 0),
         new Tuple<string, double>("{b}*2", -2),
         new Tuple<string, double>("-1*-2", 2),
         new Tuple<string, double>("-3*({cd}+2)", -12),
         new Tuple<string, double>("-(1-2)+{zero}", 1)
     };
     foreach (var test in tests)
     {
         var exp = new Algex(test.Item1, var, true);
         Assert.AreEqual(test.Item2, exp.Value);
     }
 }
Ejemplo n.º 4
0
 public void ExpressionVariableContextNestedTests()
 {
     var var = new Dictionary<string, double>();
     var.Add("a", 2);
     var.Add("b", -1);
     var.Add("cd", 5);
     var.Add("zero", 0);
     var tests = new Tuple<string, double>[]
     {
         new Tuple<string, double>("(2+3*(5-(7+12))*{zero})", 2),
         new Tuple<string, double>("(3-3)/(((3+3)*5)*{b})*(-1*{b})", 0),
         new Tuple<string, double>("0*(3-(10*(2+2)/({a}*10)))+10", 10)
     };
     foreach (var test in tests)
     {
         var exp = new Algex(test.Item1, var, true);
         Assert.AreEqual(test.Item2, exp.Value);
     }
 }