forked from tlake/data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_queue.py
62 lines (41 loc) · 1.4 KB
/
test_queue.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
#!/usr/bin/env python
from __future__ import unicode_literals
import pytest
from queue import Queue
@pytest.fixture()
def create_queue():
return Queue([1, 2, 3])
@pytest.fixture()
def create_empty_queue():
return Queue()
@pytest.fixture
def create_single_item_queue():
return Queue([1])
def test_dequeue(create_queue):
assert create_queue.dequeue() == 1
def test_dequeue_2(create_single_item_queue):
assert create_single_item_queue.dequeue() == 1
def test_enqueue(create_queue):
test_queue = create_queue
test_queue.enqueue(4)
assert test_queue.list.head.val == 4
def test_enqueue_to_empty_queue(create_empty_queue):
test_queue = create_empty_queue
test_queue.enqueue(1)
assert test_queue.list.head.val == 1
def test_dequeue_3(create_empty_queue):
with pytest.raises(IndexError):
test_queue = create_empty_queue
test_queue.dequeue()
def test_size(create_empty_queue, create_queue, create_single_item_queue):
test_empty_queue = create_empty_queue
test_create_queue = create_queue
test_create_single_item_queue = create_single_item_queue
assert test_empty_queue.size() == 0
assert test_create_queue.size() == 3
assert test_create_single_item_queue.size() == 1
def test_add_and_remove(create_empty_queue):
test_queue = create_empty_queue
test_queue.enqueue(4)
test_queue.dequeue()
assert test_queue.size() == 0