-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ds.py
More file actions
43 lines (38 loc) · 939 Bytes
/
test_ds.py
File metadata and controls
43 lines (38 loc) · 939 Bytes
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
import pytest
from ds.dynamic_array import DynamicArray
from ds.stack import Stack
from ds.queue import RingBufferQueue
from ds.hashset import HashSet
def test_dynamic_array():
arr = DynamicArray()
arr.append(1)
arr.append(2)
assert arr[0] == 1
assert len(arr) == 2
assert arr.pop() == 2
def test_stack():
stack = Stack()
stack.push(1)
stack.push(2)
assert stack.pop() == 2
assert stack.peek() == 1
assert not stack.is_empty()
def test_queue():
queue = RingBufferQueue()
queue.enqueue(1)
queue.enqueue(2)
assert queue.dequeue() == 1
assert len(queue) == 1
def test_queue_resize():
queue = RingBufferQueue()
for i in range(10):
queue.enqueue(i)
for i in range(10):
assert queue.dequeue() == i
def test_hashset():
hs = HashSet()
hs.add(1)
hs.add(2)
assert hs.contains(1)
assert not hs.contains(3)
assert len(hs) == 2