Skip to content

Commit e32755d

Browse files
committed
test: cover topological sort edge cases
1 parent 6e03a48 commit e32755d

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎graphs/kahns_algorithm_topo.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ def topological_sort(graph: dict[int, list[int]]) -> list[int] | None:
3131
3232
>>> sparse_cycle = {10: [20], 20: [10]}
3333
>>> topological_sort(sparse_cycle)
34+
35+
>>> topological_sort({})
36+
[]
37+
>>> topological_sort({42: []})
38+
[42]
39+
>>> order = topological_sort({10: [20], 20: [], 30: [40], 40: []})
40+
>>> sorted(order)
41+
[10, 20, 30, 40]
42+
>>> order.index(10) < order.index(20) and order.index(30) < order.index(40)
43+
True
44+
>>> topological_sort({7: [7]}) is None
45+
True
3446
"""
3547

3648
indegree = dict.fromkeys(graph, 0)

0 commit comments

Comments
 (0)