|
35 | 35 | from test.support.import_helper import import_module |
36 | 36 | from test.support.os_helper import (EnvironmentVarGuard, TESTFN, unlink) |
37 | 37 | from test.support.script_helper import assert_python_ok |
| 38 | +from test.support.testcase import ComplexesAreIdenticalMixin |
38 | 39 | from test.support.warnings_helper import check_warnings |
39 | 40 | from test.support import requires_IEEE_754 |
40 | 41 | from unittest.mock import MagicMock, patch |
@@ -151,7 +152,7 @@ def map_char(arg): |
151 | 152 | def pack(*args): |
152 | 153 | return args |
153 | 154 |
|
154 | | -class BuiltinTest(unittest.TestCase): |
| 155 | +class BuiltinTest(ComplexesAreIdenticalMixin, unittest.TestCase): |
155 | 156 | # Helper to check picklability |
156 | 157 | def check_iter_pickle(self, it, seq, proto): |
157 | 158 | itorg = it |
@@ -1902,6 +1903,13 @@ def __getitem__(self, index): |
1902 | 1903 | self.assertEqual(sum(xs), complex(sum(z.real for z in xs), |
1903 | 1904 | sum(z.imag for z in xs))) |
1904 | 1905 |
|
| 1906 | + # test that sum() of complex and real numbers doesn't |
| 1907 | + # smash sign of imaginary 0 |
| 1908 | + self.assertComplexesAreIdentical(sum([complex(1, -0.0), 1]), |
| 1909 | + complex(2, -0.0)) |
| 1910 | + self.assertComplexesAreIdentical(sum([complex(1, -0.0), 1.0]), |
| 1911 | + complex(2, -0.0)) |
| 1912 | + |
1905 | 1913 | @requires_IEEE_754 |
1906 | 1914 | @unittest.skipIf(HAVE_DOUBLE_ROUNDING, |
1907 | 1915 | "sum accuracy not guaranteed on machines with double rounding") |
|
0 commit comments