Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
2175af30
Commit
2175af30
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
test for heap
parent
6fbf0c91
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
satella/coding/structures.py
+6
-2
6 additions, 2 deletions
satella/coding/structures.py
tests/test_coding/test_structures.py
+3
-2
3 additions, 2 deletions
tests/test_coding/test_structures.py
with
9 additions
and
4 deletions
satella/coding/structures.py
+
6
−
2
View file @
2175af30
...
@@ -227,6 +227,7 @@ class Heap(object):
...
@@ -227,6 +227,7 @@ class Heap(object):
def
__contains__
(
self
,
item
):
def
__contains__
(
self
,
item
):
return
item
in
self
.
heap
return
item
in
self
.
heap
class
TimeBasedHeap
(
Heap
):
class
TimeBasedHeap
(
Heap
):
"""
"""
A heap of items sorted by timestamps.
A heap of items sorted by timestamps.
...
@@ -240,6 +241,9 @@ class TimeBasedHeap(Heap):
...
@@ -240,6 +241,9 @@ class TimeBasedHeap(Heap):
#notthreadsafe
#notthreadsafe
"""
"""
def
__repr__
(
self
):
return
u
'
<satella.coding.TimeBasedHeap>
'
def
__init__
(
self
):
def
__init__
(
self
):
"""
"""
Initialize an empty heap
Initialize an empty heap
...
@@ -255,7 +259,7 @@ class TimeBasedHeap(Heap):
...
@@ -255,7 +259,7 @@ class TimeBasedHeap(Heap):
"""
"""
self
.
push
(
timestamp
,
item
)
self
.
push
(
timestamp
,
item
)
@typed
(
None
,
(
float
,
int
))
@typed
(
None
,
(
float
,
int
)
,
returns
=
list
)
def
pop_less_than
(
self
,
timestamp
):
def
pop_less_than
(
self
,
timestamp
):
"""
"""
Return a list of items with timestamps less than your value.
Return a list of items with timestamps less than your value.
...
@@ -269,5 +273,5 @@ class TimeBasedHeap(Heap):
...
@@ -269,5 +273,5 @@ class TimeBasedHeap(Heap):
"""
"""
Remove all things equal to item
Remove all things equal to item
"""
"""
self
.
filter
(
lambda
i
:
i
!=
item
)
self
.
filter
map
(
filter_fun
=
lambda
i
:
i
!=
item
)
This diff is collapsed.
Click to expand it.
tests/test_coding/test_structures.py
+
3
−
2
View file @
2175af30
...
@@ -25,7 +25,7 @@ class TestHeap(unittest.TestCase):
...
@@ -25,7 +25,7 @@ class TestHeap(unittest.TestCase):
def
test_tbh_iter
(
self
):
def
test_tbh_iter
(
self
):
tbh
=
Heap
([(
10
,
'
ala
'
),
(
20
,
'
ma
'
),
(
30
,
'
kota
'
),
(
5
,
'
yo
'
)])
tbh
=
Heap
([(
10
,
'
ala
'
),
(
20
,
'
ma
'
),
(
30
,
'
kota
'
),
(
5
,
'
yo
'
)])
self
.
assertEqual
([(
5
,
'
yo
'
),
(
10
,
'
ala
'
),
(
20
,
'
ma
'
),
(
30
,
'
kota
'
)],
list
(
tbh
.
iter_ascending
()))
self
.
assertEqual
([(
5
,
'
yo
'
),
(
10
,
'
ala
'
),
(
20
,
'
ma
'
),
(
30
,
'
kota
'
)],
list
(
tbh
.
iter_ascending
()))
self
.
assertEqual
(
reversed
([(
5
,
'
yo
'
),
(
10
,
'
ala
'
),
(
20
,
'
ma
'
),
(
30
,
'
kota
'
)]),
list
(
tbh
.
iter_descending
()))
self
.
assertEqual
(
reversed
([(
5
,
'
yo
'
),
(
10
,
'
ala
'
),
(
20
,
'
ma
'
),
(
30
,
'
kota
'
)]),
list
(
tbh
.
iter_descending
()))
...
@@ -41,7 +41,8 @@ class TestHeap(unittest.TestCase):
...
@@ -41,7 +41,8 @@ class TestHeap(unittest.TestCase):
self
.
assertIn
((
10
,
'
ala
'
),
tbh
)
self
.
assertIn
((
10
,
'
ala
'
),
tbh
)
self
.
assertIn
((
20
,
'
ma
'
),
tbh
)
self
.
assertIn
((
20
,
'
ma
'
),
tbh
)
tbh
.
filtermap
(
lambda
x
:
x
[
0
]
!=
20
,
lambda
x
:
x
[
0
]
+
10
,
'
azomg
'
)
tbh
.
filtermap
(
filter_fun
=
lambda
x
:
x
[
0
]
!=
20
,
map_fun
=
lambda
x
:
(
x
[
0
]
+
10
,
'
azomg
'
))
self
.
assertIn
((
20
,
'
azomg
'
),
tbh
)
self
.
assertIn
((
20
,
'
azomg
'
),
tbh
)
self
.
assertNotIn
((
10
,
'
ala
'
),
tbh
)
self
.
assertNotIn
((
10
,
'
ala
'
),
tbh
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment