-
Notifications
You must be signed in to change notification settings - Fork 50
/
queue_test.py
72 lines (61 loc) · 1.7 KB
/
queue_test.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
69
70
71
72
#!python
from queue import Queue
import unittest
class QueueTest(unittest.TestCase):
def test_init(self):
q = Queue()
assert q.front() is None
assert q.length() == 0
assert q.is_empty() is True
def test_init_with_list(self):
q = Queue(['A', 'B', 'C'])
assert q.front() == 'A'
assert q.length() == 3
assert q.is_empty() is False
def test_length(self):
q = Queue()
assert q.length() == 0
q.enqueue('A')
assert q.length() == 1
q.enqueue('B')
assert q.length() == 2
q.dequeue()
assert q.length() == 1
q.dequeue()
assert q.length() == 0
def test_enqueue(self):
q = Queue()
q.enqueue('A')
assert q.front() == 'A'
assert q.length() == 1
q.enqueue('B')
assert q.front() == 'A'
assert q.length() == 2
q.enqueue('C')
assert q.front() == 'A'
assert q.length() == 3
assert q.is_empty() is False
def test_front(self):
q = Queue()
assert q.front() is None
q.enqueue('A')
assert q.front() == 'A'
q.enqueue('B')
assert q.front() == 'A'
q.dequeue()
assert q.front() == 'B'
q.dequeue()
assert q.front() is None
def test_dequeue(self):
q = Queue(['A', 'B', 'C'])
assert q.dequeue() == 'A'
assert q.length() == 2
assert q.dequeue() == 'B'
assert q.length() == 1
assert q.dequeue() == 'C'
assert q.length() == 0
assert q.is_empty() is True
with self.assertRaises(ValueError):
q.dequeue()
if __name__ == '__main__':
unittest.main()