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 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()))); try { _logger.Write("Sum Result: " + result); } catch (Exception ex) { _service.Notify(ex.Message); } return result; }
private static void ValidateSingleCharacterDelimiterExpression(CalculationExpressionParser parser, string expected, string calcProgram) { string[] delimiters = parser.Delimiters(calcProgram); Assert.IsTrue(delimiters.Contains(expected)); }