/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { try { ParseTree myTree = new ParseTree("(- (/ 100 20) (* 5 3))"); Console.WriteLine(myTree.PrintTree()); Console.WriteLine(myTree.CountTree()); } catch(UnexpectedSymbolException e) { Console.WriteLine("Incorrect input"); Console.WriteLine("Exception: " + e.Message); } catch(DivideByZeroException e) { Console.WriteLine(e.Message); } }
public void ThreeCalculationsPrintTreeTest() { ParseTree myTree = new ParseTree("(/ (* 10 5) (+ 2 3))"); Assert.AreEqual("(/ (* 10 5) (+ 2 3) ) ", myTree.PrintTree()); }
public void UnexpectedSymbolExceptionTest() { ParseTree myTree = new ParseTree("(/ y10 5)"); myTree.CountTree(); }
public void SimplePrintTreeTest() { ParseTree myTree = new ParseTree("(* 10 5)"); Assert.AreEqual("(* 10 5) ", myTree.PrintTree()); }
public void SimpleCountTreeTest() { ParseTree myTree = new ParseTree("(* 10 5)"); Assert.AreEqual(50, myTree.CountTree()); }
public void SevenCalculationsPrintTreeTest() { ParseTree myTree = new ParseTree("(- (* (- 12 2) (* 5 2)) (/ (* 10 5) (+ 2 3)))"); Assert.AreEqual("(- (* (- 12 2) (* 5 2) ) (/ (* 10 5) (+ 2 3) ) ) ", myTree.PrintTree()); }
public void DivideByZeroExceptionTest() { ParseTree myTree = new ParseTree("(/ 1 0)"); myTree.CountTree(); }
public void AnotherUnexpectedSymbolExceptionTest() { ParseTree myTree = new ParseTree("(- 10 5) ("); myTree.CountTree(); }