forked from 2024-realcoding/week2_question
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
66 lines (49 loc) · 1.6 KB
/
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
import unittest
from priority_queue import PriorityQueue
class TestPriorityQueue(unittest.TestCase):
def test_priority_queue_push_pop(self):
pq = PriorityQueue()
pq.push("Task 1", 3)
pq.push("Task 2", 1)
pq.push("Task 3", 2)
self.assertEqual(pq.pop(), "Task 2")
self.assertEqual(pq.pop(), "Task 3")
self.assertEqual(pq.pop(), "Task 1")
self.assertIsNone(pq.pop())
def test_priority_queue_empty_pop(self):
pq = PriorityQueue()
self.assertIsNone(pq.pop())
def test_priority_queue_push_pop_order(self):
pq = PriorityQueue()
pq.push("Task 1", 3)
pq.push("Task 2", 1)
pq.push("Task 3", 2)
pq.push("Task 4", 4)
pq.push("Task 5", 0)
self.assertEqual(pq.pop(), "Task 5")
self.assertEqual(pq.pop(), "Task 2")
self.assertEqual(pq.pop(), "Task 3")
self.assertEqual(pq.pop(), "Task 1")
self.assertEqual(pq.pop(), "Task 4")
self.assertIsNone(pq.pop())
def test_priority_queue_duplicate_push_pop(self):
pq = PriorityQueue()
pq.push("Task 1", 3)
pq.push("Task 2", 1)
pq.push("Task 3", 2)
pq.push("Task 1", 4)
self.assertEqual(pq.pop(), "Task 2")
self.assertEqual(pq.pop(), "Task 3")
self.assertEqual(pq.pop(), "Task 1")
self.assertIsNotNone(pq.pop())
def test_priority_queue_negative_priority(self):
pq = PriorityQueue()
pq.push("Task 1", 3)
pq.push("Task 2", -1)
pq.push("Task 3", 2)
self.assertEqual(pq.pop(), "Task 2")
self.assertEqual(pq.pop(), "Task 3")
self.assertEqual(pq.pop(), "Task 1")
self.assertIsNone(pq.pop())
if __name__ == "__main__":
unittest.main()