Ejemplo n.º 1
0
 /// <summary>
 /// method, that builds tree based on list with operands and operators
 /// </summary>
 /// <param name="list"></param>
 /// <returns></returns>
 public static Tree TreeBuilder(string expression)
 {
     Tree tree = new Tree();
     List<object> list = StringParser(expression);
     foreach (var value in list)
     {
         if (value is int)
         {
             tree.Add(Convert.ToInt32(value));
         }
         if (value is char)
         {
             tree.Add(Convert.ToChar(value));
         }
     }
     return tree;
 }
 public void CalculateTreeTest3()
 {
     string expr = "(/ (+ 1 1) 0)";
     tree = CreateTree.TreeBuilder(expr);
     tree.CalculateTree();
 }
 public void CalculateTreeTest2()
 {
     string expr = "(* (+ 1 1) 2)";
     tree = CreateTree.TreeBuilder(expr);
     Assert.AreEqual(4, tree.CalculateTree());
 }