Chromium Code Reviews| 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.feature import MetaFeatureValue | 7 from crash.loglinear.feature import MetaFeatureValue |
| 8 from crash.loglinear.weight import MetaWeight | 8 from crash.loglinear.weight import MetaWeight |
| 9 from crash.loglinear.weight import Weight | 9 from crash.loglinear.weight import Weight |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 | 53 |
| 54 class MetaWeightTest(unittest.TestCase): | 54 class MetaWeightTest(unittest.TestCase): |
| 55 """Tests class ``MetaWeight``.""" | 55 """Tests class ``MetaWeight``.""" |
| 56 | 56 |
| 57 def testMultiply(self): | 57 def testMultiply(self): |
| 58 """Tests overloading operators ``__mul__`` and ``__rmul__``""" | 58 """Tests overloading operators ``__mul__`` and ``__rmul__``""" |
| 59 self.assertEqual(MetaWeight({'f1': Weight(0.8), 'f2': Weight(0.4)}) * | 59 self.assertEqual(MetaWeight({'f1': Weight(0.8), 'f2': Weight(0.4)}) * |
| 60 MetaFeatureValue('f', {'f1': 2., 'f2': 1.}), 2.) | 60 MetaFeatureValue('f', {'f1': 2., 'f2': 1.}), 2.) |
| 61 self.assertEqual(MetaFeatureValue('f', {'f1': 0.8, 'f2': 0.4}) * | 61 self.assertEqual(MetaFeatureValue('f', {'f1': 0.8, 'f2': 0.4}) * |
| 62 MetaWeight({'f1': Weight(2.), 'f2': Weight(1.)}), 2.) | 62 MetaWeight({'f1': Weight(2.), 'f2': Weight(1.)}), 2.) |
| 63 with self.assertRaisesRegexp(Exception, | 63 |
|
stgao
2017/03/14 04:34:33
So you mentioned in the bug "when the trained weig
Sharu Jiang
2017/03/14 05:09:17
No, the flaky test is ``testTrainWeights`` in trai
| |
| 64 ('MetaWeight can only multiply with ' | 64 self.assertEqual( |
| 65 '``MetaFeatureValue`` ' | 65 MetaWeight({'f1': Weight(0.8), 'f3': Weight(0.0)}) * |
| 66 'with the same length')): | 66 MetaFeatureValue('f', {'f1': Weight(2.), 'f2': Weight(9), |
| 67 dummy_result = MetaWeight({'f1': 0.8, 'f2': 0.4}) * MetaFeatureValue( | 67 'f3': Weight(10)}), |
| 68 'f', {'f1': 2.}) | 68 1.6) |
| 69 | 69 |
| 70 def testIter(self): | 70 def testIter(self): |
| 71 """Tests overloading operator ``__iter__``.""" | 71 """Tests overloading operator ``__iter__``.""" |
| 72 weights = {'a': Weight(0.2), 'b': Weight(0.4), 'c': Weight(3.2)} | 72 weights = {'a': Weight(0.2), 'b': Weight(0.4), 'c': Weight(3.2)} |
| 73 meta_weight = MetaWeight(weights) | 73 meta_weight = MetaWeight(weights) |
| 74 self.assertSetEqual(set(iter(meta_weight)), set(iter(weights))) | 74 self.assertSetEqual(set(iter(meta_weight)), set(iter(weights))) |
| 75 for key, value in meta_weight.iteritems(): | 75 for key, value in meta_weight.iteritems(): |
| 76 self.assertEqual(value, weights[key]) | 76 self.assertEqual(value, weights[key]) |
| 77 | 77 |
| 78 def testLen(self): | 78 def testLen(self): |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 """Tests ``l1`` property.""" | 113 """Tests ``l1`` property.""" |
| 114 self.assertEqual(MetaWeight({'a': Weight(0.3), 'b': Weight(0.2)}).l1, 0.5) | 114 self.assertEqual(MetaWeight({'a': Weight(0.3), 'b': Weight(0.2)}).l1, 0.5) |
| 115 self.assertEqual(MetaWeight({'a': Weight(0.3), 'b': Weight(-0.3)}).l1, 0.6) | 115 self.assertEqual(MetaWeight({'a': Weight(0.3), 'b': Weight(-0.3)}).l1, 0.6) |
| 116 | 116 |
| 117 def testquadrance(self): | 117 def testquadrance(self): |
| 118 """Tests ``quadrance`` property.""" | 118 """Tests ``quadrance`` property.""" |
| 119 self.assertEqual(MetaWeight({'a': Weight(0.3), | 119 self.assertEqual(MetaWeight({'a': Weight(0.3), |
| 120 'b': Weight(0.2)}).quadrance, 0.13) | 120 'b': Weight(0.2)}).quadrance, 0.13) |
| 121 self.assertEqual(MetaWeight({'a': Weight(0.3), | 121 self.assertEqual(MetaWeight({'a': Weight(0.3), |
| 122 'b': Weight(-0.3)}).quadrance, 0.18) | 122 'b': Weight(-0.3)}).quadrance, 0.18) |
| OLD | NEW |