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

Unified Diff: tools/bisect-perf-regression_test.py

Issue 241273002: Change "percentage change" function and add comments/test for it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months 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
« tools/bisect-perf-regression.py ('K') | « tools/bisect-perf-regression.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/bisect-perf-regression_test.py
diff --git a/tools/bisect-perf-regression_test.py b/tools/bisect-perf-regression_test.py
index 44d526edfd4845b672388baa24daa1cae50cda41..976a3b765890bca1b494e3db9b85c6c51f2d7989 100644
--- a/tools/bisect-perf-regression_test.py
+++ b/tools/bisect-perf-regression_test.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import math
import unittest
# Special import necessary because filename contains dash characters.
@@ -75,5 +76,26 @@ class BisectPerfRegressionTest(unittest.TestCase):
self.assertEqual(
100, bisect_perf_module.CalculateConfidence(bad_values, good_values))
+ def testCalculateRelativeChange(self):
+ """Tests the common cases for calculating relative change."""
+ # The change is relative to the first value, regardless of which is bigger.
+ self.assertEqual(0.5, bisect_perf_module.CalculateRelativeChange(1.0, 1.5))
+ self.assertEqual(0.5, bisect_perf_module.CalculateRelativeChange(2.0, 1.0))
+
+ def testCalculateRelativeChangeFromZero(self):
+ """Tests what happens when relative change from zero is calculated."""
+ # If the first number is zero, then the result is not a number.
+ self.assertTrue(
+ math.isnan(bisect_perf_module.CalculateRelativeChange(0, 0)))
+ self.assertTrue(
+ math.isnan(bisect_perf_module.CalculateRelativeChange(0, 1)))
+
+ def testCalculateRelativeChangeWithNegatives(self):
+ """Tests that relative change given is always positive."""
+ self.assertEqual(3.0, bisect_perf_module.CalculateRelativeChange(-1, 2))
+ self.assertEqual(3.0, bisect_perf_module.CalculateRelativeChange(1, -2))
+ self.assertEqual(1.0, bisect_perf_module.CalculateRelativeChange(-1, -2))
+
+
if __name__ == '__main__':
unittest.main()
« tools/bisect-perf-regression.py ('K') | « tools/bisect-perf-regression.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698