Skip to content

Commit 2ddbfce

Browse files
authored
Merge branch 'master' into issue-2-knn-distance
2 parents 003422b + e2a78d4 commit 2ddbfce

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

data_structures/queues/circular_queue.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __len__(self) -> int:
1717
>>> len(cq)
1818
0
1919
>>> cq.enqueue("A") # doctest: +ELLIPSIS
20-
<data_structures.queues.circular_queue.CircularQueue object at ...
20+
<data_structures.queues.circular_queue.CircularQueue object at ...>
2121
>>> cq.array
2222
['A', None, None, None, None]
2323
>>> len(cq)
@@ -51,17 +51,24 @@ def enqueue(self, data):
5151
"""
5252
This function inserts an element at the end of the queue using self.rear value
5353
as an index.
54+
5455
>>> cq = CircularQueue(5)
5556
>>> cq.enqueue("A") # doctest: +ELLIPSIS
56-
<data_structures.queues.circular_queue.CircularQueue object at ...
57+
<data_structures.queues.circular_queue.CircularQueue object at ...>
5758
>>> (cq.size, cq.first())
5859
(1, 'A')
5960
>>> cq.enqueue("B") # doctest: +ELLIPSIS
60-
<data_structures.queues.circular_queue.CircularQueue object at ...
61+
<data_structures.queues.circular_queue.CircularQueue object at ...>
6162
>>> cq.array
6263
['A', 'B', None, None, None]
6364
>>> (cq.size, cq.first())
6465
(2, 'A')
66+
>>> cq.enqueue("C").enqueue("D").enqueue("E") # doctest: +ELLIPSIS
67+
<data_structures.queues.circular_queue.CircularQueue object at ...>
68+
>>> cq.enqueue("F")
69+
Traceback (most recent call last):
70+
...
71+
Exception: QUEUE IS FULL
6572
"""
6673
if self.size >= self.n:
6774
raise Exception("QUEUE IS FULL")
@@ -75,6 +82,7 @@ def dequeue(self):
7582
"""
7683
This function removes an element from the queue using on self.front value as an
7784
index and returns it
85+
7886
>>> cq = CircularQueue(5)
7987
>>> cq.dequeue()
8088
Traceback (most recent call last):

graphs/graph_adjacency_list.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def add_vertex(self, vertex: T) -> None:
6161
"""
6262
Adds a vertex to the graph. If the given vertex already exists,
6363
a ValueError will be thrown.
64+
65+
>>> g = GraphAdjacencyList(vertices=[], edges=[], directed=False)
66+
>>> g.add_vertex("A")
67+
>>> g.adj_list
68+
{'A': []}
69+
>>> g.add_vertex("A")
70+
Traceback (most recent call last):
71+
...
72+
ValueError: Incorrect input: A is already in the graph.
6473
"""
6574
if self.contains_vertex(vertex):
6675
msg = f"Incorrect input: {vertex} is already in the graph."

machine_learning/apriori_algorithm.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Examples: https://www.kaggle.com/code/earthian/apriori-association-rules-mining
1212
"""
1313

14+
from collections import Counter
1415
from itertools import combinations
1516

1617

@@ -44,11 +45,16 @@ def prune(itemset: list, candidates: list, length: int) -> list:
4445
>>> prune(itemset, candidates, 3)
4546
[]
4647
"""
48+
itemset_counter = Counter(tuple(item) for item in itemset)
4749
pruned = []
4850
for candidate in candidates:
4951
is_subsequence = True
5052
for item in candidate:
51-
if item not in itemset or itemset.count(item) < length - 1:
53+
item_tuple = tuple(item)
54+
if (
55+
item_tuple not in itemset_counter
56+
or itemset_counter[item_tuple] < length - 1
57+
):
5258
is_subsequence = False
5359
break
5460
if is_subsequence:

maths/test_factorial.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ def test_negative_number(function):
3333
function(-3)
3434

3535

36+
@pytest.mark.parametrize("function", [factorial, factorial_recursive])
37+
def test_float_number(function):
38+
with pytest.raises(ValueError):
39+
function(1.5)
40+
41+
3642
if __name__ == "__main__":
3743
pytest.main(["-v", __file__])

0 commit comments

Comments
 (0)