Пример #1
0
 public void TestEnteredKeywordLastQ()
 {
     Stack myKeyword = StackSingleton.Instance;
     Evaluate myExpression = new Evaluate();
     myExpression.RunOperation(2, 2, '+');
     Assert.AreEqual("2+2", myKeyword.RunKeywordEvaluation("lastq"));
 }
Пример #2
0
 public void TestValidateInputMultiply()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(7, 3, '*');
     Assert.AreEqual(21, myCalc.Resultado);
 }
Пример #3
0
 public void TestValidateInputSubtract()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(7, 3, '-');
     Assert.AreEqual(4, myCalc.Resultado);
 }
Пример #4
0
 public void TestValidateInputModulus()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(8, 4, '%');
     Assert.AreEqual(0, myCalc.Resultado);
 }
Пример #5
0
 public void TestValidateInputDivide()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(9, 3, '/');
     Assert.AreEqual(3, myCalc.Resultado);
 }
Пример #6
0
 public void TestValidateInputAdd()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(7, 3, '+');
     Assert.AreEqual(10, myCalc.Resultado);
 }
Пример #7
0
 public void TestInvalidExpression()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(9, 3, '&');
 }
Пример #8
0
        public void ReadInput(string input)
        {
            // Split produces an array of string based on the separator symbols.
            // The separator symbols will not be included in the array.
            var currentInput = input.Split(new char[] { '+', '-', '*', '/', '%' });
            // I must parse to the data type I want.
            try
            {
                Value1 = int.Parse(currentInput[0]);
            }
            catch (Exception) {
                Console.WriteLine("Please enter a valid number.");
            }
            // same here. I must parse the data type I want.
            try
            {
                Value2 = int.Parse(currentInput[1]);
            }

            catch (Exception)
            {
                Console.WriteLine("Please enter a valid number.");
            }

            char operation;

            // contains looks for the existence of the item.
            if (input.Contains("+"))
                operation = '+';
            else if (input.Contains("-"))
                operation = '-';
            else if (input.Contains("*"))
                operation = '*';
            else if (input.Contains("/"))
                operation = '/';
            else if (input.Contains("%"))
                operation = '%';
            else {
                Console.WriteLine("Please enter a valid operator.");
                throw new InvalidOperationException();

            }

            Operador = operation;
            Evaluate evaluator = new Evaluate();
            evaluator.RunOperation(value1, value2, operation);
        }