Beispiel #1
0
 public TreeNode BuildTree(string s, ref int i)
 {
     i++;
     if (s[i] == ')')
         i++;
     if (s[i] == '(')
     {
         i++;
         AbstractOperation newTree = null;
         if (s[i] == '+')
             newTree = new Plus();
         if (s[i] == '-')
             newTree = new Minus();
         if (s[i] == '*')
             newTree = new Multiplication();
         if (s[i] == '/')
             newTree = new Division();
         newTree.Left = this.BuildTree(s, ref i);
         newTree.Right = this.BuildTree(s, ref i);
         return newTree;
     }
     else if (Char.IsDigit(s[i]))
     {
         Operand newTree = new Operand(Convert.ToInt32(s[i]) - '0');
         return newTree;
     }
     return null;
 }
Beispiel #2
0
 public void TestMethod1()
 {
     Plus testPlus = new Plus();
     testPlus.Right = new Operand(1);
     testPlus.Left = new Operand(2);
     Assert.IsTrue(testPlus.Calculate() == 3);
 }