def testArithmeticMean(self): a = accumulators('ArithmeticMean') self.assertIsNone(a.result()) a(4) self.assertEqual(4,a.result()) a(2) a(-3) self.assertEqual(1,a.result()) a.reset() self.assertIsNone(a.result())
def __init__(self, block_size, channel_config, output_location): self.seen_rows = 0 #Accumulators bypassed if we are just doing single values if block_size == 1: channel_config = copy.deepcopy(channel_config) channel_config['accumulators'] = ['LastVal'] self.block_size = block_size self.accumulators = [accumulators(accum) for accum in channel_config['accumulators']] self.encoder = encoders(channel_config['encoder']) self.encoder.start(output_location, channel_config, block_size)
def testGeometricMean(self): a = accumulators('GeometricMean') self.assertIsNone(a.result()) a(4) self.assertEqual(4,a.result()) a(2) self.assertRaises(ValueError, lambda: a(-3)) self.assertEqual(2.8284271247461903,a.result()) a.reset() self.assertIsNone(a.result())
def testLastVal(self): a = accumulators('LastVal') self.assertIsNone(a.result()) a(5) self.assertEqual(5,a.result()) a(4) a(3) self.assertEqual(3,a.result()) a.reset() self.assertIsNone(a.result())
def testMax(self): a = accumulators('Max') self.assertEqual(float('-inf'),a.result()) a(5) self.assertEqual(5,a.result()) a(4) a(3) a(6) self.assertEqual(6,a.result()) a.reset() self.assertEqual(float('-inf'),a.result())
def testMin(self): a = accumulators('Min') self.assertEqual(float('inf'),a.result()) a(5) self.assertEqual(5,a.result()) a(4) a(3) self.assertEqual(3,a.result()) a.reset() self.assertEqual(float('inf'),a.result())
def testMedian(self): a = accumulators('Median') self.assertIsNone(a.result()) a(4) self.assertEqual(4,a.result()) a(2) a(-3) self.assertEqual(2,a.result()) a(-5) self.assertEqual(-0.5,a.result()) a.reset() self.assertIsNone(a.result())
def testPercentile(self): a = accumulators({'Percentile':{'percent':0.25}}) self.assertIsNone(a.result()) a(4) self.assertEqual(4,a.result()) a(2) a(0) self.assertEqual(1,a.result()) a(-5) a(-1) self.assertEqual(-1,a.result()) a.reset() self.assertIsNone(a.result())
def test_dynamic_load(self): self.assertEqual(type(accumulators('LastVal')), accumulators.LastVal) a = accumulators({'Median':{'test':'foobar'}}) self.assertEqual(type(a), accumulators.Median) self.assertEqual(a.test, 'foobar')