public int Add(string inputs)
        {
            CalculationExpressionParser parser = new CalculationExpressionParser();
            string[] delimiter = parser.Delimiters(inputs);
            string[] allSeparators = delimiter.Concat(new[]{"\n"}).ToArray();
            string[] strings = inputs.Split(allSeparators, StringSplitOptions.RemoveEmptyEntries);

            int temp = 0;
            int result = 0;
            foreach (string number in strings)
            {
                if(Int32.TryParse(number, out temp))
                {
                    bool stopProcessing = false;
                    foreach (ProcessValueAction numberStragey in _numberStrageies)
                    {
                        numberStragey(temp, ref result, ref stopProcessing);
                        if (stopProcessing)
                            break;
                    }
                }
            }

            if(_invalidNumbers.Count > 0)
                throw new ArgumentException("Invalid Numbers: " + String.Join(", ", _invalidNumbers.Select(x => x.ToString())));

            return result;
        }
 public void ContainsDelimiterExpression_IsValid_ForMultipleDelimiters()
 {
     string multipleDelimiterProgram = "//[*][%]\n1*2%3";
     CalculationExpressionParser parser = new CalculationExpressionParser();
     bool result = parser.ContainsDelimiterExpression(multipleDelimiterProgram);
     Assert.IsTrue(result);
 }
 public void InputInstructions_ValidForOneNumber()
 {
     CalculationExpressionParser parser = new CalculationExpressionParser();
     string singleNumber = parser.InputInstructions("//;\n1");
     Assert.AreEqual("1", singleNumber);
     string multipleNumbers = parser.InputInstructions("//;\n1,2");
     Assert.AreEqual("1,2", multipleNumbers);
 }
 public void Delimiters_HasMultipleCorrectDelimiters()
 {
     string multipleDelimiterProgram = "//[*][%]\n1*2%3";
     CalculationExpressionParser parser = new CalculationExpressionParser();
     string[] result = parser.Delimiters(multipleDelimiterProgram);
     Assert.AreEqual(2, result.Length);
     CollectionAssert.AreEqual(new[]{"*", "%"}, result);
 }
        public void Delimiters_IsValidFor_MultiCharacterDelimiters()
        {
            CalculationExpressionParser parser = new CalculationExpressionParser();
            string calcProgram = "//[***]\n1***2***3";
            string delimiter = parser.Delimiters(calcProgram)[0];
            Assert.AreEqual("***", delimiter);

            string instructions = parser.InputInstructions(calcProgram);
            Assert.AreEqual("1***2***3", instructions);
        }
        public void ContainsDelimiterExpression_SingleCharacterDelimitersExpressions_Valid()
        {
            CalculationExpressionParser parser = new CalculationExpressionParser();

            string[] singleCharacterDelimiterPrograms = {
                "//;\n1;2",
                "//,\n1,2"
            };

            foreach (string calcProgram in singleCharacterDelimiterPrograms)
            {
                bool positiveResult = parser.ContainsDelimiterExpression(calcProgram);
                Assert.IsTrue(positiveResult);
            }
        }
 public void InputInstructions_Valid_WithoutDelimiterExpression()
 {
     CalculationExpressionParser parser = new CalculationExpressionParser();
     string multipleNumbersNoInstructions = parser.InputInstructions("2,1");
     Assert.AreEqual("2,1", multipleNumbersNoInstructions);
 }
 public void Delimiters_DelimiterExpressionWithSingleCharacterIsValid()
 {
     CalculationExpressionParser parser = new CalculationExpressionParser();
     ValidateSingleCharacterDelimiterExpression(parser, ";", "//;\n1;2");
     ValidateSingleCharacterDelimiterExpression(parser, ",", "//,\n1,2");
 }
 private static void ValidateSingleCharacterDelimiterExpression(CalculationExpressionParser parser, string expected, string calcProgram)
 {
     string[] delimiters = parser.Delimiters(calcProgram);
     Assert.IsTrue(delimiters.Contains(expected));
 }
 public void ContainsDelimiterExpression_InvalidWithoutNewline()
 {
     CalculationExpressionParser parser = new CalculationExpressionParser();
     bool negativeResult = parser.ContainsDelimiterExpression("//;1;2");
     Assert.IsFalse(negativeResult);
 }
 public void IsMultiDelimiter_Single_Delimiters_AreNot_Classified_As_Multiples()
 {
     CalculationExpressionParser parser = new CalculationExpressionParser();
     string[] testCases = {
         "[%]",
         "[*]"
     };
     foreach (string invalidCase in testCases)
     {
         Assert.IsFalse(parser.IsMultiDelimiter(invalidCase));
     }
 }
 public void IsMultiDelimiter_MatchesMultipleDelimiters()
 {
     CalculationExpressionParser parser = new CalculationExpressionParser();
     string[] testCases = {
         "[%][*]",
         "[***][%%%]"
     };
     foreach (string validCase in testCases)
     {
         Assert.IsTrue(parser.IsMultiDelimiter(validCase));
     }
 }