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(); }
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)); }