| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 |
| 4 import json | 5 import json |
| 5 import unittest | 6 import unittest |
| 6 | 7 |
| 7 from metrics import histogram_util | 8 from metrics import histogram |
| 8 | 9 |
| 9 class TestHistogram(unittest.TestCase): | 10 class TestHistogram(unittest.TestCase): |
| 10 def testSubtractHistogram(self): | 11 def testSubtractHistogram(self): |
| 11 baseline_histogram = """{"count": 3, "buckets": [ | 12 baseline_histogram = """{"count": 3, "buckets": [ |
| 12 {"low": 1, "high": 2, "count": 1}, | 13 {"low": 1, "high": 2, "count": 1}, |
| 13 {"low": 2, "high": 3, "count": 2}]}""" | 14 {"low": 2, "high": 3, "count": 2}]}""" |
| 14 | 15 |
| 15 histogram = """{"count": 14, "buckets": [ | 16 later_histogram = """{"count": 14, "buckets": [ |
| 16 {"low": 1, "high": 2, "count": 1}, | 17 {"low": 1, "high": 2, "count": 1}, |
| 17 {"low": 2, "high": 3, "count": 3}, | 18 {"low": 2, "high": 3, "count": 3}, |
| 18 {"low": 3, "high": 4, "count": 10}]}""" | 19 {"low": 3, "high": 4, "count": 10}]}""" |
| 19 | 20 |
| 20 new_histogram = json.loads( | 21 new_histogram = json.loads( |
| 21 histogram_util.SubtractHistogram(histogram, baseline_histogram)) | 22 histogram.SubtractHistogram(later_histogram, baseline_histogram)) |
| 22 new_buckets = dict() | 23 new_buckets = dict() |
| 23 for b in new_histogram['buckets']: | 24 for b in new_histogram['buckets']: |
| 24 new_buckets[b['low']] = b['count'] | 25 new_buckets[b['low']] = b['count'] |
| 25 self.assertFalse(1 in new_buckets) | 26 self.assertFalse(1 in new_buckets) |
| 26 self.assertEquals(1, new_buckets[2]) | 27 self.assertEquals(1, new_buckets[2]) |
| 27 self.assertEquals(10, new_buckets[3]) | 28 self.assertEquals(10, new_buckets[3]) |
| OLD | NEW |