public int EvaluateInput(string input, Constant constant)
 {
     Parse parse = new Parse();
     Add add_input = new Add();
     Subtract subtract_input = new Subtract();
     Multiply multiply_input = new Multiply();
     Divide divide_input = new Divide();
     Modulo modulo_input = new Modulo();
     if (parse.OperatorInput(input) == '+')
     {
         return add_input.AddConstants(input, constant);
     }
     if (parse.OperatorInput(input) == '-')
     {
         return subtract_input.SubtractConstants(input, constant);
     }
     if (parse.OperatorInput(input) == '*')
     {
         return multiply_input.MultiplyConstants(input, constant);
     }
     if (parse.OperatorInput(input) == '/')
     {
         return divide_input.DivideConstants(input, constant);
     }
     if (parse.OperatorInput(input) == '%')
     {
         return modulo_input.ModuloConstants(input, constant);
     }
     throw new FormatException();
 }
Exemplo n.º 2
0
 public void AddWorksWithConstantsBackwards()
 {
     string mock_input = "22 + a";
     Parser parse = new Parser();
     int toBeKey = int.Parse(parse.GetFirst(mock_input));
     char toBeKeyValue = char.Parse(parse.GetSecond(mock_input));
     Constant constant = new Constant();
     constant.AddConstant(toBeKeyValue, 1);
     Add items = new Add();
     Assert.AreEqual(23, items.AddConstants(mock_input, constant));
 }