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() |