public void AddsFourNumbers()
        {
            StringCalculator stringCalculator = new StringCalculator();
            var result = stringCalculator.Add("1,2,3,4");

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

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

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

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

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

            Assert.AreEqual(0, result);
        }
        public void Add_GivenNumbersAsStringSeparatedByComma_ShouldReturnSumOfThoseNumbersAsInteger(string numbers, int expected)
        {
            //----------------Arrange------------------------
            var stringCalculator = new StringCalculator();

            //----------------Act----------------------------
            var actual = stringCalculator.Add(numbers);

            //----------------Assert-------------------------
            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void Add_GivenValidInputOfNumbersGreaterThan1000_ShouldReturnSumOfNumbersLessThan1000(string input, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

            //Act
            var actual = sut.Add(input);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        public void Add_GivenValidInputofWithSeparatelineCustomDelimeter_ShouldSumofAllNumbers(string input, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

            //Act
            var actual = sut.Add(input);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Пример #10
0
        public void Add_GivenValidInputWithNewLines_ShouldSumofAllNumbers(string input, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

            //Act
            var actual = sut.Add(input);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Пример #11
0
        public void Add_GivenValidInputContainSquareBracketsDelimeter_ShouldSumofAllNumbers(string input, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

            //Act
            var actual = sut.Add(input);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Пример #12
0
        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");
        }
Пример #13
0
        public void Add_WhenNumbersLargerThan1000_ShouldReturnSumOfNumbersLessThan1000()
        {
            //---------------Arrange-------------------
            var input      = "3,5,1001";
            var expected   = 8;
            var calculator = new StringCalculator();
            //---------------Act----------------------
            var result = calculator.Add(input);

            //---------------Assert-----------------------
            Assert.AreEqual(expected, result);
        }
Пример #14
0
        public void Add_WhenCustomMulitpleCharDelimiter_ShouldReturnSum()
        {
            //---------------Arrange-------------------
            var input      = "//[**]\n5**4**9";
            var expected   = 18;
            var calculator = new StringCalculator();
            //---------------Act----------------------
            var result = calculator.Add(input);

            //---------------Assert-----------------------
            Assert.AreEqual(expected, result);
        }
Пример #15
0
        public void Add_WhenCommaDelimitedString_ShouldReturnSum()
        {
            //---------------Arrange-------------------
            var input      = "5,5,9";
            var expected   = 19;
            var calculator = new StringCalculator();
            //---------------Act----------------------
            var result = calculator.Add(input);

            //---------------Assert-----------------------
            Assert.AreEqual(expected, result);
        }
Пример #16
0
        public void Add_WhenManyCustomMulitpleCharDelimiters_ShouldReturnSum()
        {
            //---------------Arrange-------------------
            var input      = "//[%*][&!][(##)]\n3%*6&!11(##)22";
            var expected   = 42;
            var calculator = new StringCalculator();
            //---------------Act----------------------
            var result = calculator.Add(input);

            //---------------Assert-----------------------
            Assert.AreEqual(expected, result);
        }
Пример #17
0
        public void Add_WhenEmptyString_ShouldReturnZero()
        {
            //---------------Arrange-------------------
            var input      = string.Empty;
            var expected   = 0;
            var calculator = new StringCalculator();
            //---------------Act----------------------
            var result = calculator.Add(input);

            //---------------Assert-----------------------
            Assert.AreEqual(expected, result);
        }
Пример #18
0
        public void Add_WhenNumbersLessThanOrEqualTo1000_ShouldReturnSum()
        {
            //---------------Arrange-------------------
            var input      = "3,2,1000,9";
            var expected   = 1014;
            var calculator = new StringCalculator();
            //---------------Act----------------------
            var result = calculator.Add(input);

            //---------------Assert-----------------------
            Assert.AreEqual(expected, result);
        }
Пример #19
0
        public void Add_WhenNewlineDelimited_ShouldReturnSum()
        {
            //---------------Arrange-------------------
            var input      = "3\n1\n5";
            var expected   = 9;
            var calculator = new StringCalculator();
            //---------------Act----------------------
            var result = calculator.Add(input);

            //---------------Assert-----------------------
            Assert.AreEqual(expected, result);
        }
Пример #20
0
        public void Add_GivenInvalidInput_ShouldReturnZero(string input)
        {
            //Arrange
            var expected = 0;
            var sut      = new StringCalculator();

            //Act
            var actual = sut.Add(input);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Пример #21
0
        public void Add_GivenNeagativeNumbersAsInput_ShouldThrowAnExceptionMessage(string input)
        {
            //Arrange
            var sut = new StringCalculator();

            //Act
            var actual = Assert.Throws <Exception>(() => sut.Add(input));

            //Assert
            var expected = "Negatives are not allowed" + input;

            Assert.AreEqual(expected, actual.Message);
        }
Пример #22
0
        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());
        }
Пример #23
0
        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);
        }
Пример #24
0
        public void ReturnTenWhenValuesOneAndTwoAndThreeAndFourAreAdded()
        {
            int result = StringCalculator.Add("1,2,3,4");

            Assert.AreEqual(result, 10);
        }
Пример #25
0
        public void ReturnZeroWhenEmptyStringIsAdded()
        {
            int result = StringCalculator.Add("");

            Assert.AreEqual(result, 0);
        }
 public void NegativeNumberThrowsAnException()
 {
     StringCalculator stringCalculator = new StringCalculator();
     var result = stringCalculator.Add("1,2,3,-4");
 }
 public void AddWithStringNumbersAndNewLineAndExtraDelimiterWithVariableLengthExpectCorrectResults(string input, string result)
 {
     var target = new StringCalculator();
     Assert.That(target.Add(input), Is.EqualTo(result));
 }
Пример #28
0
 public void Sum_SingleNumber_ReturnsThatNumber(string numbers, int expected)
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(expected, stringCalc.Add(numbers));
 }
Пример #29
0
 public void Sum_NewLineDelimiter_ReturnsSumOfNumbers()
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(3, stringCalc.Add("1\n2"));
 }
Пример #30
0
 public void Sum_EmptyString_ReturnsZero()
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(0, stringCalc.Add(""));
 }
        public void ReturnZeroWhenEmptyInput()
        {
            var result = StringCalculator.Add("");

            Assert.Equal(0, result);
        }
        public void AcceptCustomSeparatorMoreThanOneCharacter()
        {
            var result = StringCalculator.Add("//;w\n4;w4");

            Assert.Equal(8, result);
        }
Пример #33
0
        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");
        }
Пример #34
0
        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);
        }
Пример #35
0
        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);
        }
Пример #36
0
 public void Sum_UnknownNumberOfNumbers_ReturnsSumOfNumbers(string numbers, int expected)
 {
     var stringCalc = new StringCalculator();
     Assert.AreEqual(expected, stringCalc.Add(numbers));
 }
 public void AddWithStringNumbersGreatetThan1000ExpectCorrectResults(string input, string result)
 {
     var target = new StringCalculator();
     Assert.That(target.Add(input), Is.EqualTo(result));
 }
        public void Add_TwoNumberString_ReturnSum(string value, int expected)
        {
            int result = StringCalculator.Add(value);

            Assert.AreEqual(result, expected);
        }
 public void AddWithStringNumbersAndNegativeNumbersThrows(string input, string message)
 {
     var target = new StringCalculator();
     var ex = Assert.Throws<Exception>(() => target.Add(input));
     Assert.That(ex.Message, Is.EqualTo(message));
 }
        public void Add_TwoNumberStringWithNewLineDelimiter_ReturnSum()
        {
            int result = StringCalculator.Add("1\n2");

            Assert.AreEqual(result, 3);
        }
 public void MultipleNegativeNumbersThrowsAnException()
 {
     StringCalculator stringCalculator = new StringCalculator();
     var result = stringCalculator.Add("1,2,3,-4,5,-10");
 }
        public void Add_MultipleNumberString_ReturnSum()
        {
            int result = StringCalculator.Add("1,2,3");

            Assert.AreEqual(result, 6);
        }
Пример #43
0
        public void ReturnOriginalValueWhenSingleNumberIsAdded()
        {
            int result = StringCalculator.Add("1");

            Assert.AreEqual(result, 1);
        }
Пример #44
0
        public void ReturnThreeWhenCustomDelimitersAreUsedBetweenValuesOneAndTwo()
        {
            int result = StringCalculator.Add("//;\n1;2");

            Assert.AreEqual(result, 3);
        }
Пример #45
0
        public void ReturnThreeWhenValuesOneAndTwoAreAdded()
        {
            int result = StringCalculator.Add("1,2");

            Assert.AreEqual(result, 3);
        }
Пример #46
0
        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);
        }
Пример #47
0
        public void ReturnSixWhenValuesOneAndTwoAndThreeAreAddedWithBothNewLineAndCommarAsSeperators()
        {
            int result = StringCalculator.Add("1\n2,3");

            Assert.AreEqual(result, 6);
        }
Пример #48
0
        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);
        }
Пример #49
0
        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());
        }
Пример #50
0
        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 Add_NegativNumber_ThrowException()
 {
     int result = StringCalculator.Add("-1");
 }
Пример #52
0
        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 Add_NumberOver1000_IngnoreThem()
        {
            int result = StringCalculator.Add("1,1001");

            Assert.AreEqual(result, 1);
        }
Пример #54
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 Add_EmptyString_ReturnZero()
        {
            int result = StringCalculator.Add("");

            Assert.AreEqual(result, 0);
        }
Пример #56
0
        public void should_return_0_for_empty_string()
        {
            // arrange
            var calculator = new StringCalculator();

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

            // assert
            add.Should().Be(0);
        }