Skip to content

Commit

Permalink
* prod: L3292, L3306, L3316-3328
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Sep 28, 2023
1 parent b431805 commit a046568
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a046568

Please sign in to comment.