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

Unified Diff: tools/auto_bisect/math_utils_test.py

Issue 417013003: Move statistical functions in bisect script to their own module. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to nit Created 6 years, 5 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
« no previous file with comments | « tools/auto_bisect/math_utils.py ('k') | tools/bisect-perf-regression.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/auto_bisect/math_utils_test.py
diff --git a/tools/auto_bisect/math_utils_test.py b/tools/auto_bisect/math_utils_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..4d19881f55887d1b41ef531e0f7cb7e49d128b3b
--- /dev/null
+++ b/tools/auto_bisect/math_utils_test.py
@@ -0,0 +1,62 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import math
+import unittest
+
+import math_utils
+
+
+class MathUtilsTest(unittest.TestCase):
+ """Tests for mathematical utility functions."""
+
+ def testTruncatedMeanRaisesError(self):
+ """TruncatedMean should raise an error when passed an empty list."""
+ with self.assertRaises(TypeError):
+ math_utils.TruncatedMean([], 0)
+
+ def testMeanSingleNum(self):
+ """Tests the Mean function with a single number."""
+ self.assertEqual(3.0, math_utils.Mean([3]))
+
+ def testMeanShortList(self):
+ """Tests the Mean function with a short list."""
+ self.assertEqual(0.5, math_utils.Mean([-3, 0, 1, 4]))
+
+ def testMeanCompareAlternateImplementation(self):
+ """Tests Mean by comparing against an alternate implementation."""
+ def AlternateMeanFunction(values):
+ """Simple arithmetic mean function."""
+ return sum(values) / float(len(values))
+ test_values_lists = [[1], [5, 6.5, 1.2, 3], [-3, 0, 1, 4],
+ [-3, -1, 0.12, 0.752, 3.33, 8, 16, 32, 439]]
+ for values in test_values_lists:
+ self.assertEqual(
+ AlternateMeanFunction(values),
+ math_utils.Mean(values))
+
+ def testRelativeChange(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, math_utils.RelativeChange(1.0, 1.5))
+ self.assertEqual(0.5, math_utils.RelativeChange(2.0, 1.0))
+
+ def testRelativeChangeFromZero(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.assertEqual(0, math_utils.RelativeChange(0, 0))
+ self.assertTrue(
+ math.isnan(math_utils.RelativeChange(0, 1)))
+ self.assertTrue(
+ math.isnan(math_utils.RelativeChange(0, -1)))
+
+ def testRelativeChangeWithNegatives(self):
+ """Tests that relative change given is always positive."""
+ self.assertEqual(3.0, math_utils.RelativeChange(-1, 2))
+ self.assertEqual(3.0, math_utils.RelativeChange(1, -2))
+ self.assertEqual(1.0, math_utils.RelativeChange(-1, -2))
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tools/auto_bisect/math_utils.py ('k') | tools/bisect-perf-regression.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698