public void CompositeCounter_BasicVerification()
        {
            var sumTotal   = new SumTotal();
            var ratePerSec = new RatePerSecond();
            var meanPerSec =
                new MeanAverage(
                    ratePerSec.Denominator);
            var medianPerSec  = new MedianAverage();
            var movingAverage = new MovingAverage(7);
            var composite     = new CompositeCounter()
                                .AddCounter(sumTotal)
                                .AddCounter(ratePerSec)
                                .AddCounter(meanPerSec)
                                .AddCounter(medianPerSec)
                                .AddCounter(movingAverage);

            var expectedSumTotal = 0L;
            var elapsedTime      = new ElapsedTime(ElapsedTime.ElapsedTimeUnitType.Milliseconds);

            while (elapsedTime.Value <= 500)
            {
                Thread.Sleep(50);
                expectedSumTotal++;
                composite.Increment(1);
            }
            Thread.Sleep(500);
            Assert.AreEqual(expectedSumTotal, sumTotal.Value);
            Assert.AreEqual(10 /* == 1 per 50ms for 500ms */, ratePerSec.Value);
            Assert.AreEqual(sumTotal.Value, composite.Value);
        }
Esempio n. 2
0
        public void MeanAverage_BasicVerification()
        {
            var counter             = new MeanAverage();
            var expectedCount       = 0L;
            var expectedTotalCounts = 0L;

            foreach (var count in FibonacciHelper.ComputeTo(47))
            {
                counter.Increment(count);
                (counter.Denominator as ISupportsIncrement <long>)?.Increment();
                expectedCount       += count;
                expectedTotalCounts += 1;
                Assert.AreEqual(expectedCount / expectedTotalCounts, counter.Value);
            }
        }