OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 math |
5 import unittest | 6 import unittest |
6 | 7 |
7 # Special import necessary because filename contains dash characters. | 8 # Special import necessary because filename contains dash characters. |
8 bisect_perf_module = __import__('bisect-perf-regression') | 9 bisect_perf_module = __import__('bisect-perf-regression') |
9 | 10 |
10 | 11 |
11 class BisectPerfRegressionTest(unittest.TestCase): | 12 class BisectPerfRegressionTest(unittest.TestCase): |
12 """Test case for top-level functions in the bisect-perf-regrssion module.""" | 13 """Test case for top-level functions in the bisect-perf-regrssion module.""" |
13 | 14 |
14 def setUp(self): | 15 def setUp(self): |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 0, bisect_perf_module.CalculateConfidence(bad_values, good_values)) | 69 0, bisect_perf_module.CalculateConfidence(bad_values, good_values)) |
69 | 70 |
70 def testCalculateConfidence100(self): | 71 def testCalculateConfidence100(self): |
71 """Tests the confidence calculation when it's expected to be 100.""" | 72 """Tests the confidence calculation when it's expected to be 100.""" |
72 bad_values = [[1, 1], [1, 1]] | 73 bad_values = [[1, 1], [1, 1]] |
73 good_values = [[1.2, 1.2], [1.2, 1.2]] | 74 good_values = [[1.2, 1.2], [1.2, 1.2]] |
74 # Standard deviation in both groups is zero, so confidence is 100. | 75 # Standard deviation in both groups is zero, so confidence is 100. |
75 self.assertEqual( | 76 self.assertEqual( |
76 100, bisect_perf_module.CalculateConfidence(bad_values, good_values)) | 77 100, bisect_perf_module.CalculateConfidence(bad_values, good_values)) |
77 | 78 |
| 79 def testCalculateRelativeChange(self): |
| 80 """Tests the common cases for calculating relative change.""" |
| 81 # The change is relative to the first value, regardless of which is bigger. |
| 82 self.assertEqual(0.5, bisect_perf_module.CalculateRelativeChange(1.0, 1.5)) |
| 83 self.assertEqual(0.5, bisect_perf_module.CalculateRelativeChange(2.0, 1.0)) |
| 84 |
| 85 def testCalculateRelativeChangeFromZero(self): |
| 86 """Tests what happens when relative change from zero is calculated.""" |
| 87 # If the first number is zero, then the result is not a number. |
| 88 self.assertEqual(0, bisect_perf_module.CalculateRelativeChange(0, 0)) |
| 89 self.assertTrue( |
| 90 math.isnan(bisect_perf_module.CalculateRelativeChange(0, 1))) |
| 91 self.assertTrue( |
| 92 math.isnan(bisect_perf_module.CalculateRelativeChange(0, -1))) |
| 93 |
| 94 def testCalculateRelativeChangeWithNegatives(self): |
| 95 """Tests that relative change given is always positive.""" |
| 96 self.assertEqual(3.0, bisect_perf_module.CalculateRelativeChange(-1, 2)) |
| 97 self.assertEqual(3.0, bisect_perf_module.CalculateRelativeChange(1, -2)) |
| 98 self.assertEqual(1.0, bisect_perf_module.CalculateRelativeChange(-1, -2)) |
| 99 |
| 100 |
78 if __name__ == '__main__': | 101 if __name__ == '__main__': |
79 unittest.main() | 102 unittest.main() |
OLD | NEW |