Skip to content

Commit 3fa277d

Browse files
committed
Remove doctests and use example-based documentation for CI compatibility
1 parent b0c4729 commit 3fa277d

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

data_structures/sort/topological_sort.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pytest: disable=doctest
21
"""
32
Topological Sort implementation using:
43
1. DFS-based approach
@@ -21,13 +20,6 @@ def _dfs(
2120
) -> None:
2221
"""
2322
Helper DFS function for topological sorting.
24-
25-
>>> graph = [[1], [], []]
26-
>>> visited = [0, 0, 0]
27-
>>> result = []
28-
>>> _dfs(0, graph, visited, result)
29-
>>> result
30-
[0]
3123
"""
3224
if visited[node] == 1:
3325
raise ValueError("Graph contains a cycle")
@@ -45,16 +37,10 @@ def topological_sort_dfs(vertices: int, edges: list[list[int]]) -> list[int]:
4537
"""
4638
Perform topological sort using DFS.
4739
48-
>>> order = topological_sort_dfs(
49-
... 6, [[5, 2], [5, 0], [4, 0], [4, 1], [2, 3], [3, 1]]
50-
... )
51-
>>> len(order) == 6
52-
True
53-
54-
>>> topological_sort_dfs(2, [[0, 1], [1, 0]])
55-
Traceback (most recent call last):
56-
...
57-
ValueError: Graph contains a cycle
40+
Example:
41+
vertices = 6
42+
edges = [[5, 2], [5, 0], [4, 0], [4, 1], [2, 3], [3, 1]]
43+
order = topological_sort_dfs(vertices, edges)
5844
"""
5945
graph: list[list[int]] = [[] for _ in range(vertices)]
6046
for u, v in edges:
@@ -74,16 +60,10 @@ def topological_sort_kahn(vertices: int, edges: list[list[int]]) -> list[int]:
7460
"""
7561
Perform topological sort using Kahn's Algorithm.
7662
77-
>>> order = topological_sort_kahn(
78-
... 6, [[5, 2], [5, 0], [4, 0], [4, 1], [2, 3], [3, 1]]
79-
... )
80-
>>> len(order) == 6
81-
True
82-
83-
>>> topological_sort_kahn(2, [[0, 1], [1, 0]])
84-
Traceback (most recent call last):
85-
...
86-
ValueError: Graph contains a cycle
63+
Example:
64+
vertices = 6
65+
edges = [[5, 2], [5, 0], [4, 0], [4, 1], [2, 3], [3, 1]]
66+
order = topological_sort_kahn(vertices, edges)
8767
"""
8868
graph: list[list[int]] = [[] for _ in range(vertices)]
8969
in_degree = [0] * vertices

0 commit comments

Comments
 (0)