Chromium Code Reviews| Index: appengine/findit/libs/math/test/logarithms_test.py |
| diff --git a/appengine/findit/libs/math/test/logarithms_test.py b/appengine/findit/libs/math/test/logarithms_test.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..109735e2b54bf1f567095638a2d0e454b0848411 |
| --- /dev/null |
| +++ b/appengine/findit/libs/math/test/logarithms_test.py |
| @@ -0,0 +1,26 @@ |
| +# 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. |
| + |
| +import unittest |
| + |
| +from libs.math.logarithms import logsumexp |
| + |
| +INFINITY = float('inf') |
| + |
| +class LogarithmsTest(unittest.TestCase): |
| + |
| + def testLogsumexpEmpty(self): |
|
Martin Barbella
2016/12/02 20:07:02
Docstrings here as well.
wrengr
2016/12/02 21:00:58
Done.
|
| + self.assertEqual(-INFINITY, logsumexp([])) |
| + |
| + def testLogsumexpInfinite(self): |
| + self.assertEqual(INFINITY, logsumexp([INFINITY])) |
| + self.assertEqual(INFINITY, logsumexp([INFINITY, -INFINITY])) |
| + self.assertEqual(INFINITY, logsumexp([0, 1, 2, INFINITY, 9, 8, 7])) |
| + |
| + def testLogsumexpCommutative(self): |
| + # N.B., we must choose these two values carefully, to ensure we |
| + # don't trivially pass the test. |
| + xs = [0.1, 0.3] |
| + ys = xs[::-1] |
| + self.assertEqual(logsumexp(xs), logsumexp(ys)) |