public void EmptyStringReturnsZero() { var input = ""; var output = StringCalculator.Calculate(input); Assert.AreEqual(output, 0); }
public void SingleNumberReturnsValue() { var input = "8"; var output = StringCalculator.Calculate(input); Assert.AreEqual(8, output); }
public void EmptyStringReturnsZero() { var stringCalculator = new StringCalculator(); Assert.AreEqual(0, stringCalculator.Calculate("")); }
public void TwoNumbersNewLineDelimitedReturnsSum() { var input = "8\n2"; var output = StringCalculator.Calculate(input); Console.WriteLine(output); Assert.AreEqual(output, 10); }
public void Should_Calculate_NegativeNumbers_ThrowsException() { //Arrange //Act int result = StringCalculator.Calculate("-2\n3,4"); //Assert }
public void Should_Calculate_WithMultiCharDelimiter_ReturnsSum() { //Arrange //Act int result = StringCalculator.Calculate("//[###]2###3###4"); //Assert Assert.AreEqual(9, result); }
public void Should_Calculate_WithManySingleOrMultiCharDelimiter_ReturnsSum() { //Arrange //Act int result = StringCalculator.Calculate("//[$][,]2$3,4,5"); //Assert Assert.AreEqual(14, result); }
public void Should_Calculate_ThreeNumbersEitherDelimited_ReturnsSum() { //Arrange //Act int result = StringCalculator.Calculate("2\n3,4"); //Assert Assert.AreEqual(9, result); }
public void Should_Calculate_TwoNumbersNewLineDelimited_ReturnsSum() { //Arrange //Act int result = StringCalculator.Calculate("2\n3"); //Assert Assert.AreEqual(5, result); }
public void Should_Calculate_NumbersGreaterThan1000_AreIgnored() { //Arrange //Act int result = StringCalculator.Calculate("2\n1001,4"); //Assert Assert.AreEqual(6, result); }
public void Should_Calculate_WithSingleLineDelimiter_ReturnsSum() { //Arrange //Act int result = StringCalculator.Calculate("//#2#3#4"); //Assert Assert.AreEqual(9, result); }
public void Should_Calculate_EmptyString_ReturnsZero() { //Arrange //Act int result = StringCalculator.Calculate(""); //Assert Assert.AreEqual(0, result); }
public void Should_Calculate_SingleNumber_ReturnsNumber() { //Arrange //Act int result = StringCalculator.Calculate("2"); //Assert Assert.AreEqual(2, result); }
public void Calculator_GetsSumNumberSentenceForString(string inputString, string expectedNumberSentence) { var parser = new InputStringParser(); parser.Settings.AllowNegativeValues = true; var sut = new StringCalculator(parser); var numberSentence = sut.Calculate(inputString, new AdditionOperation()).NumberSentence; Assert.Equal(expectedNumberSentence, numberSentence); }
public void Calculator_GetsProductForString(string inputString, int expectedProduct) { var parser = new InputStringParser(); parser.Settings.AllowNegativeValues = true; parser.Settings.Delimiters.Add("\n"); var sut = new StringCalculator(parser); var product = sut.Calculate(inputString, new MultiplicationOperation()).Result; Assert.Equal(expectedProduct, product); }
public void Calculator_GetsDifferenceForString(string inputString, int expectedDifference) { var parser = new InputStringParser(); parser.Settings.AllowNegativeValues = true; parser.Settings.Delimiters.Add("\n"); var sut = new StringCalculator(parser); var difference = sut.Calculate(inputString, new SubtractionOperation()).Result; Assert.Equal(expectedDifference, difference); }
public void Calculator_GetsQuotientForString(string inputString, int expectedQuotient) { var parser = new InputStringParser(); parser.Settings.AllowNegativeValues = true; parser.Settings.Delimiters.Add("\n"); var sut = new StringCalculator(parser); var quotient = sut.Calculate(inputString, new DivisionOperation()).Result; Assert.Equal(expectedQuotient, quotient); }
public void Calculator_GetsSumForString(string inputString, int expectedSum) { var parser = new InputStringParser(); parser.Settings.AllowNegativeValues = true; parser.Settings.Delimiters.Add("\n"); var sut = new StringCalculator(parser); var sum = sut.Calculate(inputString, new AdditionOperation()).Result; Assert.Equal(expectedSum, sum); }
public void Calculator_ShouldThrowExceptionForNegativeValues(string inputString, int[] valuesInExceptionMessage) { var parser = new InputStringParser(); parser.Settings.AllowNegativeValues = false; parser.Settings.Delimiters.Add("\n"); var sut = new StringCalculator(parser); var ex = Assert.Throws <NegativeValuesNotSupportedException>(() => sut.Calculate(inputString, new AdditionOperation())); foreach (var number in valuesInExceptionMessage) { Assert.Contains(number.ToString(), ex.Message); } }
public void NumbersGreaterThan1000() { var stringCalculator = new StringCalculator(); Assert.Throws <NumberGreaterThanThousandException>(() => stringCalculator.Calculate("1001")); }
public void NumbersMixedWithStrings() { var stringCalculator = new StringCalculator(); Assert.AreEqual(2, stringCalculator.Calculate("abc,2")); }
public void CalculateWorks(String expression, Double expectedValue) { Assert.That(calculator.Calculate(expression), Is.EqualTo(expectedValue)); }
public void SumOfTenNumbersWithDotAsDelimiter() { var stringCalculator = new StringCalculator(); Assert.AreEqual(55, stringCalculator.Calculate("1,2.3.4.5.6.7.8.9.10")); }
public void NegativeNumbersThrowException() { var stringCalculator = new StringCalculator(); Assert.Throws <NegativeNumbersException>(() => stringCalculator.Calculate("-12")); }
public void TwoNumbersAndCommaDelimited() { var stringCalculator = new StringCalculator(); Assert.AreEqual(4, stringCalculator.Calculate("1,3")); }
public void ThreeNumbersDelimited() { var stringCalculator = new StringCalculator(); Assert.AreEqual(6, stringCalculator.Calculate("1\n2,3")); }
public void OnehundredAddedThirtyIsOnehundredthirty() { var stringCalculator = new StringCalculator(); Assert.AreEqual(130, stringCalculator.Calculate("100,30")); }
public void TwoNumbersNewLineDelimited() { var stringCalculator = new StringCalculator(); Assert.AreEqual(3, stringCalculator.Calculate("1\n2")); }
static void Main(string[] args) { var parser = new InputStringParser(); IOperation operation = new AdditionOperation();; var argValues = CommandLine.Parser.Default.ParseArguments <CommandLineArgumentOptions>(args); if (!argValues.Errors.Any()) { // Values are available here if (!string.IsNullOrEmpty(argValues.Value.AlternateDelimiter)) { parser.Settings.Delimiters.Add(argValues.Value.AlternateDelimiter); } parser.Settings.AllowNegativeValues = argValues.Value.AllowNegativeValues; parser.Settings.MaximumValue = argValues.Value.MaximumValue; if (argValues.Value.Operation == Operations.Add) { operation = new AdditionOperation(); } else if (argValues.Value.Operation == Operations.Subtract) { operation = new SubtractionOperation(); } else if (argValues.Value.Operation == Operations.Multiply) { operation = new MultiplicationOperation(); } else if (argValues.Value.Operation == Operations.Divide) { operation = new DivisionOperation(); } } else { return; } var calculator = new StringCalculator(parser); Console.WriteLine(calculator.PromptString); Console.WriteLine("Multiline strings may be entered. Input an empty line to terminate the input. " + "The application will repeat execution until the console is closed or terminated with 'Ctrl+C'"); while (true) { try { string line; string input = string.Empty; while (!String.IsNullOrWhiteSpace(line = Console.ReadLine())) { input += line + "\n"; } var result = calculator.Calculate(input.Trim(), operation).NumberSentence; Console.WriteLine($"Result: {result}"); } catch (Exception ex) { Console.WriteLine($"Error Calculating Value. Error details: {ex.Message}"); } Console.WriteLine("\n"); } }
public void SingleNumberReturnsValue() { var stringCalculator = new StringCalculator(); Assert.AreEqual(1, stringCalculator.Calculate("1")); }