public void DivisionTest() { DivideIt testDiv = new DivideIt(); ArrayList myNums = new ArrayList(); myNums.Add(5); myNums.Add(5); int answer = testDiv.Division(myNums); Assert.AreEqual(answer, 1); }
public string Calculate(string input) { // creates a new RegexProcessor RegexUtil regexProcessing = new RegexUtil(); // creates a new setting ConstantParser ConstantParser constantSetting = new ConstantParser(); // extract integers ArrayList integers = regexProcessing.ExtractNums(input); // extracts operand string thisOp = regexProcessing.ExtractsOp(input); // holds answer value string answer; // make a new instance of the applicable class per the // operand extracted switch (thisOp) { case "+": AddIt thisAddExp = new AddIt(); answer = thisAddExp.Addition(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "-": SubtractIt thisSubExp = new SubtractIt(); answer = thisSubExp.Subtraction(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "*": MultiplyIt thisMultiExp = new MultiplyIt(); answer = thisMultiExp.Multiplication(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "/": DivideIt thisDivExp = new DivideIt(); answer = thisDivExp.Division(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "%": ModIt thisModExp = new ModIt(); answer = thisModExp.Modulation(integers).ToString(); LastQnA.LastAns = Convert.ToInt32(answer); LastQnA.LastQ = input; return answer; case "=": answer = "Your value has been set"; return answer; default: throw new ArgumentException("Input doesn't contain an operand understood {0}", thisOp); } }
// this is going to extract which type of expression it is public string ExtractsOp(string input) { Match AddMatch = add_regex.Match(input); Match DivideMatch = divide_regex.Match(input); Match MultiMatch = multiply_regex.Match(input); Match SubMatch = subt_regex.Match(input); Match ModMatch = mod_regex.Match(input); if (AddMatch.Success) { AddIt thisAdd = new AddIt(); return "+"; } else if (SubMatch.Success) { SubtractIt thisSub = new SubtractIt(); return "-"; } else if (MultiMatch.Success) { MultiplyIt thisMult = new MultiplyIt(); return "*"; } else if (DivideMatch.Success) { DivideIt thisDiv = new DivideIt(); return "/"; } else if (ModMatch.Success) { ModIt thisMod = new ModIt(); return "%"; } else { throw new ArgumentException("No operator provided"); } }