예제 #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));
        }
예제 #2
1
        public void returns_0_if_empty_string()
        {
            Calculator calc = new Calculator();

            int result = calc.Add("");

            Assert.That(result, Is.EqualTo(0));
        }
예제 #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);
        }
예제 #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");
        }
예제 #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);
 }
예제 #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);
        }
예제 #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);
        }
예제 #11
1
 public void TestInitialize()
 {
     calculator = new Calculator();
 }
 public void BeforeScenario()
 {
     _calc = new Calculator();
 }
 public void setup()
 {
     calculator = new Calculator();
 }
예제 #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));
        }
예제 #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");
        }
예제 #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");
        }
예제 #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);
        }
예제 #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);
        }
예제 #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();
 }
예제 #22
0
 static void Main(string[] args)
 {
     Calculator calc = new Calculator();
     Console.WriteLine("sum = {0}", calc.Add("//[**]\n1**1**1**1"));
     Console.ReadLine();
 }
예제 #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");
        }
예제 #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");
        }
예제 #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");
        }
예제 #26
0
 public void AddEmptyReturnsCorrectResult( Calculator sut )
 {
     var numbers = "";
     int actual = sut.Add(numbers);
     Assert.Equal(0, actual);
 }
예제 #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");
        }
예제 #28
0
 public CalculatorTests()
 {
     parser = Substitute.For<StringParser>();
     calc = new Calculator(parser);
 }
예제 #29
0
 public void Setup()
 {
     _calculator = new Calculator();
 }
예제 #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);
        }
예제 #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);
 }