예제 #1
0
        public void Add_GivenANumberGreaterThan1000_ShouldNotAdd(string input, int expected)
        {
            //Arrange
            var sut = new StringCalculator();

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

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

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

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

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

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

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #5
0
        public void Add_GivenMultipleNumbers_ShouldReturnTheSum(string input, int expected)
        {
            //Arrange
            StringCalculator sut = CreateStringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void Add_GivendANullOrWhitespace_ShouldReturn0(string input)
        {
            //Arrange
            var expected = 0;
            var sut      = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #7
0
        public void Add_TwoNumbersSplitByCommaInString_ReturnsSumOfNumbers()
        {
            //Arrange
            var numberOne = random.Next(1, 10);
            var numberTwo = random.Next(1, 10);

            //Act
            var addResult = StringCalculator.Add(numberOne + "," + numberTwo);

            //Assert
            Assert.That(addResult, Is.EqualTo(numberOne + numberTwo));
        }
        public void Calculate_NonNumericValue_ReturnsZero()
        {
            //e.g. "1,Elephant,6" = 0
            // Arrange
            var calculator = new StringCalculator();

            // Action
            var result = calculator.Add("1,Elephant,6", ',');

            // Assert
            Assert.Equal(result, 0);
        }
        public void Calculate_NumbersLargerThan100_IgnoresOver100sInSum()
        {
            //e.g. "1,2,100" = 3
            // Arrange
            var calculator = new StringCalculator();

            // Action
            var result = calculator.Add("1,2,100", ',');

            // Assert
            Assert.Equal(result, 3);
        }
        public void Calculate_CanUseAlternativeDelimiters_ReturnsSum()
        {
            //e.g. "1|2|3" = 6
            // Arrange
            var calculator = new StringCalculator();

            // Action
            var result = calculator.Add("1|2|3", '|');

            // Assert
            Assert.Equal(result, 6);
        }
        public void Calculate_FiveNumbers_ReturnsSum()
        {
            //e.g. "1,2,3,4,5" = 15
            // Arrange
            var calculator = new StringCalculator();

            // Action
            var result = calculator.Add("1,2,3,4,5", ',');

            // Assert
            Assert.Equal(result, 15);
        }
        public void Calculate_TwoNumbers_ReturnsSum()
        {
            //e.g. "1,2" = 3
            // Arrange
            var calculator = new StringCalculator();

            // Action
            var result = calculator.Add("1,2", ',');

            // Assert
            Assert.Equal(result, 3);
        }
        public void Add_GivenAnEmptyString_ShouldReturn0(string input)
        {
            //Arrange
            var expected         = 0;
            StringCalculator sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #14
0
        public void Add_GivenMultipleNegativeNumbers_ShouldThrowAnException()
        {
            //Arrange
            var input            = "-1, -2, -3";
            var expected         = "negatives not allowed: -1 -2 -3";
            StringCalculator sut = CreateStringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual.Message);
        }
        public void Add_GivenNumbers100And256_ShouldReturnSumOfNumbers()
        {
            //Arrange
            string           input            = "100,256";
            int              expected         = 356;
            StringCalculator stringCalculator = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void Add_GivenEmptyString_ShouldReturn0()
        {
            //Arrange
            string           input            = "";
            int              expected         = 0;
            StringCalculator stringCalculator = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, result);
        }
예제 #17
0
        public void Add_GivenANumberOver1000_ShouldNotAdd()
        {
            //Arrange
            var input    = "1,1001";
            var expected = 1;
            var sut      = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void Add_GivenSemiColonDelimiter_ShouldReturnSum()
        {
            //Arrange
            var input            = "//;\n1;2";
            var expected         = 3;
            StringCalculator sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void Add_GivenNewLineDelimiter_ShouldReturnSum()
        {
            //Arrange
            var input            = "1\n2,3";
            var expected         = 6;
            StringCalculator sut = new StringCalculator();

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

            //Assert
            Assert.AreEqual(expected, actual);
        }
예제 #20
0
        public void Add_RandomAmountOfNumbersSplitWithComma_ReturnsSumOfAllNumbers()
        {
            //Arrange
            int        totaal  = 0;
            List <int> numbers = new List <int>();

            for (int i = 0; i < random.Next(2, 10); i++)
            {
                numbers.Add(random.Next(1, 10));
            }
            numbers.ForEach(n => totaal += n);

            StringBuilder numbersString = new StringBuilder();

            numbers.ForEach(n => numbersString.Append(n + ","));


            //Act
            var addResult = StringCalculator.Add(numbersString.ToString().TrimEnd(','));

            //Assert
            Assert.That(addResult, Is.EqualTo(totaal));
        }
        public void Add_Returns_0_For_Empty_String()
        {
            var result = underTest.Add("");

            Assert.Equal(0, result);
        }
예제 #22
0
        public void Add_DelimeterOfAnyLengthReturnSum(string input, string expected)
        {
            string output = StringCalculator.Add(input);

            Assert.AreEqual(expected, output);
        }
예제 #23
0
        public void Add_IgnoreNumbersBiggerThanOneThousand(string input, string expected)
        {
            var output = StringCalculator.Add(input);

            Assert.AreEqual(expected, output);
        }
예제 #24
0
        public void Add_ThrowExceptionWhenNegativeNumberIsInserted(string input, string negNumber)
        {
            var exception = Assert.Throws <ArgumentException>(() => StringCalculator.Add(input));

            Assert.That(exception.Message, Is.EqualTo(string.Format($"string contains {negNumber}. Negative not allowed")));
        }
예제 #25
0
        public void Add_WhenDifferentDelimeterReturnSum(string input, string expected)
        {
            string output = StringCalculator.Add(input);

            Assert.AreEqual(expected, output);
        }
예제 #26
0
        public void Add_WhenNewLineBetweenNumReturnSum(string input, string expected)
        {
            string output = StringCalculator.Add(input);

            Assert.AreEqual(expected, output);
        }
예제 #27
0
        public void Add_WheTwoNumbersReturnSum(string input, string expected)
        {
            string output = StringCalculator.Add(input);

            Assert.AreEqual(expected, output);
        }
예제 #28
0
        public void Add_WhenOneNumberReturnNumber(string input)
        {
            string output = StringCalculator.Add(input);

            Assert.AreEqual(input, output);
        }
예제 #29
0
        public void ReturnSum_WhenAdding_GivenManyNumbersAndNewLineWithSlashes(string manyNumbers, int expectedSum)
        {
            var sum = StringCalculator.Add(manyNumbers);

            sum.Should().Be(expectedSum);
        }
예제 #30
0
        public void ReturnException_WhenAdding_GivenANegativeNumber(string manyNumbers, string expectedErrorMessage)
        {
            Action act = () => StringCalculator.Add(manyNumbers);

            act.ShouldThrow <InvalidOperationException>().WithMessage(expectedErrorMessage);
        }