Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f393fc6

Browse files
committed
Add various test cases from SF patch 543867.
1 parent a301667 commit f393fc6

1 file changed

Lines changed: 58 additions & 1 deletion

File tree

Lib/test/test_complex.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest
1+
import unittest, os
22
from test import test_support
33

44
import warnings
@@ -106,6 +106,14 @@ def test_richcompare(self):
106106
def test_mod(self):
107107
self.assertRaises(ZeroDivisionError, (1+1j).__mod__, 0+0j)
108108

109+
a = 3.33+4.43j
110+
try:
111+
a % 0
112+
except ZeroDivisionError:
113+
pass
114+
else:
115+
self.fail("modulo parama can't be 0")
116+
109117
def test_divmod(self):
110118
self.assertRaises(ZeroDivisionError, divmod, 1+1j, 0+0j)
111119

@@ -117,6 +125,37 @@ def test_pow(self):
117125
self.assertAlmostEqual(pow(1j, 200), 1)
118126
self.assertRaises(ValueError, pow, 1+1j, 1+1j, 1+1j)
119127

128+
a = 3.33+4.43j
129+
self.assertEqual(a ** 0j, 1)
130+
self.assertEqual(a ** 0.+0.j, 1)
131+
132+
self.assertEqual(3j ** 0j, 1)
133+
self.assertEqual(3j ** 0, 1)
134+
135+
try:
136+
0j ** a
137+
except ZeroDivisionError:
138+
pass
139+
else:
140+
self.fail("should fail 0.0 to negative or complex power")
141+
142+
try:
143+
0j ** (3-2j)
144+
except ZeroDivisionError:
145+
pass
146+
else:
147+
self.fail("should fail 0.0 to negative or complex power")
148+
149+
# The following is used to exercise certain code paths
150+
self.assertEqual(a ** 105, a ** 105)
151+
self.assertEqual(a ** -105, a ** -105)
152+
self.assertEqual(a ** -30, a ** -30)
153+
154+
self.assertEqual(0.0j ** 0, 1)
155+
156+
b = 5.1+2.3j
157+
self.assertRaises(ValueError, pow, a, b, 0)
158+
120159
def test_boolcontext(self):
121160
for i in xrange(100):
122161
self.assert_(complex(random() + 1e-6, random() + 1e-6))
@@ -243,6 +282,24 @@ def test_repr(self):
243282
def test_neg(self):
244283
self.assertEqual(-(1+6j), -1-6j)
245284

285+
def test_file(self):
286+
a = 3.33+4.43j
287+
b = 5.1+2.3j
288+
289+
fo = None
290+
try:
291+
fo = open(test_support.TESTFN, "wb")
292+
print >>fo, a, b
293+
fo.close()
294+
fo = open(test_support.TESTFN, "rb")
295+
self.assertEqual(fo.read(), "%s %s\n" % (a, b))
296+
finally:
297+
if (fo is not None) and (not fo.closed):
298+
fo.close()
299+
try:
300+
os.remove(test_support.TESTFN)
301+
except (OSError, IOError):
302+
pass
246303

247304
def test_main():
248305
test_support.run_unittest(ComplexTest)

0 commit comments

Comments
 (0)