]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/mw/util/tests/test_heap.py
Initial commit
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / mw / util / tests / test_heap.py
1 from nose.tools import eq_
2
3 from ..heap import Heap
4
5
6 def test_heap():
7     h = Heap([5, 4, 7, 8, 2])
8     eq_(h.pop(), 2)
9     eq_(h.pop(), 4)
10     eq_(h.pop(), 5)
11     eq_(h.pop(), 7)
12     eq_(h.pop(), 8)
13     eq_(len(h), 0)
14
15     h = Heap([10, 20, 100])
16     eq_(h.pop(), 10)
17     h.push(30)
18     eq_(len(h), 3)
19     eq_(h.pop(), 20)
20     eq_(h.pop(), 30)
21     eq_(h.pop(), 100)
22     eq_(len(h), 0)
23
24     h = Heap([(1, 7), (2, 4), (10, -100)])
25     eq_(h.peek(), (1, 7))
26     h.pop()
27     eq_(h.pop(), (2, 4))
28     eq_(h.pop(), (10, -100))

Community Data Science Collective || Want to submit a patch?