public void testCumulativeCounterAfterRollingAndReset3() { MockedClock time = new MockedClock(); RollingNumberEvent type = RollingNumberEvent.SUCCESS; RollingNumber counter = new RollingNumber(time, 20, 2); Assert.Equal(0, counter.GetCumulativeSum(type)); counter.Increment(type); counter.Increment(type); counter.Increment(type); // iterate over 20 buckets on a queue sized for 2 for (int i = 0; i < 20; i++) { try { time.Increment(counter.BucketSizeInMs); } catch (Exception) { // ignore } } // since we are rolling over the buckets it should reset naturally // no increments during the loop, just some before and after counter.Increment(type); counter.Increment(type); // cumulative count should be 5 regardless of buckets rolling Assert.Equal(5, counter.GetCumulativeSum(type)); }
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)); }