| Index: appengine/findit/crash/loglinear/test/model_test.py
|
| diff --git a/appengine/findit/crash/loglinear/test/model_test.py b/appengine/findit/crash/loglinear/test/model_test.py
|
| index 17d8e6e4b85a3b0a2cf9bb9e235042f119b6f750..9bf3b431f8850346872d693097006d26876605d9 100644
|
| --- a/appengine/findit/crash/loglinear/test/model_test.py
|
| +++ b/appengine/findit/crash/loglinear/test/model_test.py
|
| @@ -5,20 +5,26 @@
|
| import math
|
| import numpy as np
|
|
|
| -from crash.loglinear.model import ToFeatureFunction
|
| +from crash.loglinear.feature import FeatureFunction
|
| from crash.loglinear.model import LogLinearModel
|
| +from crash.loglinear.model import UnnormalizedLogLinearModel
|
| from crash.loglinear.test.loglinear_testcase import LoglinearTestCase
|
|
|
|
|
| -class LoglinearTest(LoglinearTestCase):
|
| +class UnnormalizedLogLinearModelTest(LoglinearTestCase):
|
|
|
| - def testToFeatureFunction(self):
|
| - """Test that ``ToFeatureFunction`` obeys the equality its docstring says."""
|
| - for x in self._X:
|
| - for y in self._Y(x):
|
| - for i in xrange(self._qty_features):
|
| - self.assertEqual(self._feature_list[i](x)(y),
|
| - self._feature_function(x)(y)[i])
|
| + def testSingleFeatureScore(self):
|
| + """Test that ``SingleFeatureScore`` returns weighted feature score."""
|
| + model = UnnormalizedLogLinearModel(self._feature_function, self._weights,
|
| + 0.1)
|
| + for feature in self._feature_list:
|
| + feature_value = feature(5)(True)
|
| + self.assertEqual(
|
| + model.SingleFeatureScore(feature_value),
|
| + feature_value.value * model._weights.get(feature_value.name, 0.))
|
| +
|
| +
|
| +class LoglinearTest(LoglinearTestCase):
|
|
|
| def testLogLinearModel(self):
|
| """An arbitrary test to get 100% code coverage.
|
| @@ -37,7 +43,7 @@ class LoglinearTest(LoglinearTestCase):
|
| model = LogLinearModel(self._Y, self._feature_function, self._weights, 0.1)
|
| model.ClearAllMemos()
|
| model = LogLinearModel(self._Y, self._feature_function, self._weights)
|
| - self.assertListEqual(self._weights, model.weights.tolist())
|
| + self.assertDictEqual(self._weights, model.weights)
|
| self.assertEqual(math.sqrt(model.quadrance), model.l2)
|
|
|
| for x in self._X:
|
|
|