Exemple #1
0
 public void TestMethod1()
 {
     Minus testMinus = new Minus();
     testMinus.Right = new Operand(3);
     testMinus.Left = new Operand(5);
     Assert.IsTrue(testMinus.Calculate() == 2);
 }
Exemple #2
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;
 }