Beispiel #1
0
        //Evaluate
        public string Calculuate(string input)
        {
            /*  if (input.Contains("="))
            {
                Parse.ExtractCharacter();
              //  string letter = "a";
                //return letter;
            }
            */
                if (input == "lastq")
            {
                if (Stack.lastQuestion == null)
                {
                    return "No Operation entered";
                }
                return Stack.lastQuestion;
            }
            else if (input == "last")
            {
                if (Stack.lastQuestion == null)
                {
                    return "No Operation entered";
                }
                return Stack.last;
            }

            else
            {
                Parse parse = new Parse();
                var operans = parse.GetNumbers(input);
                var op = parse.GetOperator(input);
                var result = 0;

                switch (op)
                {
                    case '+':
                        result = Addition.AddNum(operans);
                        break;
                    case '-':
                        result = Subtraction.SubNum(operans);
                        break;
                    case '*':
                        result = Multiplication.MultiplyNum(operans);
                        break;
                    case '/':
                        result = Division.DivideNum(operans);
                        break;
                    case '%':
                        result = Modulus.ModNum(operans);
                        break;
                    default:
                        throw new ArgumentException("incorrect format");
                }
                Stack.last = result.ToString();
                Stack.lastQuestion = input;
                return result.ToString();
            }
        }
 public void DoesEquationHaveNumbers()
 {
     var calc = new Parse();
     var numb = calc.GetNumbers("20+5");
     var expected = new string[] { "20", "5" };
     CollectionAssert.AreEqual(expected, numb);
 }
 public void IsNumberInIndexOne()
 {
     Parse parse = new Parse();
     string[] indexOne = parse.GetNumbers("5+8");
     Assert.AreEqual("8", indexOne[1]);
 }
        public void IsNumberInIndexZero()
        {
            Parse parse = new Parse();

            string[] indexZero = parse.GetNumbers("5+8");
            Assert.AreEqual("5", indexZero[0]);
        }
 public void GetNumbersShouldReturnTwoStrings()
 {
     var calc = new Parse();
     var stringArray = calc.GetNumbers("12+16");
     var expected = new string[] { "12", "16" };
     CollectionAssert.AreEqual(stringArray, expected);
 }