| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 unittest | 5 import unittest |
| 6 | 6 |
| 7 from crash.loglinear import feature | 7 from crash.loglinear import feature |
| 8 from crash.loglinear.test.loglinear_testcase import LoglinearTestCase |
| 8 import libs.math.logarithms as lmath | 9 import libs.math.logarithms as lmath |
| 9 | 10 |
| 10 _MAXIMUM = 50. | 11 _MAXIMUM = 50. |
| 11 | 12 |
| 12 | 13 |
| 13 class ChangelistFeatureTest(unittest.TestCase): | 14 class ChangelistFeatureTest(unittest.TestCase): |
| 14 | 15 |
| 15 def testLinearlyScaledIsZero(self): | 16 def testLinearlyScaledIsZero(self): |
| 16 """Test that ``LinearlyScaled`` takes 0 to 1.""" | 17 """Test that ``LinearlyScaled`` takes 0 to 1.""" |
| 17 self.assertEqual(1., feature.LinearlyScaled(0., _MAXIMUM)) | 18 self.assertEqual(1., feature.LinearlyScaled(0., _MAXIMUM)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 31 | 32 |
| 32 def testLogLinearlyScaledMiddling(self): | 33 def testLogLinearlyScaledMiddling(self): |
| 33 """Test that ``LogLinearlyScaled`` works on middling values.""" | 34 """Test that ``LogLinearlyScaled`` works on middling values.""" |
| 34 self.assertEqual( | 35 self.assertEqual( |
| 35 lmath.log((_MAXIMUM - 42.) / _MAXIMUM), | 36 lmath.log((_MAXIMUM - 42.) / _MAXIMUM), |
| 36 feature.LogLinearlyScaled(42., _MAXIMUM)) | 37 feature.LogLinearlyScaled(42., _MAXIMUM)) |
| 37 | 38 |
| 38 def testLogLinearlyScaledIsOverMax(self): | 39 def testLogLinearlyScaledIsOverMax(self): |
| 39 """Test that ``LogLinearlyScaled`` takes values over the max to log(0).""" | 40 """Test that ``LogLinearlyScaled`` takes values over the max to log(0).""" |
| 40 self.assertEqual(lmath.LOG_ZERO, feature.LogLinearlyScaled(42., 10.)) | 41 self.assertEqual(lmath.LOG_ZERO, feature.LogLinearlyScaled(42., 10.)) |
| 42 |
| 43 |
| 44 class FeatureFunctionTest(LoglinearTestCase): |
| 45 |
| 46 def testFeatureFunction(self): |
| 47 """Test that ``FeatureFunction`` obeys the equality its docstring says.""" |
| 48 for x in self._X: |
| 49 for y in self._Y(x): |
| 50 for f in self._feature_list: |
| 51 self.assertEqual(f(x)(y), self._feature_function(x)(y)[f.name]) |
| OLD | NEW |