Skip to content

Remove useless code in doctests #7733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backtracking/hamiltonian_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
>>> curr_ind = 1
>>> util_hamilton_cycle(graph, path, curr_ind)
True
>>> print(path)
>>> path
[0, 1, 2, 4, 3, 0]

Case 2: Use exact graph as in previous case, but in the properties taken from
Expand All @@ -85,7 +85,7 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
>>> curr_ind = 3
>>> util_hamilton_cycle(graph, path, curr_ind)
True
>>> print(path)
>>> path
[0, 1, 2, 4, 3, 0]
"""

Expand Down
3 changes: 0 additions & 3 deletions computer_vision/flip_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def main() -> None:
Get images list and annotations list from input dir.
Update new images and annotations.
Save images and annotations in output dir.
>>> pass # A doctest is not possible for this function.
"""
img_paths, annos = get_dataset(LABEL_DIR, IMAGE_DIR)
print("Processing...")
Expand All @@ -48,7 +47,6 @@ def get_dataset(label_dir: str, img_dir: str) -> tuple[list, list]:
- label_dir <type: str>: Path to label include annotation of images
- img_dir <type: str>: Path to folder contain images
Return <type: list>: List of images path and labels
>>> pass # A doctest is not possible for this function.
"""
img_paths = []
labels = []
Expand Down Expand Up @@ -88,7 +86,6 @@ def update_image_and_anno(
- new_imgs_list <type: narray>: image after resize
- new_annos_lists <type: list>: list of new annotation after scale
- path_list <type: list>: list the name of image file
>>> pass # A doctest is not possible for this function.
"""
new_annos_lists = []
path_list = []
Expand Down
3 changes: 0 additions & 3 deletions computer_vision/mosaic_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def main() -> None:
Get images list and annotations list from input dir.
Update new images and annotations.
Save images and annotations in output dir.
>>> pass # A doctest is not possible for this function.
"""
img_paths, annos = get_dataset(LABEL_DIR, IMG_DIR)
for index in range(NUMBER_IMAGES):
Expand Down Expand Up @@ -60,7 +59,6 @@ def get_dataset(label_dir: str, img_dir: str) -> tuple[list, list]:
- label_dir <type: str>: Path to label include annotation of images
- img_dir <type: str>: Path to folder contain images
Return <type: list>: List of images path and labels
>>> pass # A doctest is not possible for this function.
"""
img_paths = []
labels = []
Expand Down Expand Up @@ -105,7 +103,6 @@ def update_image_and_anno(
- output_img <type: narray>: image after resize
- new_anno <type: list>: list of new annotation after scale
- path[0] <type: string>: get the name of image file
>>> pass # A doctest is not possible for this function.
"""
output_img = np.zeros([output_size[0], output_size[1], 3], dtype=np.uint8)
scale_x = scale_range[0] + random.random() * (scale_range[1] - scale_range[0])
Expand Down
4 changes: 2 additions & 2 deletions data_structures/heap/binomial_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class BinomialHeap:
... first_heap.insert(number)

Size test
>>> print(first_heap.size)
>>> first_heap.size
30

Deleting - delete() test
Expand All @@ -97,7 +97,7 @@ class BinomialHeap:
# # # #

preOrder() test
>>> print(second_heap.preOrder())
>>> second_heap.preOrder()
[(17, 0), ('#', 1), (31, 1), (20, 2), ('#', 3), ('#', 3), (34, 2), ('#', 3), ('#', 3)]

printing Heap - __str__() test
Expand Down
8 changes: 4 additions & 4 deletions data_structures/heap/heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ class Heap:
>>> unsorted = [103, 9, 1, 7, 11, 15, 25, 201, 209, 107, 5]
>>> h = Heap()
>>> h.build_max_heap(unsorted)
>>> print(h)
>>> h
[209, 201, 25, 103, 107, 15, 1, 9, 7, 11, 5]
>>>
>>> h.extract_max()
209
>>> print(h)
>>> h
[201, 107, 25, 103, 11, 15, 1, 9, 7, 5]
>>>
>>> h.insert(100)
>>> print(h)
>>> h
[201, 107, 25, 103, 100, 15, 1, 9, 7, 5, 11]
>>>
>>> h.heap_sort()
>>> print(h)
>>> h
[1, 5, 7, 9, 11, 15, 25, 100, 103, 107, 201]
"""

Expand Down
2 changes: 1 addition & 1 deletion data_structures/heap/min_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MinHeap:
>>> myMinHeap.decrease_key(b, -17)
>>> print(b)
Node(B, -17)
>>> print(myMinHeap["B"])
>>> myMinHeap["B"]
-17
"""

Expand Down
3 changes: 3 additions & 0 deletions data_structures/linked_list/skip_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,7 @@ def main():


if __name__ == "__main__":
import doctest

doctest.testmod()
main()
2 changes: 1 addition & 1 deletion graphs/gale_shapley_bigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def stable_matching(

>>> donor_pref = [[0, 1, 3, 2], [0, 2, 3, 1], [1, 0, 2, 3], [0, 3, 1, 2]]
>>> recipient_pref = [[3, 1, 2, 0], [3, 1, 0, 2], [0, 3, 1, 2], [1, 0, 3, 2]]
>>> print(stable_matching(donor_pref, recipient_pref))
>>> stable_matching(donor_pref, recipient_pref)
[1, 2, 3, 0]
"""
assert len(donor_pref) == len(recipient_pref)
Expand Down
6 changes: 3 additions & 3 deletions graphs/graph_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class GraphAdjacencyList(Generic[T]):

Directed graph example:
>>> d_graph = GraphAdjacencyList()
>>> d_graph
>>> print(d_graph)
{}
>>> d_graph.add_edge(0, 1)
{0: [1], 1: []}
>>> d_graph.add_edge(1, 2).add_edge(1, 4).add_edge(1, 5)
{0: [1], 1: [2, 4, 5], 2: [], 4: [], 5: []}
>>> d_graph.add_edge(2, 0).add_edge(2, 6).add_edge(2, 7)
{0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []}
>>> print(d_graph)
>>> d_graph
{0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []}
>>> print(repr(d_graph))
{0: [1], 1: [2, 4, 5], 2: [0, 6, 7], 4: [], 5: [], 6: [], 7: []}
Expand Down Expand Up @@ -68,7 +68,7 @@ class GraphAdjacencyList(Generic[T]):
{'a': ['b'], 'b': ['a']}
>>> char_graph.add_edge('b', 'c').add_edge('b', 'e').add_edge('b', 'f')
{'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']}
>>> print(char_graph)
>>> char_graph
{'a': ['b'], 'b': ['a', 'c', 'e', 'f'], 'c': ['b'], 'e': ['b'], 'f': ['b']}
"""

Expand Down
8 changes: 4 additions & 4 deletions graphs/minimum_spanning_tree_prims2.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ class MinPriorityQueue(Generic[T]):
>>> queue.push(3, 4000)
>>> queue.push(4, 3000)

>>> print(queue.extract_min())
>>> queue.extract_min()
2

>>> queue.update_key(4, 50)

>>> print(queue.extract_min())
>>> queue.extract_min()
4
>>> print(queue.extract_min())
>>> queue.extract_min()
1
>>> print(queue.extract_min())
>>> queue.extract_min()
3
"""

Expand Down
2 changes: 1 addition & 1 deletion graphs/random_graph_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def complete_graph(vertices_number: int) -> dict:
@input: vertices_number (number of vertices),
directed (False if the graph is undirected, True otherwise)
@example:
>>> print(complete_graph(3))
>>> complete_graph(3)
{0: [1, 2], 1: [0, 2], 2: [0, 1]}
"""
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def local_weight_regression(
def load_data(dataset_name: str, cola_name: str, colb_name: str) -> np.mat:
"""
Function used for loading data from the seaborn splitting into x and y points
>>> pass # this function has no doctest
"""
import seaborn as sns

Expand Down Expand Up @@ -112,7 +111,6 @@ def plot_preds(
) -> plt.plot:
"""
This function used to plot predictions and display the graph
>>> pass #this function has no doctest
"""
xsort = training_data_x.copy()
xsort.sort(axis=0)
Expand Down
2 changes: 1 addition & 1 deletion maths/polynomial_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def horner(poly: Sequence[float], x: float) -> float:
>>> poly = (0.0, 0.0, 5.0, 9.3, 7.0) # f(x) = 7.0x^4 + 9.3x^3 + 5.0x^2
>>> x = -13.0
>>> # f(-13) = 7.0(-13)^4 + 9.3(-13)^3 + 5.0(-13)^2 = 180339.9
>>> print(evaluate_poly(poly, x))
>>> evaluate_poly(poly, x)
180339.9
"""
poly = (0.0, 0.0, 5.0, 9.3, 7.0)
Expand Down
2 changes: 1 addition & 1 deletion maths/radix2_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FFT:
>>> x = FFT(A, B)

Print product
>>> print(x.product) # 2x + 3x^2 + 8x^3 + 4x^4 + 6x^5
>>> x.product # 2x + 3x^2 + 8x^3 + 4x^4 + 6x^5
[(-0+0j), (2+0j), (3+0j), (8+0j), (6+0j), (8+0j)]

__str__ test
Expand Down
6 changes: 3 additions & 3 deletions matrix/matrix_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class Matrix:
[7. 8. 9.]]

Matrix rows and columns are available as 2D arrays
>>> print(matrix.rows)
>>> matrix.rows
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> print(matrix.columns())
>>> matrix.columns()
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]

Order is returned as a tuple
Expand Down Expand Up @@ -55,7 +55,7 @@ class Matrix:
[[-3. 6. -3.]
[6. -12. 6.]
[-3. 6. -3.]]
>>> print(matrix.inverse())
>>> matrix.inverse()
Traceback (most recent call last):
...
TypeError: Only matrices with a non-zero determinant have an inverse
Expand Down
20 changes: 10 additions & 10 deletions searches/simple_binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
def binary_search(a_list: list[int], item: int) -> bool:
"""
>>> test_list = [0, 1, 2, 8, 13, 17, 19, 32, 42]
>>> print(binary_search(test_list, 3))
>>> binary_search(test_list, 3)
False
>>> print(binary_search(test_list, 13))
>>> binary_search(test_list, 13)
True
>>> print(binary_search([4, 4, 5, 6, 7], 4))
>>> binary_search([4, 4, 5, 6, 7], 4)
True
>>> print(binary_search([4, 4, 5, 6, 7], -10))
>>> binary_search([4, 4, 5, 6, 7], -10)
False
>>> print(binary_search([-18, 2], -18))
>>> binary_search([-18, 2], -18)
True
>>> print(binary_search([5], 5))
>>> binary_search([5], 5)
True
>>> print(binary_search(['a', 'c', 'd'], 'c'))
>>> binary_search(['a', 'c', 'd'], 'c')
True
>>> print(binary_search(['a', 'c', 'd'], 'f'))
>>> binary_search(['a', 'c', 'd'], 'f')
False
>>> print(binary_search([], 1))
>>> binary_search([], 1)
False
>>> print(binary_search([-.1, .1 , .8], .1))
>>> binary_search([-.1, .1 , .8], .1)
True
>>> binary_search(range(-5000, 5000, 10), 80)
True
Expand Down
12 changes: 6 additions & 6 deletions sorts/bitonic_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ def comp_and_swap(array: list[int], index1: int, index2: int, direction: int) ->

>>> arr = [12, 42, -21, 1]
>>> comp_and_swap(arr, 1, 2, 1)
>>> print(arr)
>>> arr
[12, -21, 42, 1]

>>> comp_and_swap(arr, 1, 2, 0)
>>> print(arr)
>>> arr
[12, 42, -21, 1]

>>> comp_and_swap(arr, 0, 3, 1)
>>> print(arr)
>>> arr
[1, 42, -21, 12]

>>> comp_and_swap(arr, 0, 3, 0)
>>> print(arr)
>>> arr
[12, 42, -21, 1]
"""
if (direction == 1 and array[index1] > array[index2]) or (
Expand All @@ -46,11 +46,11 @@ def bitonic_merge(array: list[int], low: int, length: int, direction: int) -> No

>>> arr = [12, 42, -21, 1]
>>> bitonic_merge(arr, 0, 4, 1)
>>> print(arr)
>>> arr
[-21, 1, 12, 42]

>>> bitonic_merge(arr, 0, 4, 0)
>>> print(arr)
>>> arr
[42, 12, 1, -21]
"""
if length > 1:
Expand Down
4 changes: 2 additions & 2 deletions sorts/normal_distribution_quick_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ The array elements are taken from a Standard Normal Distribution, having mean =
>>> mu, sigma = 0, 1 # mean and standard deviation
>>> X = np.random.normal(mu, sigma, p)
>>> np.save(outfile, X)
>>> print('The array is')
>>> print(X)
>>> 'The array is'
>>> X

```

Expand Down
12 changes: 6 additions & 6 deletions sorts/recursive_insertion_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def rec_insertion_sort(collection: list, n: int):

>>> col = [1, 2, 1]
>>> rec_insertion_sort(col, len(col))
>>> print(col)
>>> col
[1, 1, 2]

>>> col = [2, 1, 0, -1, -2]
>>> rec_insertion_sort(col, len(col))
>>> print(col)
>>> col
[-2, -1, 0, 1, 2]

>>> col = [1]
>>> rec_insertion_sort(col, len(col))
>>> print(col)
>>> col
[1]
"""
# Checks if the entire collection has been sorted
Expand All @@ -41,17 +41,17 @@ def insert_next(collection: list, index: int):

>>> col = [3, 2, 4, 2]
>>> insert_next(col, 1)
>>> print(col)
>>> col
[2, 3, 4, 2]

>>> col = [3, 2, 3]
>>> insert_next(col, 2)
>>> print(col)
>>> col
[3, 2, 3]

>>> col = []
>>> insert_next(col, 1)
>>> print(col)
>>> col
[]
"""
# Checks order between adjacent elements
Expand Down
2 changes: 0 additions & 2 deletions web_programming/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def get_subreddit_data(
limit : Number of posts to fetch
age : ["new", "top", "hot"]
wanted_data : Get only the required data in the list

>>> pass
"""
wanted_data = wanted_data or []
if invalid_search_terms := ", ".join(sorted(set(wanted_data) - valid_terms)):
Expand Down
Loading