Add tests for other future queues
This commit is contained in:
parent
ffe6a76241
commit
17b544f8bc
4 changed files with 269 additions and 6 deletions
|
@ -3,7 +3,7 @@ import pytest
|
|||
from pyority_queue import PureQueue
|
||||
|
||||
|
||||
type PureQueueInitializer = list[int | float] | tuple[int | float, ...]
|
||||
type PureQueueInitializer = list[float] | list[int] | tuple[float, ...] | tuple[int, ...]
|
||||
|
||||
|
||||
def test_empty_creation():
|
||||
|
@ -16,6 +16,7 @@ def test_creation(items: PureQueueInitializer):
|
|||
queue = PureQueue()
|
||||
assert len(queue) == len(items)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("items", ([], (0,), (-1, 3), range(100)))
|
||||
def test_iteration(items: PureQueueInitializer):
|
||||
queue = PureQueue(items)
|
||||
|
@ -36,8 +37,39 @@ def test_insertion():
|
|||
assert list(queue) == [0, 2, 3, 4, 6, 7, 8]
|
||||
|
||||
|
||||
def test_removal():
|
||||
queue = PureQueue[int]((4, 2, 8, 6))
|
||||
assert queue.pop() == 2
|
||||
assert queue.pop() == 4
|
||||
assert queue.pop() == 6
|
||||
assert queue.pop() == 8
|
||||
assert len(queue) == 0
|
||||
|
||||
|
||||
def test_mixed_removal():
|
||||
queue = PureQueue[int]((4, 2, 8, 6))
|
||||
assert queue.pop() == 2
|
||||
assert list(queue) == [4, 6, 8]
|
||||
|
||||
|
||||
def test_empty_removal():
|
||||
queue = PureQueue()
|
||||
with pytest.raises(IndexError):
|
||||
queue.pop()
|
||||
|
||||
|
||||
def test_duplicates():
|
||||
queue = PureQueue[int]((0, 0, 0, 5, 5))
|
||||
queue.insert(3)
|
||||
queue.insert(3)
|
||||
assert list(queue) == [0, 0, 0, 3, 3, 5, 5]
|
||||
|
||||
|
||||
def test_mixed_iteration():
|
||||
queue = PureQueue[int]((4, 2, 8, 6))
|
||||
results = []
|
||||
for number in queue:
|
||||
results.append(number)
|
||||
if len(queue):
|
||||
queue.insert(queue.pop() * 2)
|
||||
assert results == [2, 6, 8, 16]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue