| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 |
| 5 import json | 5 import json |
| 6 import math | 6 import math |
| 7 import os | 7 import os |
| 8 import random | 8 import random |
| 9 import tempfile | 9 import tempfile |
| 10 import unittest | 10 import unittest |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 'type': 'list_of_scalar_values', | 124 'type': 'list_of_scalar_values', |
| 125 'values': values} | 125 'values': values} |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 if keys: | 129 if keys: |
| 130 grouping_keys = dict(enumerate(keys)) | 130 grouping_keys = dict(enumerate(keys)) |
| 131 charts['charts'][chart_name][trace_name]['grouping_keys'] = grouping_keys | 131 charts['charts'][chart_name][trace_name]['grouping_keys'] = grouping_keys |
| 132 return self.NewJsonTempfile(charts) | 132 return self.NewJsonTempfile(charts) |
| 133 | 133 |
| 134 def testCompareClearRegression(self): | 134 def MakeChartJSONScalar(self, metric, seed, mu, sigma, keys=None): |
| 135 """Creates a normally distributed pseudo-random sample. (continuous). |
| 136 |
| 137 This function creates a deterministic pseudo-random sample and stores it in |
| 138 chartjson format to facilitate the testing of the sample comparison logic. |
| 139 |
| 140 Args: |
| 141 metric (str pair): name of chart, name of the trace. |
| 142 seed (hashable obj): to make the sequences deterministic we seed the RNG. |
| 143 mu (float): desired mean for the sample |
| 144 sigma (float): desired standard deviation for the sample |
| 145 """ |
| 146 chart_name, trace_name = metric |
| 147 random.seed(seed) |
| 148 charts = { |
| 149 'charts': { |
| 150 chart_name: { |
| 151 trace_name: { |
| 152 'type': 'scalar', |
| 153 'value': random.gauss(mu, sigma)} |
| 154 } |
| 155 } |
| 156 } |
| 157 if keys: |
| 158 grouping_keys = dict(enumerate(keys)) |
| 159 charts['charts'][chart_name][trace_name]['grouping_keys'] = grouping_keys |
| 160 return self.NewJsonTempfile(charts) |
| 161 |
| 162 def testCompareClearRegressionListOfScalars(self): |
| 135 metric = ('some_chart', 'some_trace') | 163 metric = ('some_chart', 'some_trace') |
| 136 lower_values = ','.join([self.MakeChart(metric=metric, seed='lower', | 164 lower_values = ','.join([self.MakeChart(metric=metric, seed='lower', |
| 137 mu=10, sigma=1, n=10)]) | 165 mu=10, sigma=1, n=10)]) |
| 138 higher_values = ','.join([self.MakeChart(metric=metric, seed='higher', | 166 higher_values = ','.join([self.MakeChart(metric=metric, seed='higher', |
| 139 mu=20, sigma=2, n=10)]) | 167 mu=20, sigma=2, n=10)]) |
| 140 result = json.loads(compare_samples.CompareSamples( | 168 result = json.loads(compare_samples.CompareSamples( |
| 141 lower_values, higher_values, '/'.join(metric)).stdout) | 169 lower_values, higher_values, '/'.join(metric)).stdout) |
| 142 self.assertEqual(result['result']['significance'], REJECT) | 170 self.assertEqual(result['result']['significance'], REJECT) |
| 143 | 171 |
| 172 def testCompareClearRegressionScalars(self): |
| 173 metric = ('some_chart', 'some_trace') |
| 174 lower_values = ','.join( |
| 175 [self.MakeChartJSONScalar( |
| 176 metric=metric, seed='lower', mu=10, sigma=1) for _ in range(10)]) |
| 177 higher_values = ','.join( |
| 178 [self.MakeChartJSONScalar( |
| 179 metric=metric, seed='higher', mu=20, sigma=2) for _ in range(10)]) |
| 180 result = json.loads(compare_samples.CompareSamples( |
| 181 lower_values, higher_values, '/'.join(metric)).stdout) |
| 182 self.assertEqual(result['result']['significance'], REJECT) |
| 183 |
| 144 def testCompareUnlikelyRegressionWithMultipleRuns(self): | 184 def testCompareUnlikelyRegressionWithMultipleRuns(self): |
| 145 metric = ('some_chart', 'some_trace') | 185 metric = ('some_chart', 'some_trace') |
| 146 lower_values = ','.join([ | 186 lower_values = ','.join([ |
| 147 self.MakeChart( | 187 self.MakeChart( |
| 148 metric=metric, seed='lower%d' % i, mu=10, sigma=1, n=5) | 188 metric=metric, seed='lower%d' % i, mu=10, sigma=1, n=5) |
| 149 for i in range(4)]) | 189 for i in range(4)]) |
| 150 higher_values = ','.join([ | 190 higher_values = ','.join([ |
| 151 self.MakeChart( | 191 self.MakeChart( |
| 152 metric=metric, seed='higher%d' % i, mu=10.01, sigma=0.95, n=5) | 192 metric=metric, seed='higher%d' % i, mu=10.01, sigma=0.95, n=5) |
| 153 for i in range(4)]) | 193 for i in range(4)]) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 keys = 'blank', 'about' | 278 keys = 'blank', 'about' |
| 239 lower_values = ','.join([self.MakeChart(metric=metric, seed='lower', | 279 lower_values = ','.join([self.MakeChart(metric=metric, seed='lower', |
| 240 mu=10, sigma=1, n=10, keys=keys)]) | 280 mu=10, sigma=1, n=10, keys=keys)]) |
| 241 higher_values = ','.join([self.MakeChart(metric=metric, seed='higher', | 281 higher_values = ','.join([self.MakeChart(metric=metric, seed='higher', |
| 242 mu=20, sigma=2, n=10, keys=keys)]) | 282 mu=20, sigma=2, n=10, keys=keys)]) |
| 243 result = compare_samples.CompareSamples( | 283 result = compare_samples.CompareSamples( |
| 244 lower_values, higher_values, full_metric_name).stdout | 284 lower_values, higher_values, full_metric_name).stdout |
| 245 print result | 285 print result |
| 246 result = json.loads(result) | 286 result = json.loads(result) |
| 247 self.assertEqual(result['result']['significance'], REJECT) | 287 self.assertEqual(result['result']['significance'], REJECT) |
| OLD | NEW |