Skip to content

Commit

Permalink
More tests for complex_mul()
Browse files Browse the repository at this point in the history
Partially from python#109642
  • Loading branch information
skirpichev committed Sep 27, 2023
1 parent 82031a1 commit b497e8f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Lib/test/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,31 @@ def test_sub(self):
self.assertComplexesAreIdentical((1-0j) - 1, complex(0, -0.0))
self.assertComplexesAreIdentical(1 - (1-0j), complex(0, 0))

def test_mul(self):
self.assertAlmostEqual(1j * 2, complex(0, 2))
self.assertAlmostEqual(1j * (-1), complex(0, -1))
self.assertRaises(OverflowError, operator.mul, 1j, 10**1000)
self.assertRaises(TypeError, operator.mul, 1j, None)
self.assertRaises(TypeError, operator.mul, None, 1j)

self.assertComplexesAreIdentical(0.0 * 0j, complex(0, 0))
self.assertComplexesAreIdentical(0j * 0.0, complex(0.0, 0))
self.assertComplexesAreIdentical(-0.0 * 0j, complex(0.0, -0.0))
self.assertComplexesAreIdentical(0j * (-0.0), complex(0, -0.0))
self.assertComplexesAreIdentical((-0.0+0j) * 0.0, complex(-0.0, 0))
self.assertComplexesAreIdentical(0.0 * (-0.0+0j), complex(-0.0, 0))
self.assertComplexesAreIdentical((-0.0+0j) * (-0.0), complex(0, -0.0))
self.assertComplexesAreIdentical((-0.0) * (-0.0+0j), complex(0, -0.0))
self.assertComplexesAreIdentical((-0.0-0j) * (-0.0), complex(0, 0))
self.assertComplexesAreIdentical((-0.0) * (-0.0-0j), complex(0, 0))
self.assertComplexesAreIdentical((1+0j) * (1-0j), complex(1, 0))
self.assertComplexesAreIdentical(0j * (-0.0-0j), complex(0.0, -0.0))
self.assertComplexesAreIdentical(0j * (-0j), complex(0, 0))
self.assertComplexesAreIdentical((1+0j) * (-0.0-0j), complex(0, -0.0))
self.assertComplexesAreIdentical((-0.0+0j) * (-0j), complex(0, 0))
self.assertComplexesAreIdentical((1+0j) * 1, complex(1, 0))
self.assertComplexesAreIdentical(1 * (1+0j), complex(1, 0))

def test_mod(self):
# % is no longer supported on complex numbers
with self.assertRaises(TypeError):
Expand Down

0 comments on commit b497e8f

Please sign in to comment.