changing pytest

This commit is contained in:
Ajmera, Mahita SI/HZR-IDSA 2024-10-17 11:26:52 +02:00
parent e1eb17e83e
commit 8be7753175
2 changed files with 10 additions and 25 deletions

View File

@ -33,17 +33,16 @@ def floyd_warshall(graph, v):
updated to the next vertex[i][k]. updated to the next vertex[i][k].
>>> num_vertices = 3
>>> graph = [ >>> graph = [
... [float('inf'), float('inf'), float('inf')], ... [0, 3, float('inf')],
... [float('inf'), float('inf'), float('inf')], ... [2, 0, float('inf')],
... [float('inf'), float('inf'), float('inf')] ... [float('inf'), 7, 0]
... ] ... ]
>>> expected = [ >>> expected = [
... [0, 2, float('inf')], ... [0, 3, float('inf')],
... [1, 0, float('inf')], ... [2, 0, float('inf')],
... [float('inf'), float('inf'), 0] ... [9, 7, 0]
... ] ... ]
>>> dist, _ = floyd_warshall(graph, num_vertices) >>> dist, _ = floyd_warshall(graph, num_vertices)
>>> dist == expected >>> dist == expected

View File

@ -18,24 +18,10 @@ def test_no_edges():
assert dist == expected assert dist == expected
def test_example_input(capsys): def test_with_edges():
num_vertices = 3 graph = [[0, 3, float("inf")], [2, 0, float("inf")], [float("inf"), 7, 0]]
graph = [ expected = [[0, 3, float("inf")], [2, 0, float("inf")], [9, 7, 0]]
[float("inf"), float("inf"), float("inf")], dist, _ = floyd_warshall(graph, 3)
[float("inf"), float("inf"), float("inf")],
[float("inf"), float("inf"), float("inf")],
]
for i in range(num_vertices):
graph[i][i] = 0.0
graph[0][1] = 2
graph[1][0] = 1
expected = [
[0, 2, float("inf")],
[1, 0, float("inf")],
[float("inf"), float("inf"), 0],
]
dist, _ = floyd_warshall(graph, num_vertices)
_ = capsys.readouterr()
assert dist == expected assert dist == expected