Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
363f6d65
Commit
363f6d65
authored
Feb 03, 2003
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port test_pow.py to PyUnit. From SF patch #662807
parent
93fe5642
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
149 deletions
+110
-149
Lib/test/output/test_pow
Lib/test/output/test_pow
+0
-25
Lib/test/test_pow.py
Lib/test/test_pow.py
+110
-124
No files found.
Lib/test/output/test_pow
deleted
100644 → 0
View file @
93fe5642
test_pow
Testing integer mode...
Testing 2-argument pow() function...
Testing 3-argument pow() function...
Testing long integer mode...
Testing 2-argument pow() function...
Testing 3-argument pow() function...
Testing floating point mode...
Testing 3-argument pow() function...
The number in both columns should match.
3 3
-5 -5
-1 -1
5 5
-3 -3
-7 -7
3L 3L
-5L -5L
-1L -1L
5L 5L
-3L -3L
-7L -7L
Lib/test/test_pow.py
View file @
363f6d65
import
sys
from
test
import
test_support
import
test.test_support
,
unittest
class
PowTest
(
unittest
.
TestCase
):
def
powtest
(
type
):
def
powtest
(
self
,
type
):
if
type
!=
float
:
print
" Testing 2-argument pow() function..."
for
i
in
range
(
-
1000
,
1000
):
if
pow
(
type
(
i
),
0
)
!=
1
:
raise
ValueError
,
'pow('
+
str
(
i
)
+
',0) != 1'
if
pow
(
type
(
i
),
1
)
!=
type
(
i
):
raise
ValueError
,
'pow('
+
str
(
i
)
+
',1) != '
+
str
(
i
)
if
pow
(
type
(
0
),
1
)
!=
type
(
0
):
raise
ValueError
,
'pow(0,'
+
str
(
i
)
+
') != 0'
if
pow
(
type
(
1
),
1
)
!=
type
(
1
):
raise
ValueError
,
'pow(1,'
+
str
(
i
)
+
') != 1'
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
):
if
pow
(
type
(
i
),
3
)
!=
i
*
i
*
i
:
raise
ValueError
,
'pow('
+
str
(
i
)
+
',3) != '
+
str
(
i
*
i
*
i
)
self
.
assertEquals
(
pow
(
type
(
i
),
3
),
i
*
i
*
i
)
pow2
=
1
for
i
in
range
(
0
,
31
):
if
pow
(
2
,
i
)
!=
pow2
:
raise
ValueError
,
'pow(2,'
+
str
(
i
)
+
') != '
+
str
(
pow2
)
self
.
assertEquals
(
pow
(
2
,
i
),
pow2
)
if
i
!=
30
:
pow2
=
pow2
*
2
for
othertype
in
int
,
long
:
...
...
@@ -30,10 +23,7 @@ def powtest(type):
ii
=
type
(
i
)
for
j
in
range
(
1
,
11
):
jj
=
-
othertype
(
j
)
try
:
pow
(
ii
,
jj
)
except
ValueError
:
raise
ValueError
,
"pow(%s, %s) failed"
%
(
ii
,
jj
)
for
othertype
in
int
,
long
,
float
:
for
i
in
range
(
1
,
100
):
...
...
@@ -41,21 +31,15 @@ def powtest(type):
exp
=
-
othertype
(
i
/
10.0
)
if
exp
==
0
:
continue
try
:
pow
(
zero
,
exp
)
except
ZeroDivisionError
:
pass
# taking zero to any negative exponent should fail
else
:
raise
ValueError
,
"pow(%s, %s) did not fail"
%
(
zero
,
exp
)
print
" Testing 3-argument pow() function..."
self
.
assertRaises
(
ZeroDivisionError
,
pow
,
zero
,
exp
)
il
,
ih
=
-
20
,
20
jl
,
jh
=
-
5
,
5
kl
,
kh
=
-
10
,
10
compare
=
cmp
asseq
=
self
.
assertEqual
if
type
==
float
:
il
=
1
compare
=
test_support
.
fcmp
asseq
=
self
.
assertAlmostEqual
elif
type
==
int
:
jl
=
0
elif
type
==
long
:
...
...
@@ -65,61 +49,63 @@ def powtest(type):
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
ValueError
,
"expected TypeError from "
+
\
"pow%r"
%
((
type
(
i
),
j
,
k
),)
self
.
assertRaises
(
TypeError
,
pow
,
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
)
+
","
+
\
str
(
j
)
+
") % "
+
str
(
k
)
print
'Testing integer mode...'
powtest
(
int
)
print
'Testing long integer mode...'
powtest
(
long
)
print
'Testing floating point mode...'
powtest
(
float
)
# Other tests-- not very systematic
print
'The number in both columns should match.'
print
`pow(3,3) % 8`
,
`pow(3,3,8)`
print
`pow(3,3) % -8`
,
`pow(3,3,-8)`
print
`pow(3,2) % -2`
,
`pow(3,2,-2)`
print
`pow(-3,3) % 8`
,
`pow(-3,3,8)`
print
`pow(-3,3) % -8`
,
`pow(-3,3,-8)`
print
`pow(5,2) % -8`
,
`pow(5,2,-8)`
print
print
`pow(3L,3L) % 8`
,
`pow(3L,3L,8)`
print
`pow(3L,3L) % -8`
,
`pow(3L,3L,-8)`
print
`pow(3L,2) % -2`
,
`pow(3L,2,-2)`
print
`pow(-3L,3L) % 8`
,
`pow(-3L,3L,8)`
print
`pow(-3L,3L) % -8`
,
`pow(-3L,3L,-8)`
print
`pow(5L,2) % -8`
,
`pow(5L,2,-8)`
print
print
for
i
in
range
(
-
10
,
11
):
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
(
long
)
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
(
3L
,
3L
)
%
8
,
pow
(
3L
,
3L
,
8
))
self
.
assertEquals
(
pow
(
3L
,
3L
)
%
-
8
,
pow
(
3L
,
3L
,
-
8
))
self
.
assertEquals
(
pow
(
3L
,
2
)
%
-
2
,
pow
(
3L
,
2
,
-
2
))
self
.
assertEquals
(
pow
(
-
3L
,
3L
)
%
8
,
pow
(
-
3L
,
3L
,
8
))
self
.
assertEquals
(
pow
(
-
3L
,
3L
)
%
-
8
,
pow
(
-
3L
,
3L
,
-
8
))
self
.
assertEquals
(
pow
(
5L
,
2
)
%
-
8
,
pow
(
5L
,
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
:
o
=
pow
(
i
,
j
)
%
k
n
=
pow
(
i
,
j
,
k
)
if
o
!=
n
:
print
'Integer mismatch:'
,
i
,
j
,
k
self
.
assertEquals
(
pow
(
i
,
j
)
%
k
,
pow
(
i
,
j
,
k
)
)
if
j
>=
0
and
k
!=
0
:
o
=
pow
(
long
(
i
),
j
)
%
k
n
=
pow
(
long
(
i
),
j
,
k
)
if
o
!=
n
:
print
'Integer mismatch:'
,
i
,
j
,
k
self
.
assertEquals
(
pow
(
long
(
i
),
j
)
%
k
,
pow
(
long
(
i
),
j
,
k
)
)
class
TestRpow
:
def
test_bug643260
(
self
):
class
TestRpow
:
def
__rpow__
(
self
,
other
):
return
None
None
**
TestRpow
()
# Won't fail when __rpow__ invoked. SF bug #643260.
None
**
TestRpow
()
# Won't fail when __rpow__ invoked. SF bug #643260.
def
test_main
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
PowTest
))
test
.
test_support
.
run_suite
(
suite
)
if
__name__
==
"__main__"
:
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment