forked from robertwhaskell/data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_binary_heap.py
68 lines (50 loc) · 1.13 KB
/
test_binary_heap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from binary_heap import Heap
import pytest
@pytest.fixture
def empty_heap():
h = Heap()
return h
@pytest.fixture
def full_heap():
h = Heap()
h.push(100)
h.push(19)
h.push(36)
h.push(17)
h.push(3)
h.push(25)
h.push(1)
h.push(2)
h.push(7)
return h
@pytest.fixture
def random_heap():
h = Heap()
h.push(10)
h.push(20)
h.push(2)
h.push(100)
h.push(150)
return h
def test_heap():
h = Heap()
assert h.heap_list[0] == 0
def test_iter_heap():
l = [100, 19, 36, 17, 3, 25, 1, 2, 7]
h = Heap(l)
assert h.heap_list[1] == 100
def test_random_heap(random_heap):
assert random_heap.heap_list == [0, 150, 100, 2, 10, 20]
def test_push(empty_heap):
empty_heap.push(25)
assert empty_heap.heap_list[1] == 25
empty_heap.push(50)
assert empty_heap.heap_list[1] == 50
assert empty_heap.heap_list[2] == 25
def test_pop(full_heap):
assert full_heap.pop() == 100
assert full_heap.pop() == 36
assert full_heap.pop() == 25
def test_pop_from_empty_heap(empty_heap):
with pytest.raises(IndexError):
empty_heap.pop()