Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from crash.changelist_features import min_distance | |
| 6 from crash.results import AnalysisInfo | |
| 7 from crash.results import MatchResult | |
| 8 from crash.results import Result | |
| 9 from crash.scorers.test.scorer_test_suite import ScorerTestSuite | |
| 10 from crash.stacktrace import StackFrame | |
| 11 | |
| 12 | |
| 13 class MinDistanceTest(ScorerTestSuite): | |
|
Sharu Jiang
2016/12/06 20:49:19
Now that we changed Scorer -> Feature, we should a
wrengr
2016/12/07 00:55:38
Will do. I actually just pushed a revised CL that
| |
| 14 | |
| 15 @property | |
| 16 def _maximum(self): | |
| 17 return float(min_distance.DEFAULT_MAXIMUM) | |
| 18 | |
| 19 def _GetMockResult(self, mock_min_distance): | |
| 20 """Returns a ``Result`` with the desired min_distance.""" | |
| 21 result = Result(self._GetDummyChangeLog(), 'src/') | |
| 22 result.file_to_analysis_info = { | |
| 23 'file': AnalysisInfo( | |
| 24 min_distance=mock_min_distance, | |
| 25 min_distance_frame=None) | |
| 26 } | |
| 27 return result | |
| 28 | |
| 29 def testMinDistanceFeatureNone(self): | |
| 30 """Test that the feature returns 0 when there are no frames.""" | |
| 31 result = Result(self._GetDummyChangeLog(), 'src/') | |
| 32 self.assertIsNone(min_distance.MinDistanceFeature()(result)) | |
| 33 | |
| 34 def testMinDistanceFeature(self): | |
|
inferno
2016/12/06 18:07:06
Some functions missing docstrings! Can you add pre
Sharu Jiang
2016/12/06 20:49:19
I added a bug to track this. https://bugs.chromium
| |
| 35 result = self._GetMockResult(42.) | |
| 36 self.assertEqual(42., min_distance.MinDistanceFeature()(result)) | |
| 37 | |
| 38 def testMinDistanceFeatureIsOverMax(self): | |
| 39 result = self._GetMockResult(42.) | |
| 40 self.assertEqual(10., min_distance.MinDistanceFeature(10.)(result)) | |
| 41 | |
| 42 def testLinearMinDistanceFeatureIsZero(self): | |
| 43 """Test that the feature returns 1 when the min_distance is 0.""" | |
| 44 result = self._GetMockResult(0.) | |
| 45 self.assertEqual(1., min_distance.LinearMinDistanceFeature()(result)) | |
| 46 | |
| 47 def testLinearMinDistanceFeatureMiddling(self): | |
| 48 """Test that the feature returns middling scores for middling distances.""" | |
| 49 result = self._GetMockResult(42.) | |
| 50 self.assertEqual( | |
| 51 (self._maximum - 42.) / self._maximum, | |
| 52 min_distance.LinearMinDistanceFeature()(result)) | |
| 53 | |
| 54 def testLinearMinDistanceFeatureIsOverMax(self): | |
| 55 """Test that the feature returns 0 when the min_distance is too large.""" | |
| 56 result = self._GetMockResult(self._maximum + 1) | |
| 57 self.assertEqual(0., min_distance.LinearMinDistanceFeature()(result)) | |
| 58 | |
| 59 result = self._GetMockResult(42.) | |
| 60 self.assertEqual(0., min_distance.LinearMinDistanceFeature(10.)(result)) | |
| 61 | |
| 62 def testSquaredMinDistanceFeatureMiddling(self): | |
| 63 """Test that the squared feature also returns middling values.""" | |
| 64 result = self._GetMockResult(42.) | |
| 65 self.assertEqual( | |
| 66 ((self._maximum - 42.) / self._maximum)**2, | |
| 67 min_distance.SquaredMinDistanceFeature()(result)) | |
| OLD | NEW |