Exemplo n.º 1
0
                public void ShouldReturnInitialTerm()
                {
                    var     progression = new ArithmeticSequence(42, 314);
                    decimal firstTerm   = progression.GetSum(1);

                    firstTerm.Should().Be(42);
                }
Exemplo n.º 2
0
                public void ShouldReturnCorrectTerm()
                {
                    var     progression = new ArithmeticSequence(1, 1);
                    decimal term42      = progression.GetTerm(42);

                    term42.Should().Be(42);
                }
        public void FunctionalLifeSpanTest_ShouldProduceDesiredResults()
        {
            // Arrange.
            var firstTerm        = 3d;
            var commonDifference = -7d;

            // Act.
            var target = new ArithmeticSequence(firstTerm, commonDifference);

            // Assert.
            target.CalculatedTermCount.Should().Be(1);
            target[0].Should().Be(firstTerm);
            target[1].Should().Be(-4);
            target[2].Should().Be(-11);
            target[3].Should().Be(-18);
            target[4].Should().Be(-25);
            target.CalculatedTermCount.Should().Be(5);
            target[5].Should().Be(-32);
            target[6].Should().Be(-39);
            target[7].Should().Be(-46);
            target[8].Should().Be(-53);
            target[9].Should().Be(-60);
            target.CalculatedTermCount.Should().Be(10);
            target.Reset();
            target.CalculatedTermCount.Should().Be(1);
            target[0].Should().Be(firstTerm);
            target[1].Should().Be(-4);
            target[2].Should().Be(-11);
        }
Exemplo n.º 4
0
        public long Solve()
        {
            var mult3  = ArithmeticSequence.MultipleSequence(3);
            var mult5  = ArithmeticSequence.MultipleSequence(5);
            var mult15 = ArithmeticSequence.MultipleSequence(3 * 5);

            return(mult3.GetTermsBellow(1000).Sum() + mult5.GetTermsBellow(1000).Sum() - mult15.GetTermsBellow(1000).Sum());
        }
Exemplo n.º 5
0
        public void ArithmeticSequence()
        {
            var a = new ArithmeticSequence
            {
                InitialTerm      = 2,
                CommonDifference = 4
            };

            Assert.AreEqual(18, a.NTerm(5));
        }
Exemplo n.º 6
0
        public object GetResult()
        {
            const int termCount = 100;

            long sumOfSquares = new QuadraticSequence(1, 0, 0).GetSum(termCount);
            long squareOfSum  = new ArithmeticSequence(1, 1).GetSum(termCount).Square();

            long result = squareOfSum - sumOfSquares;

            return(result);
        }
Exemplo n.º 7
0
        public object GetResult()
        {
            const int max = 1000;

            const int threesCount   = (max - 1) / 3;
            const int fivesCount    = (max - 1) / 5;
            const int fifteensCount = (max - 1) / (3 * 5);

            var threes   = new ArithmeticSequence(3, 3);
            var fives    = new ArithmeticSequence(5, 5);
            var fifteens = new ArithmeticSequence(15, 15);

            return((int)(threes.GetSum(threesCount) + fives.GetSum(fivesCount) - fifteens.GetSum(fifteensCount)));
        }
        public void Constructor_ShouldRaiseArgumentOutOfRangeException_ForZeroCommonDifferenceArgument()
        {
            // Arrange.
            var firstTerm        = 3d;
            var commonDifference = 0d;

            // Act.
            var action = new Action(() =>
            {
                var target = new ArithmeticSequence(firstTerm, commonDifference);
            });

            // Assert.
            action.Should().Throw <ArgumentOutOfRangeException>();
        }
Exemplo n.º 9
0
 public int Test(int first, int n, int c) => ArithmeticSequence.Nthterm(first, n, c);
Exemplo n.º 10
0
 public void CalculateTest_SumOutOfRange_ThrowOverflowException()
 {
     Assert.Throws <OverflowException>(() => ArithmeticSequence.Calculate(int.MaxValue, 1, 2));
 }