Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Unified Diff: tracing/tracing/metrics/compare_samples_unittest.py

Issue 2528083002: Bisect - Fix compare_samples to read scalar values. (Closed)
Patch Set: Added test. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tracing/tracing/metrics/compare_samples_cmdline.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tracing/tracing/metrics/compare_samples_unittest.py
diff --git a/tracing/tracing/metrics/compare_samples_unittest.py b/tracing/tracing/metrics/compare_samples_unittest.py
index 225d1434683c507dbfd20f9aac901b9548260173..222637d6cde9786dff3d52e01334138f260af589 100644
--- a/tracing/tracing/metrics/compare_samples_unittest.py
+++ b/tracing/tracing/metrics/compare_samples_unittest.py
@@ -131,7 +131,35 @@ class CompareSamplesUnittest(unittest.TestCase):
charts['charts'][chart_name][trace_name]['grouping_keys'] = grouping_keys
return self.NewJsonTempfile(charts)
- def testCompareClearRegression(self):
+ def MakeChartJSONScalar(self, metric, seed, mu, sigma, keys=None):
+ """Creates a normally distributed pseudo-random sample. (continuous).
+
+ This function creates a deterministic pseudo-random sample and stores it in
+ chartjson format to facilitate the testing of the sample comparison logic.
+
+ Args:
+ metric (str pair): name of chart, name of the trace.
+ seed (hashable obj): to make the sequences deterministic we seed the RNG.
+ mu (float): desired mean for the sample
+ sigma (float): desired standard deviation for the sample
+ """
+ chart_name, trace_name = metric
+ random.seed(seed)
+ charts = {
+ 'charts': {
+ chart_name: {
+ trace_name: {
+ 'type': 'scalar',
+ 'value': random.gauss(mu, sigma)}
+ }
+ }
+ }
+ if keys:
+ grouping_keys = dict(enumerate(keys))
+ charts['charts'][chart_name][trace_name]['grouping_keys'] = grouping_keys
+ return self.NewJsonTempfile(charts)
+
+ def testCompareClearRegressionListOfScalars(self):
metric = ('some_chart', 'some_trace')
lower_values = ','.join([self.MakeChart(metric=metric, seed='lower',
mu=10, sigma=1, n=10)])
@@ -141,6 +169,18 @@ class CompareSamplesUnittest(unittest.TestCase):
lower_values, higher_values, '/'.join(metric)).stdout)
self.assertEqual(result['result']['significance'], REJECT)
+ def testCompareClearRegressionScalars(self):
+ metric = ('some_chart', 'some_trace')
+ lower_values = ','.join(
+ [self.MakeChartJSONScalar(
+ metric=metric, seed='lower', mu=10, sigma=1) for _ in range(10)])
+ higher_values = ','.join(
+ [self.MakeChartJSONScalar(
+ metric=metric, seed='higher', mu=20, sigma=2) for _ in range(10)])
+ result = json.loads(compare_samples.CompareSamples(
+ lower_values, higher_values, '/'.join(metric)).stdout)
+ self.assertEqual(result['result']['significance'], REJECT)
+
def testCompareUnlikelyRegressionWithMultipleRuns(self):
metric = ('some_chart', 'some_trace')
lower_values = ','.join([
« no previous file with comments | « tracing/tracing/metrics/compare_samples_cmdline.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698