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();
 }
Example #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();
 }
 public void MultiplyWorksWithConstants()
 {
     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, 1);
     Multiply items = new Multiply();
     Assert.AreEqual(2, items.MultiplyConstants(mock_input, constant));
 }
 public void MultiplicationTest()
 {
     Multiply MyProduct = new Multiply();
     int answer = MyProduct.MultiplyNum(5, 3);
     Assert.AreEqual(answer, 15);
 }
 public void MultiplyWorks()
 {
     string mock_input = "1 * 2";
     Multiply addItems = new Multiply();
     Assert.AreEqual(2, addItems.MultiplyItems(mock_input));
 }