Skip to content

Commit 61eedc1

Browse files
Remove useless code in doctests (TheAlgorithms#7733)
* refactor: Fix matrix display deprecation * refactor: Remove useless `print` and `pass` statements * revert: Replace broken doctests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * revert: Fix failing doctests * chore: Satisfy pre-commit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 501a1cf commit 61eedc1

21 files changed

+51
-61
lines changed

backtracking/hamiltonian_cycle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
7171
>>> curr_ind = 1
7272
>>> util_hamilton_cycle(graph, path, curr_ind)
7373
True
74-
>>> print(path)
74+
>>> path
7575
[0, 1, 2, 4, 3, 0]
7676
7777
Case 2: Use exact graph as in previous case, but in the properties taken from
@@ -85,7 +85,7 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
8585
>>> curr_ind = 3
8686
>>> util_hamilton_cycle(graph, path, curr_ind)
8787
True
88-
>>> print(path)
88+
>>> path
8989
[0, 1, 2, 4, 3, 0]
9090
"""
9191

computer_vision/flip_augmentation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def main() -> None:
2222
Get images list and annotations list from input dir.
2323
Update new images and annotations.
2424
Save images and annotations in output dir.
25-
>>> pass # A doctest is not possible for this function.
2625
"""
2726
img_paths, annos = get_dataset(LABEL_DIR, IMAGE_DIR)
2827
print("Processing...")
@@ -48,7 +47,6 @@ def get_dataset(label_dir: str, img_dir: str) -> tuple[list, list]:
4847
- label_dir <type: str>: Path to label include annotation of images
4948
- img_dir <type: str>: Path to folder contain images
5049
Return <type: list>: List of images path and labels
51-
>>> pass # A doctest is not possible for this function.
5250
"""
5351
img_paths = []
5452
labels = []
@@ -88,7 +86,6 @@ def update_image_and_anno(
8886
- new_imgs_list <type: narray>: image after resize
8987
- new_annos_lists <type: list>: list of new annotation after scale
9088
- path_list <type: list>: list the name of image file
91-
>>> pass # A doctest is not possible for this function.
9289
"""
9390
new_annos_lists = []
9491
path_list = []

computer_vision/mosaic_augmentation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def main() -> None:
2323
Get images list and annotations list from input dir.
2424
Update new images and annotations.
2525
Save images and annotations in output dir.
26-
>>> pass # A doctest is not possible for this function.
2726
"""
2827
img_paths, annos = get_dataset(LABEL_DIR, IMG_DIR)
2928
for index in range(NUMBER_IMAGES):
@@ -60,7 +59,6 @@ def get_dataset(label_dir: str, img_dir: str) -> tuple[list, list]:
6059
- label_dir <type: str>: Path to label include annotation of images
6160
- img_dir <type: str>: Path to folder contain images
6261
Return <type: list>: List of images path and labels
63-
>>> pass # A doctest is not possible for this function.
6462
"""
6563
img_paths = []
6664
labels = []
@@ -105,7 +103,6 @@ def update_image_and_anno(
105103
- output_img <type: narray>: image after resize
106104
- new_anno <type: list>: list of new annotation after scale
107105
- path[0] <type: string>: get the name of image file
108-
>>> pass # A doctest is not possible for this function.
109106
"""
110107
output_img = np.zeros([output_size[0], output_size[1], 3], dtype=np.uint8)
111108
scale_x = scale_range[0] + random.random() * (scale_range[1] - scale_range[0])

data_structures/heap/binomial_heap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class BinomialHeap:
7171
... first_heap.insert(number)
7272
7373
Size test
74-
>>> print(first_heap.size)
74+
>>> first_heap.size
7575
30
7676
7777
Deleting - delete() test
@@ -97,7 +97,7 @@ class BinomialHeap:
9797
# # # #
9898
9999
preOrder() test
100-
>>> print(second_heap.preOrder())
100+
>>> second_heap.preOrder()
101101
[(17, 0), ('#', 1), (31, 1), (20, 2), ('#', 3), ('#', 3), (34, 2), ('#', 3), ('#', 3)]
102102
103103
printing Heap - __str__() test

data_structures/heap/heap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ class Heap:
99
>>> unsorted = [103, 9, 1, 7, 11, 15, 25, 201, 209, 107, 5]
1010
>>> h = Heap()
1111
>>> h.build_max_heap(unsorted)
12-
>>> print(h)
12+
>>> h
1313
[209, 201, 25, 103, 107, 15, 1, 9, 7, 11, 5]
1414
>>>
1515
>>> h.extract_max()
1616
209
17-
>>> print(h)
17+
>>> h
1818
[201, 107, 25, 103, 11, 15, 1, 9, 7, 5]
1919
>>>
2020
>>> h.insert(100)
21-
>>> print(h)
21+
>>> h
2222
[201, 107, 25, 103, 100, 15, 1, 9, 7, 5, 11]
2323
>>>
2424
>>> h.heap_sort()
25-
>>> print(h)
25+
>>> h
2626
[1, 5, 7, 9, 11, 15, 25, 100, 103, 107, 201]
2727
"""
2828

data_structures/heap/min_heap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MinHeap:
2727
>>> myMinHeap.decrease_key(b, -17)
2828
>>> print(b)
2929
Node(B, -17)
30-
>>> print(myMinHeap["B"])
30+
>>> myMinHeap["B"]
3131
-17
3232
"""
3333

data_structures/linked_list/skip_list.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,7 @@ def main():
443443

444444

445445
if __name__ == "__main__":
446+
import doctest
447+
448+
doctest.testmod()
446449
main()

graphs/gale_shapley_bigraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def stable_matching(
1717
1818
>>> donor_pref = [[0, 1, 3, 2], [0, 2, 3, 1], [1, 0, 2, 3], [0, 3, 1, 2]]
1919
>>> recipient_pref = [[3, 1, 2, 0], [3, 1, 0, 2], [0, 3, 1, 2], [1, 0, 3, 2]]
20-
>>> print(stable_matching(donor_pref, recipient_pref))
20+
>>> stable_matching(donor_pref, recipient_pref)
2121
[1, 2, 3, 0]
2222
"""
2323
assert len(donor_pref) == len(recipient_pref)

graphs/graph_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class GraphAdjacencyList(Generic[T]):
1818
1919
Directed graph example:
2020
>>> d_graph = GraphAdjacencyList()
21-
>>> d_graph
21+
>>> print(d_graph)
2222
{}
2323
>>> d_graph.add_edge(0, 1)
2424
{0: [1], 1: []}
2525
>>> d_graph.add_edge(1, 2).add_edge(1, 4).add_edge(1, 5)
2626
{0: [1], 1: [2, 4, 5], 2: [], 4: [], 5: []}
2727
>>> d_graph.add_edge(2, 0).add_edge(2, 6).add_edge(2, 7)
2828
{0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []}
29-
>>> print(d_graph)
29+
>>> d_graph
3030
{0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []}
3131
>>> print(repr(d_graph))
3232
{0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []}
@@ -68,7 +68,7 @@ class GraphAdjacencyList(Generic[T]):
6868
{'a': ['b'], 'b': ['a']}
6969
>>> char_graph.add_edge('b', 'c').add_edge('b', 'e').add_edge('b', 'f')
7070
{'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']}
71-
>>> print(char_graph)
71+
>>> char_graph
7272
{'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']}
7373
"""
7474

graphs/minimum_spanning_tree_prims2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ class MinPriorityQueue(Generic[T]):
6969
>>> queue.push(3, 4000)
7070
>>> queue.push(4, 3000)
7171
72-
>>> print(queue.extract_min())
72+
>>> queue.extract_min()
7373
2
7474
7575
>>> queue.update_key(4, 50)
7676
77-
>>> print(queue.extract_min())
77+
>>> queue.extract_min()
7878
4
79-
>>> print(queue.extract_min())
79+
>>> queue.extract_min()
8080
1
81-
>>> print(queue.extract_min())
81+
>>> queue.extract_min()
8282
3
8383
"""
8484

0 commit comments

Comments
 (0)