public void ExtractNumbers_Should_Return_Numbers_Part_For_Multiple_Delimiter() { string numbers = @"//;\n1;2"; char delimiter = ','; char[] delimiterArray = new char[] {}; numbers = numbersExtractor.ExtractNumbers(numbers, delimiter, ref delimiterArray); Assert.AreEqual("1;2", numbers); }
public int Add(string numbers) { int sum = 0; // null, empty or whitespace input if (string.IsNullOrWhiteSpace(numbers)) { return(sum); } // validate input if (!validator.IsValid(numbers)) { throw new Exception("Invalid Input"); } // default delimiter char delimiter = ','; // delimiter array to hold multiple delimiter char[] delimiterArray = new char[] {}; // get numbers input if multiple delimiters present // if single delimiter present then add it to delimiters array numbers = numbersExtractor.ExtractNumbers(numbers, delimiter, ref delimiterArray); // replace new line character with default or first delimiter replacer.Replace(ref numbers, "\\n", delimiterArray[0].ToString()); //Console.WriteLine(numbers); // calculate sum if (delimiterArray.Length == 0) { // with no delimiter sum = Convert.ToInt32(numbers); } else { // with single or multiple delimeters sum = this.sumCalculator.CalculateSum(numbers, delimiterArray); } return(sum); }