Fix mypy errors at mst_kruskal (#4581)

This commit is contained in:
Hasanul Islam 2021-08-02 18:40:48 +06:00 committed by GitHub
parent a5bcf0f674
commit da71184b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -1,15 +1,14 @@
from typing import List, Tuple def kruskal(
num_nodes: int, edges: list[tuple[int, int, int]]
) -> list[tuple[int, int, int]]:
def kruskal(num_nodes: int, num_edges: int, edges: List[Tuple[int, int, int]]) -> int:
""" """
>>> kruskal(4, 3, [(0, 1, 3), (1, 2, 5), (2, 3, 1)]) >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1)])
[(2, 3, 1), (0, 1, 3), (1, 2, 5)] [(2, 3, 1), (0, 1, 3), (1, 2, 5)]
>>> kruskal(4, 5, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2)]) >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2)])
[(2, 3, 1), (0, 2, 1), (0, 1, 3)] [(2, 3, 1), (0, 2, 1), (0, 1, 3)]
>>> kruskal(4, 6, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2), >>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2),
... (2, 1, 1)]) ... (2, 1, 1)])
[(2, 3, 1), (0, 2, 1), (2, 1, 1)] [(2, 3, 1), (0, 2, 1), (2, 1, 1)]
""" """
@ -44,4 +43,4 @@ if __name__ == "__main__": # pragma: no cover
node1, node2, cost = [int(x) for x in input().strip().split()] node1, node2, cost = [int(x) for x in input().strip().split()]
edges.append((node1, node2, cost)) edges.append((node1, node2, cost))
kruskal(num_nodes, num_edges, edges) kruskal(num_nodes, edges)

View File

@ -2,7 +2,7 @@ from graphs.minimum_spanning_tree_kruskal import kruskal
def test_kruskal_successful_result(): def test_kruskal_successful_result():
num_nodes, num_edges = 9, 14 num_nodes = 9
edges = [ edges = [
[0, 1, 4], [0, 1, 4],
[0, 7, 8], [0, 7, 8],
@ -20,7 +20,7 @@ def test_kruskal_successful_result():
[1, 7, 11], [1, 7, 11],
] ]
result = kruskal(num_nodes, num_edges, edges) result = kruskal(num_nodes, edges)
expected = [ expected = [
[7, 6, 1], [7, 6, 1],