Exemplo n.º 1
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));
        }
Exemplo n.º 2
1
        public void returns_0_if_empty_string()
        {
            Calculator calc = new Calculator();

            int result = calc.Add("");

            Assert.That(result, Is.EqualTo(0));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
        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");
        }
        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_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");
        }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
1
 public void TestInitialize()
 {
     calculator = new Calculator();
 }
 public void BeforeScenario()
 {
     _calc = new Calculator();
 }
 public void setup()
 {
     calculator = new Calculator();
 }
Exemplo n.º 14
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));
        }
Exemplo n.º 15
0
        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");
        }
Exemplo n.º 16
0
        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");
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
 public void SetUp()
 {
     _calculationAggregatorMock = new Mock<ICalculationAggregator>();
     _calculationAggregatorMock.Setup(c => c.PostResults(It.IsAny<int>())).Returns(true);
     _sut = new Calculator(_calculationAggregatorMock.Object);
 }
 public StringCalculatorTest1()
 {
     _calculator = new Calculator();
 }
 public void SetUp()
 {
     calc = new Calculator();
 }
Exemplo n.º 22
0
 static void Main(string[] args)
 {
     Calculator calc = new Calculator();
     Console.WriteLine("sum = {0}", calc.Add("//[**]\n1**1**1**1"));
     Console.ReadLine();
 }
Exemplo n.º 23
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");
        }
Exemplo n.º 24
0
        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");
        }
Exemplo n.º 25
0
        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");
        }
Exemplo n.º 26
0
 public void AddEmptyReturnsCorrectResult( Calculator sut )
 {
     var numbers = "";
     int actual = sut.Add(numbers);
     Assert.Equal(0, actual);
 }
Exemplo n.º 27
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");
        }
Exemplo n.º 28
0
 public CalculatorTests()
 {
     parser = Substitute.For<StringParser>();
     calc = new Calculator(parser);
 }
Exemplo n.º 29
0
 public void Setup()
 {
     _calculator = new Calculator();
 }
Exemplo n.º 30
0
 public void AddSingleNumberReturnsCorrectResult(Calculator sut, int expected)
 {
     var numbers = expected.ToString();
     var actual = sut.Add(numbers);
     Assert.Equal(expected, actual);
 }
        public void EmptyStringShouldReturnZeroWhenAdd()
        {
            var calculator = new Calculator();

            Assert.AreEqual(calculator.Add(""), 0);
        }
Exemplo n.º 32
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);
 }