示例#1
0
        public void UpdateShouldCalculateCorrectAverageTwoValues()
        {
            var host = new AverageCalc();

            host.Update(456);
            host.Update(195);
            Assert.That(host.Average, Is.EqualTo(325.5), "Incorrect Average Calculation for a two updates");
        }
示例#2
0
        public void UpdateShouldCalculateCorrectAverageSingleValue()
        {
            var host = new AverageCalc();

            host.Update(456);
            Assert.That(host.Average, Is.EqualTo(456), "Incorrect Average Calculation for a single update");
        }
示例#3
0
        public void UpdateShouldCalculateCorrectAverageTenValues()
        {
            var host = new AverageCalc();

            for (var i = 1; i <= 10; i++)
            {
                host.Update(i);
            }
            Assert.That(host.Average, Is.EqualTo(5.5), "Incorrect Average Calculation for a two updates");
        }
示例#4
0
        private static void UpdateWithRandoms(AverageCalc host, int numberOfElements, int maxRange)
        {
            double sum = 0;

            for (var i = 0; i < numberOfElements; i++)
            {
                var val = GetRandomNumber(0, maxRange);
                host.Update(val);
                sum += val;
            }
            var actual = sum / numberOfElements;

            Assert.That(host.Average, Is.EqualTo(actual), "Incorrect Average Calculation");
        }