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

Unified Diff: appengine/findit/crash/changelist_features/test/top_frame_index_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/top_frame_index_test.py
diff --git a/appengine/findit/crash/changelist_features/test/top_frame_index_test.py b/appengine/findit/crash/changelist_features/test/top_frame_index_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..4dc63a40ecafe1c1483a8153ab6eed332bd63561
--- /dev/null
+++ b/appengine/findit/crash/changelist_features/test/top_frame_index_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 top_frame_index
+from crash.results import Result
+from crash.results import StackInfo
+from crash.scorers.test.scorer_test_suite import ScorerTestSuite
+from crash.stacktrace import StackFrame
+from lib.gitiles.change_log import ChangeLog
+
+
+class TopFrameIndexTest(ScorerTestSuite):
+
+ @property
+ def _maximum(self):
+ return float(top_frame_index._MAX_FRAME_INDEX)
+
+ def _GetMockResult(self, mock_top_frame_index):
+ """Returns a ``Result`` with the desired top frame index."""
+ dep_path = 'src/'
+ result = Result(self._GetDummyChangeLog(), dep_path)
+ result.file_to_stack_infos = {
+ 'a.cc': [StackInfo(
+ frame = StackFrame(
+ index = mock_top_frame_index,
+ dep_path = dep_path,
+ function = 'func',
+ file_path = 'a.cc',
+ raw_file_path = 'a.cc',
+ crashed_line_numbers = [7]),
+ priority = 0)]
+ }
+ return result
+
+ def testTopFrameIndexNone(self):
+ """Test that the feature returns 0 when there are no frames."""
+ result = Result(self._GetDummyChangeLog(), 'src/')
+ self.assertEqual(0., top_frame_index.TopFrameIndexFeature()(result))
+
+ def testTopFrameIndexIsZero(self):
+ """Test that the feature returns 1 when the top frame index is 0."""
+ result = self._GetMockResult(0)
+ self.assertEqual(1., top_frame_index.TopFrameIndexFeature()(result))
+
+ def testTopFrameIndexMiddling(self):
+ """Test that the feature returns middling scores for middling indices."""
+ result = self._GetMockResult(3)
+ self.assertEqual(
+ (self._maximum - 3.) / self._maximum,
+ top_frame_index.TopFrameIndexFeature()(result))
+
+ def testTopFrameIndexIsOverMax(self):
+ """Test that the feature returns 0 when the top frame index is too large."""
+ result = self._GetMockResult(self._maximum + 1)
+ self.assertEqual(0., top_frame_index.TopFrameIndexFeature()(result))
+
+ result = self._GetMockResult(5)
+ self.assertEqual(0., top_frame_index.TopFrameIndexFeature(2)(result))
+
+ def testSquaredTopFrameIndexMiddling(self):
+ """Test that the squared feature also returns middling values."""
+ result = self._GetMockResult(3)
+ self.assertEqual(
+ ((self._maximum - 3.) / self._maximum)**2,
+ top_frame_index.SquaredTopFrameIndexFeature()(result))

Powered by Google App Engine
This is Rietveld 408576698