Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 public void UserRequestLastAnswer()
 {
     Stack.last = "2";
     Evaulate evaulate = new Evaulate();
     string result = evaulate.Calculuate("last");
     Assert.AreEqual("2", result);
 }
Ejemplo n.º 3
0
 public void UserFailedtoEnterInput()
 {
     Stack.lastQuestion = null;
     Evaulate evaulate = new Evaulate();
        // object obj = null;
     Assert.IsTrue (Stack.lastQuestion == null);
 }
Ejemplo n.º 4
0
 public void UserentersLastQuestion()
 {
     Stack.lastQuestion = "1+1";
     Evaulate evaulate = new Evaulate();
     string result = evaulate.Calculuate("lastq");
     Assert.AreEqual("1+1", result);
 }
Ejemplo n.º 5
0
 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!");
 }
Ejemplo n.º 6
0
 public void UserAskLastQAfterEnteringInvalidInput()
 {
     Stack.lastQuestion = "lastq";
     Evaulate evaulate = new Evaulate();
     string result = evaulate.Calculuate("lastq");
     Assert.AreEqual("lastq", result);
 }