From b497e8fae1f2935f3d139f46281d6be25b6ccb8a Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 27 Sep 2023 12:06:42 +0300 Subject: [PATCH] More tests for complex_mul() Partially from python/cpython#109642 --- Lib/test/test_complex.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 5fee4d103f2b20..9129f133d1cc77 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -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):