public void testCumulativeCounterAfterRolling()
{
MockedClock time = new MockedClock();
RollingNumberEvent type = RollingNumberEvent.SUCCESS;
RollingNumber counter = new RollingNumber(time, 20, 2);
Assert.Equal(0, counter.GetCumulativeSum(type));
// iterate over 20 buckets on a queue sized for 2
for (int i = 0; i < 20; i++)
{
// first bucket
counter.Increment(type);
try
{
time.Increment(counter.BucketSizeInMs);
}
catch (Exception)
{
// ignore
}
counter.GetValueOfLatestBucket(type);
Assert.Equal(2, counter.GetValues(type).Count());
}
// cumulative count should be 20 (for the number of loops above) regardless of buckets rolling
Assert.Equal(20, counter.GetCumulativeSum(type));
}