diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-03 08:35:41 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-03 08:35:41 (GMT) |
commit | 32f453eaa476c78376cd721d29ba8ab726e400bb (patch) | |
tree | aec8b2e54ec4a0a7cbd66569d3a8531db118f153 /Lib/test/test_b2.py | |
parent | 5d2b77cf31c5a3cbabc74936831480b9caea3a12 (diff) | |
download | cpython-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/test/test_b2.py')
-rw-r--r-- | Lib/test/test_b2.py | 27 |
1 files changed, 19 insertions, 8 deletions
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)' |