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); } }
public void GettingConstantValueWorks() { Constants.AddKey2Dictionary("y", 6); RegexUtil TestingRegex = new RegexUtil(); string input = "y + 6"; ArrayList actual = TestingRegex.ExtractNums(input); ArrayList expected = new ArrayList(); expected.Add(6); expected.Add(6); CollectionAssert.AreEqual(expected, actual); }
public void extractsNumsTest() { string input = "3 + 4"; RegexUtil processor = new RegexUtil(); ArrayList answer = processor.ExtractNums(input); ArrayList expected = new ArrayList(); expected.Add(3); expected.Add(4); CollectionAssert.AreEqual(expected, answer); }
public void DoesNotTakeNoOpPresent() { string input = "24"; RegexUtil process = new RegexUtil(); ArrayList answer = process.ExtractNums(input); }
public void doesNotTakeBadInputWithTwoOps() { string input = "3 + %"; RegexUtil processor = new RegexUtil(); ArrayList answer = processor.ExtractNums(input); }
public void DoesNotTakeBadInput2() { string input = "+ 24 5"; RegexUtil processor = new RegexUtil(); ArrayList answer = processor.ExtractNums(input); }
public void DoesNotTakeAlphabet() { string input = "abc + def"; RegexUtil process = new RegexUtil(); ArrayList answer = process.ExtractNums(input); }