-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_priority.py
61 lines (36 loc) · 927 Bytes
/
test_priority.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
import pytest
from priority import PriorityQueue
def test_add():
queue = PriorityQueue()
queue.add('two', 2)
queue.add('three', 3)
queue.add('one', 1)
item = queue.pop()
assert item == 'one'
def test_add_default_priority():
queue = PriorityQueue()
queue.add('one', 1)
queue.add('zero')
item = queue.pop()
assert item == 'zero'
def test_pop_empty():
queue = PriorityQueue()
with pytest.raises(KeyError):
queue.pop()
def test_bool_false():
queue = PriorityQueue()
assert not queue
def test_bool_true():
queue = PriorityQueue()
queue.add('foo')
assert queue
def test_change_priority():
queue = PriorityQueue()
queue.add('one', 3)
queue.add('two', 2)
queue.add('one', 1)
assert queue.pop() == 'one'
assert queue.pop() == 'two'
assert not queue
with pytest.raises(KeyError):
queue.pop()