コード例 #1
0
        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);
            }
        }
コード例 #2
0
 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);
 }
コード例 #3
0
 public void ExtractsSubOperand()
 {
     string input = "10 - 2";
     RegexUtil subtracting = new RegexUtil();
     string answer = subtracting.ExtractsOp(input);
     string expected = "-";
     Assert.AreEqual(expected, answer);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 public void ExtractsMultiOperand()
 {
     string input = "10 * 2";
     RegexUtil multiplying = new RegexUtil();
     string answer = multiplying.ExtractsOp(input);
     string expected = "*";
     Assert.AreEqual(expected, answer);
 }
コード例 #6
0
 public void ExtractsModOperand()
 {
     string input = "10 % 2";
     RegexUtil modulusing = new RegexUtil();
     string answer = modulusing.ExtractsOp(input);
     string expected = "%";
     Assert.AreEqual(expected, answer);
 }
コード例 #7
0
 public void ExtractsDivOperandTest()
 {
     string input = "10 / 2";
     RegexUtil dividing = new RegexUtil();
     string answer = dividing.ExtractsOp(input);
     string expected = "/";
     Assert.AreEqual(expected, answer);
 }
コード例 #8
0
 public void ExtractsAddOperand()
 {
     string input = "3 + 4";
     RegexUtil adding = new RegexUtil();
     string answer = adding.ExtractsOp(input);
     string expected = "+";
     Assert.AreEqual(expected, answer);
 }
コード例 #9
0
 public void DoesNotTakeNoOpPresent()
 {
     string input = "24";
     RegexUtil process = new RegexUtil();
     ArrayList answer = process.ExtractNums(input);
 }
コード例 #10
0
 public void doesNotTakeBadInputWithTwoOps()
 {
     string input = "3 + %";
     RegexUtil processor = new RegexUtil();
     ArrayList answer = processor.ExtractNums(input);
 }
コード例 #11
0
 public void DoesNotTakeBadInput2()
 {
     string input = "+ 24 5";
     RegexUtil processor = new RegexUtil();
     ArrayList answer = processor.ExtractNums(input);
 }
コード例 #12
0
 public void Execute(string input)
 {
     RegexUtil ProcessIt = new RegexUtil();
 }
コード例 #13
0
 public void DoesNotTakeAlphabet()
 {
     string input = "abc + def";
     RegexUtil process = new RegexUtil();
     ArrayList answer = process.ExtractNums(input);
 }