static void Main(string[] args) { int x = 0; while (true) { Console.WriteLine("[" + x + "]>"); string input = Console.ReadLine(); Evaulate eval = new Evaulate(); Parse parse = new Parse(); Stack stack = new Stack(); if (input.ToLower() == "exit" || input.ToLower() == "quit") break; try { var result = eval.Calculuate(input); Console.WriteLine(" = " + result); } catch (Exception e) { Console.WriteLine(e.Message); } try { if (input.Contains("=")) { parse.ExtractConstant(input); stack.SaveConstant(parse.ConstantKey, parse.ConstantValue); } else { parse.ExtractValue(input); eval.Calculuate(Convert.ToInt32(input[0]), Convert.ToInt32(input[1])); } } catch (System.ArgumentException) { Console.WriteLine("You made a syntax error"); } x++; } Console.WriteLine("Goodbye, Mr Bond!"); Task.Delay(TimeSpan.FromSeconds(2)).Wait(); }
public void UserRequestLastAnswer() { Stack.last = "2"; Evaulate evaulate = new Evaulate(); string result = evaulate.Calculuate("last"); Assert.AreEqual("2", result); }
public void UserentersLastQuestion() { Stack.lastQuestion = "1+1"; Evaulate evaulate = new Evaulate(); string result = evaulate.Calculuate("lastq"); Assert.AreEqual("1+1", result); }
public void UserCanExitCalculator() { Evaulate evaulate = new Evaulate(); string result = evaulate.Calculuate("exit"); //exit method removed from stack now exits via bool on program // Assert.AreEqual(Stack.Exit(), "Bye Felica!"); }
public void UserAskLastQAfterEnteringInvalidInput() { Stack.lastQuestion = "lastq"; Evaulate evaulate = new Evaulate(); string result = evaulate.Calculuate("lastq"); Assert.AreEqual("lastq", result); }