public void ShouldNotAllowNumberBiggerThanThousandAndWithManyDelemiters(string input)
        {
            _stringCalculator = new StringCalculator(input);

            var sumOfValueInAString = _stringCalculator.GetTheCalculatedValue();
            Assert.That(sumOfValueInAString, Is.EqualTo(6));
        }
        public void AddsFourNumbers()
        {
            StringCalculator stringCalculator = new StringCalculator();
            var result = stringCalculator.Add("1,2,3,4");

            Assert.AreEqual(10, result);
        }
        public void AddsEmptyString()
        {
            StringCalculator stringCalculator = new StringCalculator();
            var result = stringCalculator.Add("");

            Assert.AreEqual(0, result);
        }
        public void AddsNumbersWithNewLines()
        {
            StringCalculator stringCalculator = new StringCalculator();
            var result = stringCalculator.Add("1\n2,3");

            Assert.AreEqual(6, result);
        }
        public void AddsNumbersWithNewLinesAndCommasMixed()
        {
            StringCalculator stringCalculator = new StringCalculator();
            var result = stringCalculator.Add("1\n2,3,\n,4,\n5");

            Assert.AreEqual(15, result);
        }
        public void AddsOneNumber()
        {
            StringCalculator stringCalculator = new StringCalculator();
            var result = stringCalculator.Add("1");

            Assert.AreEqual(1, result);
        }
        public void ShouldCalculateSumOfsingleValueInaString(string input, int output)
        {
            _stringCalculator = new StringCalculator(input);
            var sumOfValuesOFThestring = _stringCalculator.GetTheCalculatedValue();

            Assert.That(sumOfValuesOFThestring, Is.EqualTo(output));
        }
        public void AddsTwoNumbers()
        {
            StringCalculator stringCalculator = new StringCalculator();
            var result = stringCalculator.Add("1,2");

            Assert.AreEqual(3, result);
        }
        public void Add_EmptyString_ReturnZero()
        {
            StringCalculator stringCalc = new StringCalculator();

            int result = StringCalculator.Add("");

            Assert.AreEqual(0, result);
        }
        public void should_return_14_for_5_and_9()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int add = calculator.Add("5,9");

            // assert
            add.Should().Be(14);
        }
Beispiel #11
0
 internal void Add(string numbers)
 {
     var calculator = new StringCalculator(new[] { "," });
     var result = calculator.Add(numbers);
     Console.WriteLine(string.Format("The result is {0}", result));
 }
        public void should_return_5_for_5()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int add = calculator.Add("5");

            // assert
            add.Should().Be(5);
        }
        public void should_return_sum_for_unknown_amount_of_numbers()
        {
            // arrange
            int[] numbersWithUnknownAmounts = GetRandomNumbers();
            string numbers = String.Join(",", numbersWithUnknownAmounts);
            var calculator = new StringCalculator();

            // act
            int add = calculator.Add(numbers);

            // assert
            add.Should().Be(numbersWithUnknownAmounts.Sum());
        }
        public void ShouldReturnSumOfValuesInAStringStartingWithDelimeter(string input, int output)
        {
            _stringCalculator = new StringCalculator(input);

            var sumOfValueInAString = _stringCalculator.GetTheCalculatedValue();
            Assert.That(sumOfValueInAString, Is.EqualTo(output));
        }
 public void SetUp()
 {
     calculator = new StringCalculator();
 }
        public void should_support_multiple_delimiters()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int result = calculator.Add("//[==-][&&$]\n2==-3==-6&&$8&&$9");

            // assert
            result.Should().Be(2 + 3 + 6 + 8 + 9);
        }
 public void Sum_SingleNumber_ReturnsThatNumber(string numbers, int expected)
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(expected, stringCalc.Add(numbers));
 }
 public void Sum_UnknownNumberOfNumbers_ReturnsSumOfNumbers(string numbers, int expected)
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(expected, stringCalc.Add(numbers));
 }
 public void MultipleNegativeNumbersThrowsAnException()
 {
     StringCalculator stringCalculator = new StringCalculator();
     var result = stringCalculator.Add("1,2,3,-4,5,-10");
 }
 public StringCalculatorTests()
 {
     _calculator = new StringCalculator();
 }
 public void BeforeEachTest()
 {
     _stringCalculator = new StringCalculator();
 }
        public void should_throw_exception_for_negatives_and_message_should_list_all_negatives()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            Action act = () => calculator.Add("-1,2,-3");

            // assert
            act.ShouldThrow<InvalidOperationException>()
                .WithMessage("negatives are not allowed: " + "-1,-3");
        }
        public void should_support_new_line_as_delimiter()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int add = calculator.Add("3,4\n6\n7");

            // assert
            add.Should().Be(3 + 4 + 6 + 7);
        }
        public void should_return_0_for_empty_string()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int add = calculator.Add("");

            // assert
            add.Should().Be(0);
        }
        public void ShouldThrowAnExceptionwhenNegativeNumberIsPassed(string input)
        {
            _stringCalculator = new StringCalculator(input);

            Assert.Throws<System.NotSupportedException>(() => _stringCalculator.GetTheCalculatedValue());
        }
        public void should_ignore_numbers_greater_than_1000()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int result = calculator.Add("2,1002");

            // assert
            result.Should().Be(2);
        }
        public void should_support_custom_delimiter()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int result = calculator.Add("//*\n4*3*2");

            // assert
            result.Should().Be(4 + 3 + 2);
        }
 public void Sum_EmptyString_ReturnsZero()
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(0, stringCalc.Add(""));
 }
        public void should_support_delimiters_of_any_length()
        {
            // arrange
            var calculator = new StringCalculator();

            // act
            int result = calculator.Add("//[***]\n1***2***3");

            // assert
            result.Should().Be(1 + 2 + 3);
        }
 public void NegativeNumberThrowsAnException()
 {
     StringCalculator stringCalculator = new StringCalculator();
     var result = stringCalculator.Add("1,2,3,-4");
 }
 public void Sum_NewLineDelimiter_ReturnsSumOfNumbers()
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(3, stringCalc.Add("1\n2"));
 }