def testCompressedHistograms(self): """Tests compressed histograms inserted into EventAccumulator.""" gen = _EventGenerator(self) acc = ea.EventAccumulator(gen, compression_bps=(0, 2500, 5000, 7500, 10000)) gen.AddHistogram( "hst1", wall_time=1, step=10, hmin=1, hmax=2, hnum=3, hsum=4, hsum_squares=5, hbucket_limit=[1, 2, 3], hbucket=[0, 3, 0], ) gen.AddHistogram( "hst2", wall_time=2, step=12, hmin=-2, hmax=3, hnum=4, hsum=5, hsum_squares=6, hbucket_limit=[2, 3, 4], hbucket=[1, 3, 0], ) acc.Reload() # Create the expected values after compressing hst1 expected_vals1 = [ compressor.CompressedHistogramValue(bp, val) for bp, val in [ (0, 1.0), (2500, 1.25), (5000, 1.5), (7500, 1.75), (10000, 2.0), ] ] expected_cmphst1 = ea.CompressedHistogramEvent( wall_time=1, step=10, compressed_histogram_values=expected_vals1) self.assertEqual(acc.CompressedHistograms("hst1"), [expected_cmphst1]) # Create the expected values after compressing hst2 expected_vals2 = [ compressor.CompressedHistogramValue(bp, val) for bp, val in [ (0, -2), (2500, 2), (5000, 2 + 1 / 3), (7500, 2 + 2 / 3), (10000, 3), ] ] expected_cmphst2 = ea.CompressedHistogramEvent( wall_time=2, step=12, compressed_histogram_values=expected_vals2) self.assertEqual(acc.CompressedHistograms("hst2"), [expected_cmphst2])
def _make_expected_value(*values): return [compressor.CompressedHistogramValue(bp, val) for bp, val in values]