mirror of
https://github.com/python/cpython.git
synced 2025-08-11 12:29:34 +00:00

svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83212 | florent.xicluna | 2010-07-28 18:39:41 +0200 (mer., 28 juil. 2010) | 2 lines Syntax cleanup. ........ r83829 | florent.xicluna | 2010-08-08 18:16:07 +0200 (dim., 08 août 2010) | 2 lines Use unittest specific methods for some urllib test cases. And replace urllib2 with urllib.request in comments. ........ r83833 | florent.xicluna | 2010-08-08 18:25:27 +0200 (dim., 08 août 2010) | 2 lines Add test case for the HTTPResponse being an iterable. Follow-up of issue #4608. ........ r83838 | florent.xicluna | 2010-08-08 20:03:44 +0200 (dim., 08 août 2010) | 2 lines Typo. ........ r83839 | florent.xicluna | 2010-08-08 20:06:13 +0200 (dim., 08 août 2010) | 2 lines Issue #7564: Skip test_ioctl if another process is attached to /dev/tty. ........ r83878 | florent.xicluna | 2010-08-09 10:29:08 +0200 (lun., 09 août 2010) | 1 line Merge the 2to3 script from /sandbox/trunk/2to3/2to3, revision 72867 (latest). ........ r84019 | florent.xicluna | 2010-08-14 17:56:42 +0200 (sam., 14 août 2010) | 11 lines Merged manually from 2.7 branch to 3.x trunk. ------------------------------------------------------------------------ r79925 | nick.coghlan | 2010-04-10 16:24:36 +0200 (sam. 10 avril 2010) Try to turn some buildbots green by allowing test_multiprocessing to pass even if it hits the sys.exc_clear code in the threading module, and improve the test coverage by making the ctypes dependencies a bit more granular (two of the cited ctypes objects don't exist on my system) ------------------------------------------------------------------------ ........ r84025 | florent.xicluna | 2010-08-14 18:56:27 +0200 (sam., 14 août 2010) | 1 line List Misc/python-config.in in Misc/README. Fix few typos. ........ r84028 | florent.xicluna | 2010-08-14 19:02:49 +0200 (sam., 14 août 2010) | 1 line Fix order. ........ r84032 | florent.xicluna | 2010-08-14 19:15:31 +0200 (sam., 14 août 2010) | 1 line Convert to spaces. ........ r84036 | florent.xicluna | 2010-08-14 20:03:19 +0200 (sam., 14 août 2010) | 1 line Remove bad merge (from svnmerge r82301) ........
129 lines
4.5 KiB
Python
129 lines
4.5 KiB
Python
import test.support, unittest
|
|
|
|
class PowTest(unittest.TestCase):
|
|
|
|
def powtest(self, type):
|
|
if type != float:
|
|
for i in range(-1000, 1000):
|
|
self.assertEquals(pow(type(i), 0), 1)
|
|
self.assertEquals(pow(type(i), 1), type(i))
|
|
self.assertEquals(pow(type(0), 1), type(0))
|
|
self.assertEquals(pow(type(1), 1), type(1))
|
|
|
|
for i in range(-100, 100):
|
|
self.assertEquals(pow(type(i), 3), i*i*i)
|
|
|
|
pow2 = 1
|
|
for i in range(0, 31):
|
|
self.assertEquals(pow(2, i), pow2)
|
|
if i != 30 : pow2 = pow2*2
|
|
|
|
for othertype in (int,):
|
|
for i in list(range(-10, 0)) + list(range(1, 10)):
|
|
ii = type(i)
|
|
for j in range(1, 11):
|
|
jj = -othertype(j)
|
|
pow(ii, jj)
|
|
|
|
for othertype in int, float:
|
|
for i in range(1, 100):
|
|
zero = type(0)
|
|
exp = -othertype(i/10.0)
|
|
if exp == 0:
|
|
continue
|
|
self.assertRaises(ZeroDivisionError, pow, zero, exp)
|
|
|
|
il, ih = -20, 20
|
|
jl, jh = -5, 5
|
|
kl, kh = -10, 10
|
|
asseq = self.assertEqual
|
|
if type == float:
|
|
il = 1
|
|
asseq = self.assertAlmostEqual
|
|
elif type == int:
|
|
jl = 0
|
|
elif type == int:
|
|
jl, jh = 0, 15
|
|
for i in range(il, ih+1):
|
|
for j in range(jl, jh+1):
|
|
for k in range(kl, kh+1):
|
|
if k != 0:
|
|
if type == float or j < 0:
|
|
self.assertRaises(TypeError, pow, type(i), j, k)
|
|
continue
|
|
asseq(
|
|
pow(type(i),j,k),
|
|
pow(type(i),j)% type(k)
|
|
)
|
|
|
|
def test_powint(self):
|
|
self.powtest(int)
|
|
|
|
def test_powlong(self):
|
|
self.powtest(int)
|
|
|
|
def test_powfloat(self):
|
|
self.powtest(float)
|
|
|
|
def test_other(self):
|
|
# Other tests-- not very systematic
|
|
self.assertEquals(pow(3,3) % 8, pow(3,3,8))
|
|
self.assertEquals(pow(3,3) % -8, pow(3,3,-8))
|
|
self.assertEquals(pow(3,2) % -2, pow(3,2,-2))
|
|
self.assertEquals(pow(-3,3) % 8, pow(-3,3,8))
|
|
self.assertEquals(pow(-3,3) % -8, pow(-3,3,-8))
|
|
self.assertEquals(pow(5,2) % -8, pow(5,2,-8))
|
|
|
|
self.assertEquals(pow(3,3) % 8, pow(3,3,8))
|
|
self.assertEquals(pow(3,3) % -8, pow(3,3,-8))
|
|
self.assertEquals(pow(3,2) % -2, pow(3,2,-2))
|
|
self.assertEquals(pow(-3,3) % 8, pow(-3,3,8))
|
|
self.assertEquals(pow(-3,3) % -8, pow(-3,3,-8))
|
|
self.assertEquals(pow(5,2) % -8, pow(5,2,-8))
|
|
|
|
for i in range(-10, 11):
|
|
for j in range(0, 6):
|
|
for k in range(-7, 11):
|
|
if j >= 0 and k != 0:
|
|
self.assertEquals(
|
|
pow(i,j) % k,
|
|
pow(i,j,k)
|
|
)
|
|
if j >= 0 and k != 0:
|
|
self.assertEquals(
|
|
pow(int(i),j) % k,
|
|
pow(int(i),j,k)
|
|
)
|
|
|
|
def test_bug643260(self):
|
|
class TestRpow:
|
|
def __rpow__(self, other):
|
|
return None
|
|
None ** TestRpow() # Won't fail when __rpow__ invoked. SF bug #643260.
|
|
|
|
def test_bug705231(self):
|
|
# -1.0 raised to an integer should never blow up. It did if the
|
|
# platform pow() was buggy, and Python didn't worm around it.
|
|
eq = self.assertEquals
|
|
a = -1.0
|
|
# The next two tests can still fail if the platform floor()
|
|
# function doesn't treat all large inputs as integers
|
|
# test_math should also fail if that is happening
|
|
eq(pow(a, 1.23e167), 1.0)
|
|
eq(pow(a, -1.23e167), 1.0)
|
|
for b in range(-10, 11):
|
|
eq(pow(a, float(b)), b & 1 and -1.0 or 1.0)
|
|
for n in range(0, 100):
|
|
fiveto = float(5 ** n)
|
|
# For small n, fiveto will be odd. Eventually we run out of
|
|
# mantissa bits, though, and thereafer fiveto will be even.
|
|
expected = fiveto % 2.0 and -1.0 or 1.0
|
|
eq(pow(a, fiveto), expected)
|
|
eq(pow(a, -fiveto), expected)
|
|
eq(expected, 1.0) # else we didn't push fiveto to evenness
|
|
|
|
def test_main():
|
|
test.support.run_unittest(PowTest)
|
|
|
|
if __name__ == "__main__":
|
|
test_main()
|