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
92911bfc
Commit
92911bfc
authored
Oct 29, 2006
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for basic argument errors.
parent
7d000990
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
Lib/test/test_math.py
Lib/test/test_math.py
+27
-0
No files found.
Lib/test/test_math.py
View file @
92911bfc
...
@@ -20,21 +20,25 @@ class MathTests(unittest.TestCase):
...
@@ -20,21 +20,25 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'e'
,
math
.
e
,
2.7182818
)
self
.
ftest
(
'e'
,
math
.
e
,
2.7182818
)
def
testAcos
(
self
):
def
testAcos
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
acos
)
self
.
ftest
(
'acos(-1)'
,
math
.
acos
(
-
1
),
math
.
pi
)
self
.
ftest
(
'acos(-1)'
,
math
.
acos
(
-
1
),
math
.
pi
)
self
.
ftest
(
'acos(0)'
,
math
.
acos
(
0
),
math
.
pi
/
2
)
self
.
ftest
(
'acos(0)'
,
math
.
acos
(
0
),
math
.
pi
/
2
)
self
.
ftest
(
'acos(1)'
,
math
.
acos
(
1
),
0
)
self
.
ftest
(
'acos(1)'
,
math
.
acos
(
1
),
0
)
def
testAsin
(
self
):
def
testAsin
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
asin
)
self
.
ftest
(
'asin(-1)'
,
math
.
asin
(
-
1
),
-
math
.
pi
/
2
)
self
.
ftest
(
'asin(-1)'
,
math
.
asin
(
-
1
),
-
math
.
pi
/
2
)
self
.
ftest
(
'asin(0)'
,
math
.
asin
(
0
),
0
)
self
.
ftest
(
'asin(0)'
,
math
.
asin
(
0
),
0
)
self
.
ftest
(
'asin(1)'
,
math
.
asin
(
1
),
math
.
pi
/
2
)
self
.
ftest
(
'asin(1)'
,
math
.
asin
(
1
),
math
.
pi
/
2
)
def
testAtan
(
self
):
def
testAtan
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
atan
)
self
.
ftest
(
'atan(-1)'
,
math
.
atan
(
-
1
),
-
math
.
pi
/
4
)
self
.
ftest
(
'atan(-1)'
,
math
.
atan
(
-
1
),
-
math
.
pi
/
4
)
self
.
ftest
(
'atan(0)'
,
math
.
atan
(
0
),
0
)
self
.
ftest
(
'atan(0)'
,
math
.
atan
(
0
),
0
)
self
.
ftest
(
'atan(1)'
,
math
.
atan
(
1
),
math
.
pi
/
4
)
self
.
ftest
(
'atan(1)'
,
math
.
atan
(
1
),
math
.
pi
/
4
)
def
testAtan2
(
self
):
def
testAtan2
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
atan2
)
self
.
ftest
(
'atan2(-1, 0)'
,
math
.
atan2
(
-
1
,
0
),
-
math
.
pi
/
2
)
self
.
ftest
(
'atan2(-1, 0)'
,
math
.
atan2
(
-
1
,
0
),
-
math
.
pi
/
2
)
self
.
ftest
(
'atan2(-1, 1)'
,
math
.
atan2
(
-
1
,
1
),
-
math
.
pi
/
4
)
self
.
ftest
(
'atan2(-1, 1)'
,
math
.
atan2
(
-
1
,
1
),
-
math
.
pi
/
4
)
self
.
ftest
(
'atan2(0, 1)'
,
math
.
atan2
(
0
,
1
),
0
)
self
.
ftest
(
'atan2(0, 1)'
,
math
.
atan2
(
0
,
1
),
0
)
...
@@ -42,6 +46,7 @@ class MathTests(unittest.TestCase):
...
@@ -42,6 +46,7 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'atan2(1, 0)'
,
math
.
atan2
(
1
,
0
),
math
.
pi
/
2
)
self
.
ftest
(
'atan2(1, 0)'
,
math
.
atan2
(
1
,
0
),
math
.
pi
/
2
)
def
testCeil
(
self
):
def
testCeil
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
ceil
)
self
.
ftest
(
'ceil(0.5)'
,
math
.
ceil
(
0.5
),
1
)
self
.
ftest
(
'ceil(0.5)'
,
math
.
ceil
(
0.5
),
1
)
self
.
ftest
(
'ceil(1.0)'
,
math
.
ceil
(
1.0
),
1
)
self
.
ftest
(
'ceil(1.0)'
,
math
.
ceil
(
1.0
),
1
)
self
.
ftest
(
'ceil(1.5)'
,
math
.
ceil
(
1.5
),
2
)
self
.
ftest
(
'ceil(1.5)'
,
math
.
ceil
(
1.5
),
2
)
...
@@ -50,31 +55,37 @@ class MathTests(unittest.TestCase):
...
@@ -50,31 +55,37 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'ceil(-1.5)'
,
math
.
ceil
(
-
1.5
),
-
1
)
self
.
ftest
(
'ceil(-1.5)'
,
math
.
ceil
(
-
1.5
),
-
1
)
def
testCos
(
self
):
def
testCos
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
cos
)
self
.
ftest
(
'cos(-pi/2)'
,
math
.
cos
(
-
math
.
pi
/
2
),
0
)
self
.
ftest
(
'cos(-pi/2)'
,
math
.
cos
(
-
math
.
pi
/
2
),
0
)
self
.
ftest
(
'cos(0)'
,
math
.
cos
(
0
),
1
)
self
.
ftest
(
'cos(0)'
,
math
.
cos
(
0
),
1
)
self
.
ftest
(
'cos(pi/2)'
,
math
.
cos
(
math
.
pi
/
2
),
0
)
self
.
ftest
(
'cos(pi/2)'
,
math
.
cos
(
math
.
pi
/
2
),
0
)
self
.
ftest
(
'cos(pi)'
,
math
.
cos
(
math
.
pi
),
-
1
)
self
.
ftest
(
'cos(pi)'
,
math
.
cos
(
math
.
pi
),
-
1
)
def
testCosh
(
self
):
def
testCosh
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
cosh
)
self
.
ftest
(
'cosh(0)'
,
math
.
cosh
(
0
),
1
)
self
.
ftest
(
'cosh(0)'
,
math
.
cosh
(
0
),
1
)
self
.
ftest
(
'cosh(2)-2*cosh(1)**2'
,
math
.
cosh
(
2
)
-
2
*
math
.
cosh
(
1
)
**
2
,
-
1
)
# Thanks to Lambert
self
.
ftest
(
'cosh(2)-2*cosh(1)**2'
,
math
.
cosh
(
2
)
-
2
*
math
.
cosh
(
1
)
**
2
,
-
1
)
# Thanks to Lambert
def
testDegrees
(
self
):
def
testDegrees
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
degrees
)
self
.
ftest
(
'degrees(pi)'
,
math
.
degrees
(
math
.
pi
),
180.0
)
self
.
ftest
(
'degrees(pi)'
,
math
.
degrees
(
math
.
pi
),
180.0
)
self
.
ftest
(
'degrees(pi/2)'
,
math
.
degrees
(
math
.
pi
/
2
),
90.0
)
self
.
ftest
(
'degrees(pi/2)'
,
math
.
degrees
(
math
.
pi
/
2
),
90.0
)
self
.
ftest
(
'degrees(-pi/4)'
,
math
.
degrees
(
-
math
.
pi
/
4
),
-
45.0
)
self
.
ftest
(
'degrees(-pi/4)'
,
math
.
degrees
(
-
math
.
pi
/
4
),
-
45.0
)
def
testExp
(
self
):
def
testExp
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
exp
)
self
.
ftest
(
'exp(-1)'
,
math
.
exp
(
-
1
),
1
/
math
.
e
)
self
.
ftest
(
'exp(-1)'
,
math
.
exp
(
-
1
),
1
/
math
.
e
)
self
.
ftest
(
'exp(0)'
,
math
.
exp
(
0
),
1
)
self
.
ftest
(
'exp(0)'
,
math
.
exp
(
0
),
1
)
self
.
ftest
(
'exp(1)'
,
math
.
exp
(
1
),
math
.
e
)
self
.
ftest
(
'exp(1)'
,
math
.
exp
(
1
),
math
.
e
)
def
testFabs
(
self
):
def
testFabs
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
fabs
)
self
.
ftest
(
'fabs(-1)'
,
math
.
fabs
(
-
1
),
1
)
self
.
ftest
(
'fabs(-1)'
,
math
.
fabs
(
-
1
),
1
)
self
.
ftest
(
'fabs(0)'
,
math
.
fabs
(
0
),
0
)
self
.
ftest
(
'fabs(0)'
,
math
.
fabs
(
0
),
0
)
self
.
ftest
(
'fabs(1)'
,
math
.
fabs
(
1
),
1
)
self
.
ftest
(
'fabs(1)'
,
math
.
fabs
(
1
),
1
)
def
testFloor
(
self
):
def
testFloor
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
floor
)
self
.
ftest
(
'floor(0.5)'
,
math
.
floor
(
0.5
),
0
)
self
.
ftest
(
'floor(0.5)'
,
math
.
floor
(
0.5
),
0
)
self
.
ftest
(
'floor(1.0)'
,
math
.
floor
(
1.0
),
1
)
self
.
ftest
(
'floor(1.0)'
,
math
.
floor
(
1.0
),
1
)
self
.
ftest
(
'floor(1.5)'
,
math
.
floor
(
1.5
),
1
)
self
.
ftest
(
'floor(1.5)'
,
math
.
floor
(
1.5
),
1
)
...
@@ -83,6 +94,7 @@ class MathTests(unittest.TestCase):
...
@@ -83,6 +94,7 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'floor(-1.5)'
,
math
.
floor
(
-
1.5
),
-
2
)
self
.
ftest
(
'floor(-1.5)'
,
math
.
floor
(
-
1.5
),
-
2
)
def
testFmod
(
self
):
def
testFmod
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
fmod
)
self
.
ftest
(
'fmod(10,1)'
,
math
.
fmod
(
10
,
1
),
0
)
self
.
ftest
(
'fmod(10,1)'
,
math
.
fmod
(
10
,
1
),
0
)
self
.
ftest
(
'fmod(10,0.5)'
,
math
.
fmod
(
10
,
0.5
),
0
)
self
.
ftest
(
'fmod(10,0.5)'
,
math
.
fmod
(
10
,
0.5
),
0
)
self
.
ftest
(
'fmod(10,1.5)'
,
math
.
fmod
(
10
,
1.5
),
1
)
self
.
ftest
(
'fmod(10,1.5)'
,
math
.
fmod
(
10
,
1.5
),
1
)
...
@@ -91,6 +103,8 @@ class MathTests(unittest.TestCase):
...
@@ -91,6 +103,8 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'fmod(-10,1.5)'
,
math
.
fmod
(
-
10
,
1.5
),
-
1
)
self
.
ftest
(
'fmod(-10,1.5)'
,
math
.
fmod
(
-
10
,
1.5
),
-
1
)
def
testFrexp
(
self
):
def
testFrexp
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
frexp
)
def
testfrexp
(
name
,
(
mant
,
exp
),
(
emant
,
eexp
)):
def
testfrexp
(
name
,
(
mant
,
exp
),
(
emant
,
eexp
)):
if
abs
(
mant
-
emant
)
>
eps
or
exp
!=
eexp
:
if
abs
(
mant
-
emant
)
>
eps
or
exp
!=
eexp
:
self
.
fail
(
'%s returned %r, expected %r'
%
\
self
.
fail
(
'%s returned %r, expected %r'
%
\
...
@@ -102,16 +116,19 @@ class MathTests(unittest.TestCase):
...
@@ -102,16 +116,19 @@ class MathTests(unittest.TestCase):
testfrexp
(
'frexp(2)'
,
math
.
frexp
(
2
),
(
0.5
,
2
))
testfrexp
(
'frexp(2)'
,
math
.
frexp
(
2
),
(
0.5
,
2
))
def
testHypot
(
self
):
def
testHypot
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
hypot
)
self
.
ftest
(
'hypot(0,0)'
,
math
.
hypot
(
0
,
0
),
0
)
self
.
ftest
(
'hypot(0,0)'
,
math
.
hypot
(
0
,
0
),
0
)
self
.
ftest
(
'hypot(3,4)'
,
math
.
hypot
(
3
,
4
),
5
)
self
.
ftest
(
'hypot(3,4)'
,
math
.
hypot
(
3
,
4
),
5
)
def
testLdexp
(
self
):
def
testLdexp
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
ldexp
)
self
.
ftest
(
'ldexp(0,1)'
,
math
.
ldexp
(
0
,
1
),
0
)
self
.
ftest
(
'ldexp(0,1)'
,
math
.
ldexp
(
0
,
1
),
0
)
self
.
ftest
(
'ldexp(1,1)'
,
math
.
ldexp
(
1
,
1
),
2
)
self
.
ftest
(
'ldexp(1,1)'
,
math
.
ldexp
(
1
,
1
),
2
)
self
.
ftest
(
'ldexp(1,-1)'
,
math
.
ldexp
(
1
,
-
1
),
0.5
)
self
.
ftest
(
'ldexp(1,-1)'
,
math
.
ldexp
(
1
,
-
1
),
0.5
)
self
.
ftest
(
'ldexp(-1,1)'
,
math
.
ldexp
(
-
1
,
1
),
-
2
)
self
.
ftest
(
'ldexp(-1,1)'
,
math
.
ldexp
(
-
1
,
1
),
-
2
)
def
testLog
(
self
):
def
testLog
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
log
)
self
.
ftest
(
'log(1/e)'
,
math
.
log
(
1
/
math
.
e
),
-
1
)
self
.
ftest
(
'log(1/e)'
,
math
.
log
(
1
/
math
.
e
),
-
1
)
self
.
ftest
(
'log(1)'
,
math
.
log
(
1
),
0
)
self
.
ftest
(
'log(1)'
,
math
.
log
(
1
),
0
)
self
.
ftest
(
'log(e)'
,
math
.
log
(
math
.
e
),
1
)
self
.
ftest
(
'log(e)'
,
math
.
log
(
math
.
e
),
1
)
...
@@ -120,11 +137,14 @@ class MathTests(unittest.TestCase):
...
@@ -120,11 +137,14 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'log(10**40, 10**20)'
,
math
.
log
(
10
**
40
,
10
**
20
),
2
)
self
.
ftest
(
'log(10**40, 10**20)'
,
math
.
log
(
10
**
40
,
10
**
20
),
2
)
def
testLog10
(
self
):
def
testLog10
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
log10
)
self
.
ftest
(
'log10(0.1)'
,
math
.
log10
(
0.1
),
-
1
)
self
.
ftest
(
'log10(0.1)'
,
math
.
log10
(
0.1
),
-
1
)
self
.
ftest
(
'log10(1)'
,
math
.
log10
(
1
),
0
)
self
.
ftest
(
'log10(1)'
,
math
.
log10
(
1
),
0
)
self
.
ftest
(
'log10(10)'
,
math
.
log10
(
10
),
1
)
self
.
ftest
(
'log10(10)'
,
math
.
log10
(
10
),
1
)
def
testModf
(
self
):
def
testModf
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
modf
)
def
testmodf
(
name
,
(
v1
,
v2
),
(
e1
,
e2
)):
def
testmodf
(
name
,
(
v1
,
v2
),
(
e1
,
e2
)):
if
abs
(
v1
-
e1
)
>
eps
or
abs
(
v2
-
e2
):
if
abs
(
v1
-
e1
)
>
eps
or
abs
(
v2
-
e2
):
self
.
fail
(
'%s returned %r, expected %r'
%
\
self
.
fail
(
'%s returned %r, expected %r'
%
\
...
@@ -134,37 +154,44 @@ class MathTests(unittest.TestCase):
...
@@ -134,37 +154,44 @@ class MathTests(unittest.TestCase):
testmodf
(
'modf(-1.5)'
,
math
.
modf
(
-
1.5
),
(
-
0.5
,
-
1.0
))
testmodf
(
'modf(-1.5)'
,
math
.
modf
(
-
1.5
),
(
-
0.5
,
-
1.0
))
def
testPow
(
self
):
def
testPow
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
pow
)
self
.
ftest
(
'pow(0,1)'
,
math
.
pow
(
0
,
1
),
0
)
self
.
ftest
(
'pow(0,1)'
,
math
.
pow
(
0
,
1
),
0
)
self
.
ftest
(
'pow(1,0)'
,
math
.
pow
(
1
,
0
),
1
)
self
.
ftest
(
'pow(1,0)'
,
math
.
pow
(
1
,
0
),
1
)
self
.
ftest
(
'pow(2,1)'
,
math
.
pow
(
2
,
1
),
2
)
self
.
ftest
(
'pow(2,1)'
,
math
.
pow
(
2
,
1
),
2
)
self
.
ftest
(
'pow(2,-1)'
,
math
.
pow
(
2
,
-
1
),
0.5
)
self
.
ftest
(
'pow(2,-1)'
,
math
.
pow
(
2
,
-
1
),
0.5
)
def
testRadians
(
self
):
def
testRadians
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
radians
)
self
.
ftest
(
'radians(180)'
,
math
.
radians
(
180
),
math
.
pi
)
self
.
ftest
(
'radians(180)'
,
math
.
radians
(
180
),
math
.
pi
)
self
.
ftest
(
'radians(90)'
,
math
.
radians
(
90
),
math
.
pi
/
2
)
self
.
ftest
(
'radians(90)'
,
math
.
radians
(
90
),
math
.
pi
/
2
)
self
.
ftest
(
'radians(-45)'
,
math
.
radians
(
-
45
),
-
math
.
pi
/
4
)
self
.
ftest
(
'radians(-45)'
,
math
.
radians
(
-
45
),
-
math
.
pi
/
4
)
def
testSin
(
self
):
def
testSin
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
sin
)
self
.
ftest
(
'sin(0)'
,
math
.
sin
(
0
),
0
)
self
.
ftest
(
'sin(0)'
,
math
.
sin
(
0
),
0
)
self
.
ftest
(
'sin(pi/2)'
,
math
.
sin
(
math
.
pi
/
2
),
1
)
self
.
ftest
(
'sin(pi/2)'
,
math
.
sin
(
math
.
pi
/
2
),
1
)
self
.
ftest
(
'sin(-pi/2)'
,
math
.
sin
(
-
math
.
pi
/
2
),
-
1
)
self
.
ftest
(
'sin(-pi/2)'
,
math
.
sin
(
-
math
.
pi
/
2
),
-
1
)
def
testSinh
(
self
):
def
testSinh
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
sinh
)
self
.
ftest
(
'sinh(0)'
,
math
.
sinh
(
0
),
0
)
self
.
ftest
(
'sinh(0)'
,
math
.
sinh
(
0
),
0
)
self
.
ftest
(
'sinh(1)**2-cosh(1)**2'
,
math
.
sinh
(
1
)
**
2
-
math
.
cosh
(
1
)
**
2
,
-
1
)
self
.
ftest
(
'sinh(1)**2-cosh(1)**2'
,
math
.
sinh
(
1
)
**
2
-
math
.
cosh
(
1
)
**
2
,
-
1
)
self
.
ftest
(
'sinh(1)+sinh(-1)'
,
math
.
sinh
(
1
)
+
math
.
sinh
(
-
1
),
0
)
self
.
ftest
(
'sinh(1)+sinh(-1)'
,
math
.
sinh
(
1
)
+
math
.
sinh
(
-
1
),
0
)
def
testSqrt
(
self
):
def
testSqrt
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
sqrt
)
self
.
ftest
(
'sqrt(0)'
,
math
.
sqrt
(
0
),
0
)
self
.
ftest
(
'sqrt(0)'
,
math
.
sqrt
(
0
),
0
)
self
.
ftest
(
'sqrt(1)'
,
math
.
sqrt
(
1
),
1
)
self
.
ftest
(
'sqrt(1)'
,
math
.
sqrt
(
1
),
1
)
self
.
ftest
(
'sqrt(4)'
,
math
.
sqrt
(
4
),
2
)
self
.
ftest
(
'sqrt(4)'
,
math
.
sqrt
(
4
),
2
)
def
testTan
(
self
):
def
testTan
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
tan
)
self
.
ftest
(
'tan(0)'
,
math
.
tan
(
0
),
0
)
self
.
ftest
(
'tan(0)'
,
math
.
tan
(
0
),
0
)
self
.
ftest
(
'tan(pi/4)'
,
math
.
tan
(
math
.
pi
/
4
),
1
)
self
.
ftest
(
'tan(pi/4)'
,
math
.
tan
(
math
.
pi
/
4
),
1
)
self
.
ftest
(
'tan(-pi/4)'
,
math
.
tan
(
-
math
.
pi
/
4
),
-
1
)
self
.
ftest
(
'tan(-pi/4)'
,
math
.
tan
(
-
math
.
pi
/
4
),
-
1
)
def
testTanh
(
self
):
def
testTanh
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
tanh
)
self
.
ftest
(
'tanh(0)'
,
math
.
tanh
(
0
),
0
)
self
.
ftest
(
'tanh(0)'
,
math
.
tanh
(
0
),
0
)
self
.
ftest
(
'tanh(1)+tanh(-1)'
,
math
.
tanh
(
1
)
+
math
.
tanh
(
-
1
),
0
)
self
.
ftest
(
'tanh(1)+tanh(-1)'
,
math
.
tanh
(
1
)
+
math
.
tanh
(
-
1
),
0
)
...
...
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