Пример #1
0
        public void ParseAddSpacesToUserInputIfEnteredWithoutThemTest2()
        {
            Parse test = new Parse();
            string input = "100 /-4";

            string actual = test.formatInput(input);
            string expected = "100 / -4";

            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        static void Main(string[] args)
        {
            Parse userInput = new Parse();
            Evaluate expression = new Evaluate();
            Stack stack = new Stack();

            bool runProgram = true;
            int counter = 0;

            while (runProgram)
            {
                Console.Write("[" + counter + "]> ");

                string response = Console.ReadLine();

                if (response == "exit" || response == "quit")
                {
                    Console.WriteLine("Bye!! \nPress any key to close program...");
                    runProgram = false;
                    Console.ReadKey();
                }
                else if(response == "lastq")
                {
                    Console.WriteLine("     " + stack.LastExpression);
                }
                else if (response == "last")
                {
                    Console.WriteLine("     " + stack.LastAnswer);

                }
                else
                {
                    string splitResponse = userInput.formatInput(response);
                    if (splitResponse == "Invalid Expression. Please try again!")
                    {
                        Console.WriteLine(splitResponse);
                    }
                    else
                    {
                        userInput.splitString(splitResponse);
                        decimal user_answer =
                            expression.calculate(userInput.FirstNumber, userInput.Operator, userInput.SecondNumber);
                        counter += 1;
                        Console.WriteLine("   " + "=" + " " + user_answer);
                        stack.LastExpression = response;
                        stack.LastAnswer = user_answer;
                    }
                }
            }
        }
Пример #3
0
 public void ParseGetFormatStringUsingRegexTest2()
 {
     Parse test = new Parse();
     string str = "-9876 / - 45";
     string actual = test.formatInput(str);
     string expected = "Invalid Expression. Please try again!";
     Assert.AreEqual(expected, actual);
 }