コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("What is your name?");
            string userName = Console.ReadLine();
            Parse p = new Parse();
            Evaluate e = new Evaluate();
            bool run = true;

            while (run)
            {
                Console.WriteLine(userName + " Define your mathematical operation");
                string input = Console.ReadLine();
                if (input.ToUpper() == "LASTQ")
                {
                    Console.WriteLine(e.lastExpression());
                    run = false;
                    break;
                }
                string oper = p.getOperator(input);
                int num1 = p.getNumberOne(input);
                int num2 = p.getNumberTwo(input);
                int answer = e.ExecuteMethod(num1, num2, oper);
                Console.WriteLine("The answer to your operation is: " + answer);
            }
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
コード例 #2
0
 public void EvaluateTestEnsureICanSubtract()
 {
     Evaluate e = new Evaluate();
     Parse p = new Parse();
     string input = "2 - 2";
     int num1 = p.getNumberOne(input);
     int num2 = p.getNumberTwo(input);
     string oper = p.getOperator(input);
     int expected = 0;
     Assert.AreEqual(expected, e.ExecuteMethod(num1, num2, oper));
 }
コード例 #3
0
 public void CommandEnsureICanGetReturnFromLastQCommand()
 {
     Parse p = new Parse();
     Evaluate e = new Evaluate();
     string input = "2 + 2";
     int num1 = p.getNumberOne(input);
     int num2 = p.getNumberTwo(input);
     string oper = p.getOperator(input);
     int answer = e.ExecuteMethod(num1, num2, oper);
     string expected = "2 + 2";
     string actual = e.lastExpression();
     Assert.AreEqual(expected, actual);
 }
コード例 #4
0
 public void ParseEnsureICanGetAdditionOperator()
 {
     Parse p = new Parse();
     string input = "2 + 2";
     Assert.AreEqual("+", p.getOperator(input));
 }
コード例 #5
0
 public void ParseEnsureICanCaptureBadInputNegativeSpaceNumber()
 {
     Parse p = new Parse();
     string input = "2+- 3";
     p.getOperator(input);
 }
コード例 #6
0
 public void ParseEnsureICanCaptureBadInputDoubleOperator()
 {
     Parse p = new Parse();
     string input = "2 ++ 2";
     p.getOperator(input);
 }