Esempio n. 1
0
        private void sumOfMultiplesButton_Click(object sender, EventArgs e)
        {
            int input = 0;

            if (int.TryParse(inputRichTextBox.Text, out input))
            {
                this.ResultText = _sumOfMultiplesCalcultor.SumOfMultiplesOfThreeAndFive(input).ToString();
            }
            else
            {
                this.ErrorText = "Given input is not a number or not withing given boundaries between 4 and 2147483647";
            }
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithLimitEqualsToIntegerMaxNumberTest()
        {
            // arrange
            int limit = int.MaxValue;
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();
            decimal expected = 1076060070465310994m;
            // (new SumOfMultiplesHelper()).SumOfMultiplesOfThreeAndFive(limit);

            // act
            decimal actual = sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithLargeLimitNumber()
        {
            // arrange
            int limit = 1000000000;
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();
            decimal expected = 233333333166666668m;
            // (new SumOfMultiplesHelper()).SumOfMultiplesOfThreeAndFive(limit);

            // act
            decimal actual = sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithLimitEqualsToSixteenTest()
        {
            // arrange
            int limit = 16;
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();
            decimal expected = 60m;
            // (new SumOfMultiplesHelper()).SumOfMultiplesOfThreeAndFive(limit);

            // act
            decimal actual = sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithLimitEqualsMinimumNumberContainsThreeAndFiveTest()
        {
            // arrange
            int limit = 6;
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();
            decimal expected = 8m;
            // (new SumOfMultiplesHelper()).SumOfMultiplesOfThreeAndFive(limit);

            // act
            decimal actual = sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithRandomLimitNumberGreaterThan100Million()
        {
            // arrange
            Random random = new Random();
            int    limit  = random.Next(100000000, int.MaxValue);
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();
            SumOfMultiplesHelper  myCalculator   = new SumOfMultiplesHelper();
            decimal expected = myCalculator.SumOfMultiplesOfThreeAndFive(limit);

            // act
            decimal actual = sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithLimitEqualsToZeroTest()
        {
            // arrange
            int limit = 0;
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();

            // act && assert
            try
            {
                sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);
            }
            catch (LimitIsNegativeOrZeroException)
            {
                return;
            }
            catch
            {
                Assert.Fail("LimitIsNegativeOrZeroException was not thrown.");
            }
            Assert.Fail("No exception was thrown.");
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithLimitEqualsToThreeTest()
        {
            int limit = 3;
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();

            // act && assert
            try
            {
                sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);
            }
            catch (LimitIsLessThanNumberException ex)
            {
                //AssertFailedException
                StringAssert.Contains(ex.Message, "Given limit number is less than or equal 3");
                return;
            }
            catch
            {
                Assert.Fail("LimitIsLessThanNumberException was not thrown.");
            }
            Assert.Fail("No exception was thrown.");
        }
        public void GetSumOfMultiplesOfThreeAndFiveWithNegativeLimitTest()
        {
            // arrange
            Random random = new Random();
            int    limit  = random.Next(int.MinValue, -1);
            SumOfMultiplesOf3And5 sumOfMultiples = new SumOfMultiplesOf3And5();

            // act && assert
            try
            {
                sumOfMultiples.SumOfMultiplesOfThreeAndFive(limit);
            }
            catch (LimitIsNegativeOrZeroException)
            {
                return;
            }
            catch
            {
                Assert.Fail("LimitIsNegativeOrZeroException was not thrown.");
            }
            Assert.Fail("No exception was thrown.");
        }