예제 #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";
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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.");
        }
예제 #8
0
        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.");
        }
예제 #9
0
        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.");
        }