public void RatePerSecond_BasicVerification()
        {
            var counter = new RatePerSecond();

            foreach (var item in FibonacciHelper.ComputeTo(47).Skip(7).Take(7))
            {
                counter.Increment(item);
            }
            Assert.AreEqual(589, counter.Value);
        }
        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);
            }
        }
        public void MovingAverage_BasicVerification()
        {
            var seriesLength  = byte.MaxValue;
            var counter       = new MovingAverage(seriesLength);
            var series        = new Queue <long>();
            var approximation = 0L;

            foreach (var count in FibonacciHelper.ComputeTo(47))
            {
                counter.Increment(count);
                series.Enqueue(count);
                approximation += count;
                if (series.Count > seriesLength)
                {
                    approximation -= series.Dequeue();
                }
                Assert.AreEqual(approximation / seriesLength, counter.Value);
            }
        }
示例#4
0
        public void MedianAverage_BasicVerification()
        {
            var counter = new MedianAverage();

            // verify 'tween' result
            // with initial series: 1,1,2,3,5,8,13,21,34,55,89 !,! 144,233,377,610,987,1597,2584,4181,6765,10946,17711
            foreach (var count in FibonacciHelper.ComputeTo(21))
            {
                counter.Increment(count);
            }
            Assert.AreEqual(72, counter.Value);

            // verify 'non-tween' result
            // with additional series: 34,55,89,144,233,377, !610! ,987,1597,2584,4181,6765,10946,17711
            foreach (var count in FibonacciHelper.ComputeTo(27).Skip(8))
            {
                counter.Increment(count);
            }
            Assert.AreEqual(377, counter.Value);

            // verify performant enough not to timeout test tool
            var fib = FibonacciHelper.ComputeTo(127).ToArray();

            for (int i = 0; i < ushort.MaxValue; i++)
            {
                counter.Increment(fib[i++ % fib.Length]);
            }
            Assert.AreEqual(4807526976, counter.Value);

            // confirm outlier does not pull average
            counter.Reset();
            counter.Increment(1);
            counter.Increment(1);
            counter.Increment(1);
            counter.Increment(int.MaxValue);
            Assert.AreEqual(1, counter.Value);
        }