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
e00168a4
Commit
e00168a4
authored
Feb 29, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#14089: increase coverage of the fractions module. Patch by Oleg Plakhotnyuk.
parent
1cf1d98e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
Lib/test/test_fractions.py
Lib/test/test_fractions.py
+19
-1
No files found.
Lib/test/test_fractions.py
View file @
e00168a4
...
...
@@ -6,6 +6,7 @@ import math
import
numbers
import
operator
import
fractions
import
sys
import
unittest
from
copy
import
copy
,
deepcopy
from
cPickle
import
dumps
,
loads
...
...
@@ -88,6 +89,9 @@ class DummyRational(object):
__hash__
=
None
class
DummyFraction
(
fractions
.
Fraction
):
"""Dummy Fraction subclass for copy and deepcopy testing."""
class
GcdTest
(
unittest
.
TestCase
):
def
testMisc
(
self
):
...
...
@@ -301,11 +305,15 @@ class FractionTest(unittest.TestCase):
self
.
assertEqual
(
F
(
201
,
200
).
limit_denominator
(
100
),
F
(
1
))
self
.
assertEqual
(
F
(
201
,
200
).
limit_denominator
(
101
),
F
(
102
,
101
))
self
.
assertEqual
(
F
(
0
).
limit_denominator
(
10000
),
F
(
0
))
for
i
in
(
0
,
-
1
):
self
.
assertRaisesMessage
(
ValueError
,
"max_denominator should be at least 1"
,
F
(
1
).
limit_denominator
,
i
)
def
testConversions
(
self
):
self
.
assertTypedEquals
(
-
1
,
math
.
trunc
(
F
(
-
11
,
10
)))
self
.
assertTypedEquals
(
-
1
,
int
(
F
(
-
11
,
10
)))
self
.
assertTypedEquals
(
1
,
math
.
trunc
(
F
(
11
,
10
)))
self
.
assertEqual
(
False
,
bool
(
F
(
0
,
1
)))
self
.
assertEqual
(
True
,
bool
(
F
(
3
,
2
)))
self
.
assertTypedEquals
(
0.1
,
float
(
F
(
1
,
10
)))
...
...
@@ -330,6 +338,7 @@ class FractionTest(unittest.TestCase):
self
.
assertEqual
(
F
(
8
,
27
),
F
(
2
,
3
)
**
F
(
3
))
self
.
assertEqual
(
F
(
27
,
8
),
F
(
2
,
3
)
**
F
(
-
3
))
self
.
assertTypedEquals
(
2.0
,
F
(
4
)
**
F
(
1
,
2
))
self
.
assertEqual
(
F
(
1
,
1
),
+
F
(
1
,
1
))
# Will return 1j in 3.0:
self
.
assertRaises
(
ValueError
,
pow
,
F
(
-
1
),
F
(
1
,
2
))
...
...
@@ -394,6 +403,10 @@ class FractionTest(unittest.TestCase):
TypeError
,
"unsupported operand type(s) for +: 'Fraction' and 'Decimal'"
,
operator
.
add
,
F
(
3
,
11
),
Decimal
(
'3.1415926'
))
self
.
assertRaisesMessage
(
TypeError
,
"unsupported operand type(s) for +: 'Decimal' and 'Fraction'"
,
operator
.
add
,
Decimal
(
'3.1415926'
),
F
(
3
,
11
))
self
.
assertNotEqual
(
F
(
5
,
2
),
Decimal
(
'2.5'
))
def
testComparisons
(
self
):
...
...
@@ -571,9 +584,14 @@ class FractionTest(unittest.TestCase):
def
test_copy_deepcopy_pickle
(
self
):
r
=
F
(
13
,
7
)
dr
=
DummyFraction
(
13
,
7
)
self
.
assertEqual
(
r
,
loads
(
dumps
(
r
)))
self
.
assertEqual
(
id
(
r
),
id
(
copy
(
r
)))
self
.
assertEqual
(
id
(
r
),
id
(
deepcopy
(
r
)))
self
.
assertNotEqual
(
id
(
dr
),
id
(
copy
(
dr
)))
self
.
assertNotEqual
(
id
(
dr
),
id
(
deepcopy
(
dr
)))
self
.
assertTypedEquals
(
dr
,
copy
(
dr
))
self
.
assertTypedEquals
(
dr
,
deepcopy
(
dr
))
def
test_slots
(
self
):
# Issue 4998
...
...
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