示例#1
1
        public void returns_0_if_empty_string()
        {
            Calculator calc = new Calculator();

            int result = calc.Add("");

            Assert.That(result, Is.EqualTo(0));
        }
示例#2
1
        public void returns_the_same_number_when_you_pass_1_number()
        {
            Calculator calc = new Calculator();

            int result = calc.Add("26");

            Assert.That(result, Is.EqualTo(26));
        }
示例#3
1
        public void AddAnyAmountOfNumbersReturnsCorrectResult(Calculator sut, int count, Generator<int> generator)
        {
            var integers = generator.Take(count+2).ToArray();
            var numbers = string.Join(",", integers);

            var actual = sut.Add(numbers);
            var expected = integers.Sum();

            Assert.Equal(expected, actual);
        }
示例#4
1
        public void AddIgnoresBigNumbers(Calculator sut, int smallSeed, int bigSeed)
        {
            var x = Math.Min(smallSeed, 1000);
            var y = bigSeed + 1000;
            var numbers = string.Join(",", x, y);

            var actual = sut.Add(numbers);

            Assert.Equal(x, actual);
        }
        public void Add_LongDelimeter()
        {
            // arrange
            string str1 = "//[***]\n1***9***3";
            Calculator calc = new Calculator();

            //act
            int expected = 13;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
        public void Add_GreaterThanThousand()
        {
            // arrange
            string str1 = "1\n2002,3\n5";
            Calculator calc = new Calculator();

            //act
            int expected = 9;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
        public void Add_DelimeterOfOtherLength()
        {
            // arrange
            string str1 = "//[**]\n1**5**6**2";
            Calculator calc = new Calculator();

            //act
            int expected = 14;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
示例#8
1
        public void AddLineWithCustomDelimiterStringsReturnsCorrectResult(Calculator sut,
                                                                          string delimiter1,
                                                                          string delimiter2,
                                                                          int x,
                                                                          int y,
                                                                          int z)
        {
            var numbers = string.Format("//[{0}][{1}]\n{2}{0}{3}{1}{4}",
                                        delimiter1,
                                        delimiter2,
                                        x,
                                        y,
                                        z);
            var actual = sut.Add(numbers);
            var expected = x + y + z;

            Assert.Equal(expected, actual);
        }
示例#9
1
 public void AddTwoNumbersReturnsCorrectResult(Calculator sut, int x, int y)
 {
     var numbers = string.Join(",", x, y);
     var actual = sut.Add(numbers);
     Assert.Equal(x + y, actual);
 }
示例#10
1
        public void AddLineWithNegativeNumbersThrowsCorrectException(Calculator sut, int x, int y, int z)
        {
            var numbers = string.Join(",", -x, y, -z);

            var e = Assert.Throws<ArgumentOutOfRangeException>(() => sut.Add(numbers));

            Assert.True(e.Message.StartsWith("Negatives not allowed."));
            Assert.Contains((-x).ToString(), e.Message);
            Assert.Contains((-z).ToString(), e.Message);
        }
示例#11
0
        public void returns_the_sum_of_2_numbers()
        {
            Calculator calc = new Calculator();

            int result = calc.Add("20,15");

            Assert.That(result,Is.EqualTo(35));
        }
        public void Add_ChangeDelimeter()
        {
            // arrange
            string str1 = "//;\n1;2;8;10";
            Calculator calc = new Calculator();

            //act
            int expected = 21;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
        public void Add_NegativeNumber()
        {
            // arrange
            string str1 = "//;\n1;2;-8;10";
            Calculator calc = new Calculator();

            //act
            int expected = 13;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
示例#14
0
        public void AddLineWithCustomDelimiterReturnsCorrrectResult(Calculator sut, 
                                                                    Generator<char> charGenerator, 
                                                                    Generator<int> intGenerator,
                                                                    int count)
        {
            int dummy;
            var delimiter = charGenerator.Where(c => !int.TryParse(c.ToString(), out dummy) &&
                                                c != '-').First();
            var integers = intGenerator.Take(count).ToArray();
            var numbers = string.Format("//{0}\n{1}", delimiter, string.Join(delimiter.ToString(), integers));

            var actual = sut.Add(numbers);
            var expected = integers.Sum();

            Assert.Equal(expected, actual);
        }
示例#15
0
        public void AddReturnZeroWhenSuppliedEmptyOrNullString(string numbers)
        {
            var result = Calculator.Add(numbers);

            Assert.That(result, Is.EqualTo(0));
        }
        public void Add_StringWithNewLine()
        {
            // arrange
            string str1 = "1\n2,3";
            Calculator calc = new Calculator();

            //act
            int expected = 6;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
 static void Main(string[] args)
 {
     Calculator calc = new Calculator();
     Console.WriteLine("sum = {0}", calc.Add("//[**]\n1**1**1**1"));
     Console.ReadLine();
 }
        public void Add_SeveralDelimeters()
        {
            // arrange
            string str1 = "//[*][%]\n1*2%3";
            Calculator calc = new Calculator();

            //act
            int expected = 6;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
        public void Add_SimpleString()
        {
            // arrange
            string str1 = "1,2,6,15";
            Calculator calc = new Calculator();

            //act
            int expected = 24;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
示例#20
0
        public void AddReturnSumWhenSuppliedMultipleNumbersInString(string numbers, int expectedResult)
        {
            var result = Calculator.Add(numbers);

            Assert.That(result, Is.EqualTo(expectedResult));
        }
示例#21
0
 public void AddSingleNumberReturnsCorrectResult(Calculator sut, int expected)
 {
     var numbers = expected.ToString();
     var actual = sut.Add(numbers);
     Assert.Equal(expected, actual);
 }
示例#22
0
        public void AddWhenGivenDefinedDelimiterUsesThatDelimiter(string input, int expectation)
        {
            var result = Calculator.Add(input);

            Assert.That(result, Is.EqualTo(expectation));
        }
示例#23
0
 public void AddWithLineBreakAndCommaAsDelimitersReturnsCorrectResult(Calculator sut, int x, int y, int z)
 {
     var numbers = string.Format("{0}\n{1},{2}", x, y, z);
     var actual = sut.Add(numbers);
     Assert.Equal(x + y + z, actual);
 }
示例#24
0
        private void sum(string value, int equalTo)
        {
            var result = calculator.Add(value);

            Assert.AreEqual(equalTo, result);
        }
        public void EmptyStringReturns0()
        {
            var actual = _calculator.Add(string.Empty);

            Assert.Equal(0, actual);
        }
示例#26
0
 public void AddEmptyReturnsCorrectResult( Calculator sut )
 {
     var numbers = "";
     int actual = sut.Add(numbers);
     Assert.Equal(0, actual);
 }
示例#27
0
        public void AddLineWithCustomDelimiterStringREturnsCorrectResult(Calculator sut,
                                                                         string delimiter,
                                                                         int count,
                                                                         Generator<int> intGenerator)
        {
            var integers = intGenerator.Take(count).ToArray();
            var numbers = string.Format("//[{0}]\n{1}",
                                        delimiter,
                                        string.Join(delimiter, integers));

            var expected = integers.Sum();

            var actual = sut.Add(numbers);

            Assert.Equal(expected, actual);
        }
        public void addingEmptyStringIsZero()
        {
            int actual   = calculator.Add("");
            int expected = 0;

            Assert.AreEqual(expected, actual, "Empty string should be 0");
        }
        public void Add_NullString()
        {
            // arrange
            string str1 = "";
            Calculator calc = new Calculator();

            //act
            int expected = 0;

            // assert
            int actual = calc.Add(str1);
            Assert.AreEqual(expected, actual, "Not correctly");
        }
        public void EmptyStringShouldReturnZeroWhenAdd()
        {
            var calculator = new Calculator();

            Assert.AreEqual(calculator.Add(""), 0);
        }