def test_100_out_of_10_elements(self): population = [i for i in range(0, 10)] sample = ExponentiallyDecayingSample(100, 0.99) for i in population: sample.update(i) self.assertEqual(sample.size(), 10) self.assertEqual(len(sample.get_values()), 10, 'Should have 10 elements') self.assertEqual( len(set(sample.get_values()).difference(set(population))), 0, 'Should only have elements from the population')
def test_ewma_overflow(self): """Long pauses on metric input should not overflow weight.""" _time = [10000] def wtime(): return _time[0] sample = ExponentiallyDecayingSample(100, 0.99, wall_time=wtime) for i in xrange(100): sample.update(random.normalvariate(0, 10)) _time[0] += 10000 self.assertEqual(sample.size(), 100) self.assertEqual(len(sample.get_values()), 100, 'Should have 100 elements')
def test_ewma_sample_load(self): _time = [10000] def wtime(): return _time[0] sample = ExponentiallyDecayingSample(100, 0.99, wall_time=wtime) sample.RESCALE_THRESHOLD = 100 sample.clear() for i in xrange(10000000): sample.update(random.normalvariate(0, 10)) _time[0] += 1 self.assertEqual(sample.size(), 100) self.assertEqual(len(sample.get_values()), 100, 'Should have 100 elements')