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
8a9c4d98
Commit
8a9c4d98
authored
Apr 13, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 3051: make pure python code pass the same tests as the C version.
parent
5864c9f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
16 deletions
+9
-16
Lib/heapq.py
Lib/heapq.py
+4
-5
Lib/test/test_heapq.py
Lib/test/test_heapq.py
+5
-11
No files found.
Lib/heapq.py
View file @
8a9c4d98
...
@@ -212,11 +212,10 @@ def nsmallest(n, iterable):
...
@@ -212,11 +212,10 @@ def nsmallest(n, iterable):
pop
=
result
.
pop
pop
=
result
.
pop
los
=
result
[
-
1
]
# los --> Largest of the nsmallest
los
=
result
[
-
1
]
# los --> Largest of the nsmallest
for
elem
in
it
:
for
elem
in
it
:
if
los
<=
elem
:
if
elem
<
los
:
continue
insort
(
result
,
elem
)
insort
(
result
,
elem
)
pop
()
pop
()
los
=
result
[
-
1
]
los
=
result
[
-
1
]
return
result
return
result
# An alternative approach manifests the whole iterable in memory but
# An alternative approach manifests the whole iterable in memory but
# saves comparisons by heapifying all at once. Also, saves time
# saves comparisons by heapifying all at once. Also, saves time
...
...
Lib/test/test_heapq.py
View file @
8a9c4d98
...
@@ -211,12 +211,6 @@ class TestHeapC(TestHeap):
...
@@ -211,12 +211,6 @@ class TestHeapC(TestHeap):
self
.
assertEqual
(
hsort
(
data
,
LT
),
target
)
self
.
assertEqual
(
hsort
(
data
,
LT
),
target
)
self
.
assertRaises
(
TypeError
,
data
,
LE
)
self
.
assertRaises
(
TypeError
,
data
,
LE
)
# As an early adopter, we sanity check the
# test.support.import_fresh_module utility function
def
test_accelerated
(
self
):
self
.
assertTrue
(
sys
.
modules
[
'heapq'
]
is
self
.
module
)
self
.
assertFalse
(
hasattr
(
self
.
module
.
heapify
,
'__code__'
))
#==============================================================================
#==============================================================================
...
@@ -319,16 +313,16 @@ class TestErrorHandling(unittest.TestCase):
...
@@ -319,16 +313,16 @@ class TestErrorHandling(unittest.TestCase):
def
test_non_sequence
(
self
):
def
test_non_sequence
(
self
):
for
f
in
(
self
.
module
.
heapify
,
self
.
module
.
heappop
):
for
f
in
(
self
.
module
.
heapify
,
self
.
module
.
heappop
):
self
.
assertRaises
(
TypeError
,
f
,
10
)
self
.
assertRaises
(
(
TypeError
,
AttributeError
)
,
f
,
10
)
for
f
in
(
self
.
module
.
heappush
,
self
.
module
.
heapreplace
,
for
f
in
(
self
.
module
.
heappush
,
self
.
module
.
heapreplace
,
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
self
.
assertRaises
(
TypeError
,
f
,
10
,
10
)
self
.
assertRaises
(
(
TypeError
,
AttributeError
)
,
f
,
10
,
10
)
def
test_len_only
(
self
):
def
test_len_only
(
self
):
for
f
in
(
self
.
module
.
heapify
,
self
.
module
.
heappop
):
for
f
in
(
self
.
module
.
heapify
,
self
.
module
.
heappop
):
self
.
assertRaises
(
TypeError
,
f
,
LenOnly
())
self
.
assertRaises
(
(
TypeError
,
AttributeError
)
,
f
,
LenOnly
())
for
f
in
(
self
.
module
.
heappush
,
self
.
module
.
heapreplace
):
for
f
in
(
self
.
module
.
heappush
,
self
.
module
.
heapreplace
):
self
.
assertRaises
(
TypeError
,
f
,
LenOnly
(),
10
)
self
.
assertRaises
(
(
TypeError
,
AttributeError
)
,
f
,
LenOnly
(),
10
)
for
f
in
(
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
for
f
in
(
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
self
.
assertRaises
(
TypeError
,
f
,
2
,
LenOnly
())
self
.
assertRaises
(
TypeError
,
f
,
2
,
LenOnly
())
...
@@ -353,7 +347,7 @@ class TestErrorHandling(unittest.TestCase):
...
@@ -353,7 +347,7 @@ class TestErrorHandling(unittest.TestCase):
for
f
in
(
self
.
module
.
heapify
,
self
.
module
.
heappop
,
for
f
in
(
self
.
module
.
heapify
,
self
.
module
.
heappop
,
self
.
module
.
heappush
,
self
.
module
.
heapreplace
,
self
.
module
.
heappush
,
self
.
module
.
heapreplace
,
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
self
.
assertRaises
(
TypeError
,
f
,
10
)
self
.
assertRaises
(
(
TypeError
,
AttributeError
)
,
f
,
10
)
def
test_iterable_args
(
self
):
def
test_iterable_args
(
self
):
for
f
in
(
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
for
f
in
(
self
.
module
.
nlargest
,
self
.
module
.
nsmallest
):
...
...
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