public void TestEnteredKeywordLastQ()
 {
     Stack myKeyword = StackSingleton.Instance;
     Evaluate myExpression = new Evaluate();
     myExpression.RunOperation(2, 2, '+');
     Assert.AreEqual("2+2", myKeyword.RunKeywordEvaluation("lastq"));
 }
 public void TestValidateInputMultiply()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(7, 3, '*');
     Assert.AreEqual(21, myCalc.Resultado);
 }
 public void TestValidateInputSubtract()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(7, 3, '-');
     Assert.AreEqual(4, myCalc.Resultado);
 }
 public void TestValidateInputModulus()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(8, 4, '%');
     Assert.AreEqual(0, myCalc.Resultado);
 }
 public void TestValidateInputDivide()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(9, 3, '/');
     Assert.AreEqual(3, myCalc.Resultado);
 }
 public void TestValidateInputAdd()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(7, 3, '+');
     Assert.AreEqual(10, myCalc.Resultado);
 }
 public void TestInvalidExpression()
 {
     Evaluate myCalc = new Evaluate();
     myCalc.RunOperation(9, 3, '&');
 }
Exemple #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);
        }