summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-03 08:35:41 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-03 08:35:41 (GMT)
commit32f453eaa476c78376cd721d29ba8ab726e400bb (patch)
treeaec8b2e54ec4a0a7cbd66569d3a8531db118f153 /Lib
parent5d2b77cf31c5a3cbabc74936831480b9caea3a12 (diff)
downloadcpython-32f453eaa476c78376cd721d29ba8ab726e400bb.zip
cpython-32f453eaa476c78376cd721d29ba8ab726e400bb.tar.gz
cpython-32f453eaa476c78376cd721d29ba8ab726e400bb.tar.bz2
New restriction on pow(x, y, z): If z is not None, x and y must be of
integer types, and y must be >= 0. See discussion at http://sf.net/tracker/index.php?func=detail&aid=457066&group_id=5470&atid=105470
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/output/test_pow4
-rw-r--r--Lib/test/test_b2.py27
-rw-r--r--Lib/test/test_long.py17
-rw-r--r--Lib/test/test_pow.py18
4 files changed, 41 insertions, 25 deletions
diff --git a/Lib/test/output/test_pow b/Lib/test/output/test_pow
index e236862..9649936 100644
--- a/Lib/test/output/test_pow
+++ b/Lib/test/output/test_pow
@@ -22,8 +22,4 @@ The number in both columns should match.
-3L -3L
-7L -7L
-3.0 3.0
--5.0 -5.0
--1.0 -1.0
--7.0 -7.0
diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py
index ae07f5b..1a21689 100644
--- a/Lib/test/test_b2.py
+++ b/Lib/test/test_b2.py
@@ -82,17 +82,28 @@ if fcmp(pow(2.,10), 1024.): raise TestFailed, 'pow(2.,10)'
if fcmp(pow(2.,20), 1024.*1024.): raise TestFailed, 'pow(2.,20)'
if fcmp(pow(2.,30), 1024.*1024.*1024.): raise TestFailed, 'pow(2.,30)'
#
-# XXX These don't work -- negative float to the float power...
-#if fcmp(pow(-2.,0), 1.): raise TestFailed, 'pow(-2.,0)'
-#if fcmp(pow(-2.,1), -2.): raise TestFailed, 'pow(-2.,1)'
-#if fcmp(pow(-2.,2), 4.): raise TestFailed, 'pow(-2.,2)'
-#if fcmp(pow(-2.,3), -8.): raise TestFailed, 'pow(-2.,3)'
-#
+if fcmp(pow(-2.,0), 1.): raise TestFailed, 'pow(-2.,0)'
+if fcmp(pow(-2.,1), -2.): raise TestFailed, 'pow(-2.,1)'
+if fcmp(pow(-2.,2), 4.): raise TestFailed, 'pow(-2.,2)'
+if fcmp(pow(-2.,3), -8.): raise TestFailed, 'pow(-2.,3)'
+
+from types import FloatType
for x in 2, 2L, 2.0:
for y in 10, 10L, 10.0:
for z in 1000, 1000L, 1000.0:
- if fcmp(pow(x, y, z), 24.0):
- raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z)
+ if isinstance(x, FloatType) or \
+ isinstance(y, FloatType) or \
+ isinstance(z, FloatType):
+ try:
+ pow(x, y, z)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed("3-arg float pow() should have "
+ "raised TypeError %r" % (x, y, z))
+ else:
+ if fcmp(pow(x, y, z), 24.0):
+ raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z)
print 'range'
if range(3) != [0, 1, 2]: raise TestFailed, 'range(3)'
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 3b6081e..b0eaff7 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -314,10 +314,19 @@ def test_auto_overflow():
checkit(x, '**', y)
for z in special:
- if z != 0:
- expected = pow(longx, longy, long(z))
- got = pow(x, y, z)
- checkit('pow', x, y, '%', z)
+ if z != 0 :
+ if y >= 0:
+ expected = pow(longx, longy, long(z))
+ got = pow(x, y, z)
+ checkit('pow', x, y, '%', z)
+ else:
+ try:
+ pow(longx, longy, long(z))
+ except TypeError:
+ pass
+ else:
+ raise TestFailed("pow%r should have raised "
+ "TypeError" % ((longx, longy, long(z))))
# ---------------------------------------------------------------- do it
diff --git a/Lib/test/test_pow.py b/Lib/test/test_pow.py
index 51d7484..41911bf 100644
--- a/Lib/test/test_pow.py
+++ b/Lib/test/test_pow.py
@@ -64,6 +64,15 @@ def powtest(type):
for j in range(jl, jh+1):
for k in range(kl, kh+1):
if k != 0:
+ if type == float or j < 0:
+ try:
+ pow(type(i),j,k)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed("expected TypeError from "
+ "pow%r" % ((type(i), j, k)))
+ continue
if compare(pow(type(i),j,k), pow(type(i),j)% type(k)):
raise ValueError, "pow(" +str(i)+ "," +str(j)+ \
"," +str(k)+ ") != pow(" +str(i)+ "," + \
@@ -96,10 +105,6 @@ print `pow(-3L,3L) % -8`, `pow(-3L,3L,-8)`
print `pow(5L,2) % -8`, `pow(5L,2,-8)`
print
-print pow(3.0,3.0) % 8, pow(3.0,3.0,8)
-print pow(3.0,3.0) % -8, pow(3.0,3.0,-8)
-print pow(3.0,2) % -2, pow(3.0,2,-2)
-print pow(5.0,2) % -8, pow(5.0,2,-8)
print
for i in range(-10, 11):
@@ -112,8 +117,3 @@ for i in range(-10, 11):
if j >= 0 and k != 0:
o = pow(long(i),j) % k
n = pow(long(i),j,k)
- if o != n: print 'Long mismatch:', i,j,k
- if i >= 0 and k != 0:
- o = pow(float(i),j) % k
- n = pow(float(i),j,k)
- if o != n: print 'Float mismatch:', i,j,k