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

Unified Diff: appengine/findit/crash/changelist_features/test/min_distance_test.py

Issue 2517383005: Implementing loglinear classification (without training), for CL classification (Closed)
Patch Set: rebase Created 4 years 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
Index: appengine/findit/crash/changelist_features/test/min_distance_test.py
diff --git a/appengine/findit/crash/changelist_features/test/min_distance_test.py b/appengine/findit/crash/changelist_features/test/min_distance_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..eb2ae28a6a4940fe73abd7966592d78569ab2d98
--- /dev/null
+++ b/appengine/findit/crash/changelist_features/test/min_distance_test.py
@@ -0,0 +1,67 @@
+# Copyright 2016 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.
+
+from crash.changelist_features import min_distance
+from crash.results import AnalysisInfo
+from crash.results import MatchResult
+from crash.results import Result
+from crash.scorers.test.scorer_test_suite import ScorerTestSuite
+from crash.stacktrace import StackFrame
+
+
+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
+
+ @property
+ def _maximum(self):
+ return float(min_distance.DEFAULT_MAXIMUM)
+
+ def _GetMockResult(self, mock_min_distance):
+ """Returns a ``Result`` with the desired min_distance."""
+ result = Result(self._GetDummyChangeLog(), 'src/')
+ result.file_to_analysis_info = {
+ 'file': AnalysisInfo(
+ min_distance=mock_min_distance,
+ min_distance_frame=None)
+ }
+ return result
+
+ def testMinDistanceFeatureNone(self):
+ """Test that the feature returns 0 when there are no frames."""
+ result = Result(self._GetDummyChangeLog(), 'src/')
+ self.assertIsNone(min_distance.MinDistanceFeature()(result))
+
+ 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
+ result = self._GetMockResult(42.)
+ self.assertEqual(42., min_distance.MinDistanceFeature()(result))
+
+ def testMinDistanceFeatureIsOverMax(self):
+ result = self._GetMockResult(42.)
+ self.assertEqual(10., min_distance.MinDistanceFeature(10.)(result))
+
+ def testLinearMinDistanceFeatureIsZero(self):
+ """Test that the feature returns 1 when the min_distance is 0."""
+ result = self._GetMockResult(0.)
+ self.assertEqual(1., min_distance.LinearMinDistanceFeature()(result))
+
+ def testLinearMinDistanceFeatureMiddling(self):
+ """Test that the feature returns middling scores for middling distances."""
+ result = self._GetMockResult(42.)
+ self.assertEqual(
+ (self._maximum - 42.) / self._maximum,
+ min_distance.LinearMinDistanceFeature()(result))
+
+ def testLinearMinDistanceFeatureIsOverMax(self):
+ """Test that the feature returns 0 when the min_distance is too large."""
+ result = self._GetMockResult(self._maximum + 1)
+ self.assertEqual(0., min_distance.LinearMinDistanceFeature()(result))
+
+ result = self._GetMockResult(42.)
+ self.assertEqual(0., min_distance.LinearMinDistanceFeature(10.)(result))
+
+ def testSquaredMinDistanceFeatureMiddling(self):
+ """Test that the squared feature also returns middling values."""
+ result = self._GetMockResult(42.)
+ self.assertEqual(
+ ((self._maximum - 42.) / self._maximum)**2,
+ min_distance.SquaredMinDistanceFeature()(result))

Powered by Google App Engine
This is Rietveld 408576698