Skip to content

Commit 2b46a96

Browse files
committed
added sum() test
1 parent de5f353 commit 2b46a96

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Lib/test/test_builtin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from test.support.import_helper import import_module
3636
from test.support.os_helper import (EnvironmentVarGuard, TESTFN, unlink)
3737
from test.support.script_helper import assert_python_ok
38+
from test.support.testcase import ComplexesAreIdenticalMixin
3839
from test.support.warnings_helper import check_warnings
3940
from test.support import requires_IEEE_754
4041
from unittest.mock import MagicMock, patch
@@ -151,7 +152,7 @@ def map_char(arg):
151152
def pack(*args):
152153
return args
153154

154-
class BuiltinTest(unittest.TestCase):
155+
class BuiltinTest(ComplexesAreIdenticalMixin, unittest.TestCase):
155156
# Helper to check picklability
156157
def check_iter_pickle(self, it, seq, proto):
157158
itorg = it
@@ -1902,6 +1903,13 @@ def __getitem__(self, index):
19021903
self.assertEqual(sum(xs), complex(sum(z.real for z in xs),
19031904
sum(z.imag for z in xs)))
19041905

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+
19051913
@requires_IEEE_754
19061914
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
19071915
"sum accuracy not guaranteed on machines with double rounding")

0 commit comments

Comments
 (0)