예제 #1
0
        public void GivenAnEmptyStringShouldReturnZero()
        {
            var calculator = new StringCalculator();
            var expected = 0;

            Assert.AreEqual(expected, calculator.Add(string.Empty));
        }
예제 #2
0
        public void GivenConsecutiveDelimetersShouldThrowException()
        {
            var calculator = new StringCalculator();
            var expected = -1;

            Assert.Throws(typeof(ArgumentException), () => calculator.Add(",,"));
        }
예제 #3
0
        public void GivenASingleNumberShouldReturnNumber()
        {
            var calculator = new StringCalculator();
            var expected = 1;

            Assert.AreEqual(expected, calculator.Add("1"));
        }
예제 #4
0
        public void GivenNewLineAsDelimeterShouldReturnSumOfAllNumbers()
        {
            var calculator = new StringCalculator();
            var expected = 6;

            Assert.AreEqual(expected, calculator.Add("1\n2\n3"));
        }
예제 #5
0
        public void GivenMultipleNumbersShouldReturnSumOfAllNumbers()
        {
            var calculator = new StringCalculator();
            var expected = 6;

            Assert.AreEqual(expected, calculator.Add("1,2,3"));
        }
예제 #6
0
        public void NegativeNumberErrorMessageShouldContainNegativeNumber()
        {
            var calculator = new StringCalculator();

            var error = Assert.Throws(typeof(ArgumentOutOfRangeException), () => calculator.Add("-1,2"));
            Assert.True(error.Message.Contains("-1"));
        }
예제 #7
0
        public void GivenTwoNumbersShouldReturnTheSumOfBothNumbers()
        {
            var calculator = new StringCalculator();
            var expected = 3;

            Assert.AreEqual(expected, calculator.Add("1,2"));
        }
예제 #8
0
 public void QuandoEseguoIlCalcolo()
 {
     var stringa = ScenarioContext.Current.Get<string>("stringa");
     var stringCalculator = new StringCalculator();
     var result = stringCalculator.Add(stringa);
     ScenarioContext.Current.Add("somma", result);
 }
예제 #9
0
 public void Add_ShouldBeAbleToHandleNewLineInParameterString()
 {
     var calculator = new StringCalculator();
     var result = calculator.Add(@"1
     2");
     Assert.AreEqual(3, result);
 }
예제 #10
0
 public void Add_ShouldBeAbleToHandleUserDefinedDelimiter()
 {
     var calculator = new StringCalculator();
     var result = calculator.Add(@"//;
     1;2");
     Assert.AreEqual(3, result);
 }
예제 #11
0
        public void GivenANegativeNumberShouldReturnThrowAnException()
        {
            var calculator = new StringCalculator();
            var expected = -1;

            Assert.Throws(typeof(ArgumentOutOfRangeException), () => calculator.Add("-1,2"));
        }
예제 #12
0
 public void Add_ShouldBeAbleToHandleBothNewLineAndCommaParameterString()
 {
     var calculator = new StringCalculator();
     var result = calculator.Add(@"1,
     2,3");
     Assert.AreEqual(6, result);
 }
        public void Add_WhenAnEmptyStringIsUsedThenZeroIsReturned()
        {
            StringCalculator sc = new StringCalculator();
            string emptyParameter = string.Empty;

            var result = sc.Add(emptyParameter);
            Assert.AreEqual(0, result);
        }
        public void Add_ProvidedNumbersInStringWithCustomDelimiters_ReturnValue(string input, int expectedOutput)
        {
            var stringCalculator = new StringCalculator();

            var result = stringCalculator.Add(input);

            Assert.AreEqual(expectedOutput, result);
        }
        public void Add_WhenANewLineCharacterIsUsedThenItIsTreatedAsADelimiterAndTheSumOfTheNumbersIsReturned()
        {
            StringCalculator sc = new StringCalculator();
            string twoNumberParameter = "1,2\n3,4,5";

            var result = sc.Add(twoNumberParameter);
            Assert.AreEqual(1 + 2 + 3 + 4 + 5, result);
        }
        public void Add_WhenAMultipleCharacterDelimiterIsSpecfiedInTheNumberParameterThenItIsUsedToSeparateTheNumbers()
        {
            StringCalculator sc = new StringCalculator();
            string numbersParameter = "//[---]\n1---2---3---4---5";

            var result = sc.Add(numbersParameter);
            Assert.AreEqual(1 + 2 + 3 + 4 + 5, result);
        }
        public void Add_WhenAnyNumbersofNumbersAreUsedThenTheSumOfTheNumbersIsReturned()
        {
            StringCalculator sc = new StringCalculator();
            string twoNumberParameter = "1,2,3,4,5";

            var result = sc.Add(twoNumberParameter);
            Assert.AreEqual(1 + 2 + 3 + 4 + 5, result);
        }
        public void Add_WhenOneNumberIsUsedThenThatNumberIsReturned()
        {
            StringCalculator sc = new StringCalculator();
            string oneNumberParameter = "1";

            var result = sc.Add(oneNumberParameter);
            Assert.AreEqual(1, result);
        }
        public void Add_WhenADelimiterParameterIsSpecfiedThenItIsUsedToSeparateTheNumbers()
        {
            StringCalculator sc = new StringCalculator();
            string twoNumberParameter = "1;2;3;4;5";
            string[] delimiters = new string[] { ";" };

            var result = sc.Add(twoNumberParameter, delimiters);
            Assert.AreEqual(1 + 2 + 3 + 4 + 5, result);
        }
 public void should_return_zero_for_empty_string()
 {
     //arrange
     var calc = new StringCalculator();
     //act
     var result = calc.Add("");
     //accert
     result.ShouldBeEquivalentTo(0);
 }
 public void should_handle_one_number()
 {
     //arrange
     var calc = new StringCalculator();
     var randomNumber = new Random().Next(10);
     //act
     var result = calc.Add(randomNumber.ToString());
     //accert
     result.ShouldBeEquivalentTo(randomNumber);
 }
        public void should_handle_new_line_separator()
        {
            //arrange
            var calc = new StringCalculator();

            //act
            var result = calc.Add("1\n2,3");
            //accert
            result.ShouldBeEquivalentTo(6);
        }
        public void Add_ThreeNumbers10And21And15WithNewLineDemilter_Returns46()
        {
            //Arrange
            var stringCalculator = new StringCalculator();

            //Act
            var result = stringCalculator.Add("10\n21\n15");

            //Assert
            Assert.AreEqual(46, result);
        }
예제 #24
0
        public void Add_GivenMultipleNumbersSeparatedByAComma_ShouldReturnTheirSum(string numbers, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #25
0
        public void Adding_multiple_numbers_returns_sum(string numbers, int sum)
        {
            //Arrange
            var caluculator = new StringCalculator();

            //Act
            var result = caluculator.Add(numbers);

            //Assert
            Assert.That(result, Is.EqualTo(sum));
        }
        public void Test_Add_Should_ReturnZero_When_CalledWithEmptyString()
        {
            // Arrange
            StringCalculator calc = new StringCalculator();

            // Act
            var result = calc.Add(String.Empty);

            // Assert
            Assert.AreEqual(0, result, "Result should be zero!");
        }
        public void Test_Add_Should_ReturnSum_When_CalledWithTwoNumbers()
        {
            // Arrange
            StringCalculator calc = new StringCalculator();

            // Act
            var result = calc.Add("1,2");

            // Assert
            Assert.AreEqual(3, result, "Result should be 3.");
        }
        public void Add_GivenNumbersWithNewLineInBetweenandSingleDelimeter_ShouldReturnTheSumOfNumbers(string numbers, int expected)
        {
            //Arrange
            var createStringCalculator = new StringCalculator();

            //Act
            var actual = createStringCalculator.Add(numbers);

            //Assert
            Assert.AreEqual(actual, expected);
        }
예제 #29
0
        public void Add_GivenNumbersThatAreGreaterThan1000_ShouldIgnoreThem(string numbers, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #30
0
        public void Add_SingleNumber_ReturnsSameNumber()
        {
            //Arrange
            var stringCalculator = new StringCalculator();

            //Act
            var actual = stringCalculator.Add("0");

            //Assert
            Assert.Equal(0, actual);
        }
예제 #31
0
        public void Add_GivenNegativeNumbers_ShouldReturnNegativesNotAllowedAndThoseNegativeNumbers(string numbers, string expected)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual.Message);
        }
예제 #32
0
        public void Add_GivenStringHavingMultipleCharDelimitersOfAnyLength_ShouldReturnTheSum(int expected, string input)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #33
0
        public void Add_WebService_Receives()
        {
            var custWebService = new TestWebService();
            var c = new StringCalculator(null, custWebService);

            try {
                c.Add("1,-2");
            }
            catch { }
            Assert.IsTrue(custWebService.message.Contains("Negatives"));
        }
 public void TestThatNegativeNumbersThrowAnException()
 {
     try
     {
         StringCalculator.Add("//$,#\n-1$2#3$1001");
     }
     catch (System.Exception ex)
     {
         Assert.AreEqual("Negatives not allowed\nThe invalid numbers were -1, ", ex.Message);
     }
 }
예제 #35
0
        public void Add_Numbers_ReturnsSum(string input, int result)
        {
            //Arrange
            StringCalculator calculator = new StringCalculator();
            int answer = 0;

            //Act
            answer = calculator.Add(input);
            //Assert
            Assert.AreEqual(result, answer);
        }
예제 #36
0
        [Test]//[TestMethod]
        public void Add_ThreeNumbers_ReturnsSum()
        {
            //Arrange
            StringCalculator calculator = new StringCalculator();
            int result = 0;

            //Act
            result = calculator.Add("1,2,3");
            //Assert
            Assert.AreEqual(6, result);
        }
예제 #37
0
        public void Add_EmptyString_ReturnsZero()
        {
            // Arrange
            var stringCalculator = new StringCalculator();

            // Act
            var actual = stringCalculator.Add("");

            // Assert
            Assert.Equal(0, actual);
        }
예제 #38
0
        public void Add_InputNullOrAlphabetic_ThrowsArgumentException(string input)
        {
            //Arrange
            var stringCalculator = new StringCalculator();

            //Act
            Action actual = () => stringCalculator.Add(input);

            //Assert
            Assert.Throws <ArgumentException>(actual);
        }
        public void Add_GivenThreeNumbers_ShouldReturnTheSumOfNumbers(string numbers, int expected)
        {
            //Arrange
            var createStringCalculator = new StringCalculator();

            //Act
            var actual = createStringCalculator.Add(numbers);

            //Assert
            Assert.AreEqual(actual, expected);
        }
 public void should_handle_two_numbers()
 {
     //arrange
     var calc = new StringCalculator();
     var oneNumber = new Random().Next(10);
     var twoNumber = new Random().Next(10);
     //act
     var result = calc.Add(oneNumber + "," + twoNumber);
     //accert
     result.ShouldBeEquivalentTo(oneNumber + twoNumber);
 }
 public void NegativeNumbersShouldReturnExceptionWithNumbers()
 {
     try
     {
         StringCalculator.Add("1,-2,-3,5");
     }
     catch (NotSupportedException e)
     {
         Assert.AreEqual("negatives not allowed -2 -3", e.Message);
     }
 }
        public void Add_TwoNumbers1And2_Returns3()
        {
            //Arrange
            var stringCalculator = new StringCalculator();

            //Act
            var result = stringCalculator.Add("1,2");

            //Assert
            Assert.AreEqual(3, result);
        }
예제 #43
0
        public void Add_GivenASingleNumber_ShouldReturnThatNumber(string numbers, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #44
0
        public void Add_GivenStringWithOneNumber_ShouldReturnTheNumberItself(int expected, string input)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //ASsert
            Assert.AreEqual(expected, actual);
        }
        public void Test_Add_Should_ReturnSingleNumber_When_CalledWithSingleNumber()
        {
            // Arrange
            StringCalculator calc = new StringCalculator();

            // Act
            var result = calc.Add("1");

            // Assert
            Assert.AreEqual(1, result, "Result should be 1.");
        }
예제 #46
0
        public void Add_GivenStringWithUnkownAmountOfNumbers_ShouldReturnTheSum(int expected, string input)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //ASsert
            Assert.AreEqual(expected, actual);
        }
        public void Test_Add_Should_ReturnSum_When_CalledWithMultipleNumbers(string input, int expectedResult)
        {
            // Arrange
            StringCalculator calc = new StringCalculator();

            // Act
            var result = calc.Add(input);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }
예제 #48
0
        public void Adding_one_number_returns_same_number(int number)
        {
            //Arrange
            var caluculator = new StringCalculator();

            //Act
            var result = caluculator.Add(number.ToString());

            //Assert
            Assert.That(result, Is.EqualTo(number));
        }
예제 #49
0
        public void Add_GivenMultipleNumbersSeparatedByDifferentDelimetersAndNewLineInBetween_ShouldReturnTheirSum(string numbers, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #50
0
        public void Add_GivenStringWithNegativeNumbers_ShouldReturnTheSum(string expected, string input)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //ASsert
            Assert.AreEqual(expected, actual.Message);
        }
예제 #51
0
        public void Add_GivenStringWithNumbersMoreThan1000_ShouldReturnTheSumOfThoseEqualOrLessThan1000(int expected, string input)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //ASsert
            Assert.AreEqual(expected, actual);
        }
        public void Add_ThreeNumbers10And21And15_Returns46()
        {
            //Arrange
            var stringCalculator = new StringCalculator();

            //Act
            var result = stringCalculator.Add("10,21,15");

            //Assert
            Assert.AreEqual(46, result);
        }
예제 #53
0
        public void Add_GivenEmptyString_ShouldReturn0(int expected, string input)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //ASsert
            Assert.AreEqual(expected, actual);
        }
예제 #54
0
        public void Add_GivenStringWithCustomDelimiter_ShouldReturnTheSum(int expected, string input)
        {
            //Arrange
            var sut = new StringCalculator();

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

            //ASsert
            Assert.AreEqual(expected, actual);
        }
예제 #55
0
        public void Add_MultipleNumbers_ReturnsSumOfNumbers(string input, int expected)
        {
            //Arrange
            var stringCalculator = new StringCalculator();

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

            //Assert
            Assert.Equal(expected, actual);
        }
예제 #56
0
        public void Adding_zero_numbers_returns_zero()
        {
            //Arrange
            var calculator = new StringCalculator();

            //Act
            var result = calculator.Add("");

            //Assert
            Assert.That(result, Is.EqualTo(0));
        }
예제 #57
0
        public void AllowsSpecifiedOneCharDelimiters()
        {
            // arrange
            var          calc  = new StringCalculator();
            const string input = "//;\n1;2";

            // act
            var result = calc.Add(input);

            // assert
            Assert.AreEqual(3, result);
        }
        public void Add_GivenNegativeNumbers_ShouldReturnNegativesNotAllowedAndNumbersThatAreNegative()
        {
            //Arrange
            var sut     = new StringCalculator();
            var numbers = "1\n-2,-3";

            //Act
            var expected = Assert.Throws <Exception> (() => sut.Add(numbers));

            //Assert
            Assert.AreEqual(" Negatives Not Allowed -2 -3", expected.Message);
        }
예제 #59
0
        public void write_in_file_StringCalculatorAdd_result()
        {
            var numbers = "1,2\n4";

            SaveAction.Run(_save, numbers);
            _sr = new StreamReader(_path);
            var writeLine = _sr.ReadToEnd();

            _sr.Close();

            writeLine.Should().Contain(numbers.Replace("\n", "[\\n]") + " = " + StringCalculator.Add(numbers));
        }
예제 #60
0
        public void Add_NegativeNumbers_ThrowsFormatException(string input, string invalidNumbers)
        {
            // arrange

            // act
            Action act = () => StringCalculator.Add(input);

            // assert
            var exception = Assert.Throws <FormatException>(act);

            Assert.Contains(invalidNumbers, exception.Message);
        }