From 3dcaaefadfce258aa3a73c356af22e508ee2282a Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 19 Sep 2023 10:46:09 +0300 Subject: [PATCH] * prod: L3292, L3306, L3316-3328 --- Lib/test/test_math.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index c25b845fb6cba8b..f66ee49f1d15a4b 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -2132,6 +2132,8 @@ def test_mtestfile(self): '\n '.join(failures)) def test_prod(self): + from fractions import Fraction as F + prod = math.prod self.assertEqual(prod([]), 1) self.assertEqual(prod([], start=5), 5) @@ -2143,6 +2145,14 @@ def test_prod(self): self.assertEqual(prod([1.0, 2.0, 3.0, 4.0, 5.0]), 120.0) self.assertEqual(prod([1, 2, 3, 4.0, 5.0]), 120.0) self.assertEqual(prod([1.0, 2.0, 3.0, 4, 5]), 120.0) + self.assertEqual(prod([1., F(3, 2)]), 1.5) + + # Error in multiplication + class BadMultiply: + def __rmul__(self, other): + raise RuntimeError + with self.assertRaises(RuntimeError): + prod([10., BadMultiply()]) # Test overflow in fast-path for integers self.assertEqual(prod([1, 1, 2**32, 1, 1]), 2**32)