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();
 }
Пример #2
0
 public int EvaluateInput(string input)
 {
     Parser parse = new Parser();
     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.GetOperator(input) == '+')
     {
        return add_input.AddItems(input);
     }
     if (parse.GetOperator(input) == '-')
     {
         return subtract_input.SubtractItems(input);
     }
     if (parse.GetOperator(input) == '*')
     {
         return multiply_input.MultiplyItems(input);
     }
     if (parse.GetOperator(input) == '/')
     {
         return divide_input.DivideItems(input);
     }
     if (parse.GetOperator(input) == '%')
     {
         return modulo_input.ModuloItems(input);
     }
     throw new FormatException();
 }
Пример #3
0
 public void DivideWorksWithConstants()
 {
     string mock_input = "a / 2";
     Parser parse = new Parser();
     char toBeKey = char.Parse(parse.GetFirst(mock_input));
     int toBeKeyValue = int.Parse(parse.GetSecond(mock_input));
     Constant constant = new Constant();
     constant.AddConstant(toBeKey, 2);
     Divide items = new Divide();
     Assert.AreEqual(1, items.DivideConstants(mock_input, constant));
 }
Пример #4
0
 public void DivideWorks()
 {
     string mock_input = "2 / 2";
     Divide addItems = new Divide();
     Assert.AreEqual(1, addItems.DivideItems(mock_input));
 }