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); }
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); }