Skip to content
Extraits de code Groupes Projets
Valider 21ccf795 rédigé par Louis Navarre's avatar Louis Navarre
Parcourir les fichiers

Add color

parent d0f38f90
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -2,6 +2,10 @@ import argparse
import struct
OKGREEN = '\033[92m'
FAIL = '\033[91m'
def verify_output(file):
with open(file, "rb") as fd:
# First 4 bytes should be the number of nodes.
......@@ -17,12 +21,12 @@ def verify_output(file):
source_idx, destination_idx, _cost, path_len = struct.unpack(">llql", data)
# The node index lies within the limits.
assert source_idx >= 0 and source_idx < nb_nodes, f"The source idx does not have the correct format: {source_idx}"
assert destination_idx >= 0 and destination_idx < nb_nodes, f"The destination idx does not have the correct format: {destination_idx}"
assert source_idx >= 0 and source_idx < nb_nodes, FAIL + f"The source idx does not have the correct format: {source_idx}"
assert destination_idx >= 0 and destination_idx < nb_nodes, FAIL + f"The destination idx does not have the correct format: {destination_idx}"
# The path len can be nul if there is no path.
# The shortest path cannot contain loops.
assert path_len >= 1 and path_len <= nb_nodes, f"The path length is too long or nul: {path_len}"
assert path_len >= 1 and path_len <= nb_nodes, FAIL + f"The path length is too long or nul: {path_len}"
if path_len > 0:
for i in range(path_len):
......@@ -30,20 +34,20 @@ def verify_output(file):
hop_idx, = struct.unpack(">l", data)
# Same... the node index lies within the limits.
assert hop_idx >= 0 and hop_idx < nb_nodes, f"A hop of the path does not have the correct format {hop_idx}"
assert hop_idx >= 0 and hop_idx < nb_nodes, FAIL + f"A hop of the path does not have the correct format {hop_idx}"
# The first node should be the source.
if i == 0:
assert hop_idx == source_idx, f"The first node of the path is not the source: {hop_idx} (and source is {source_idx})"
assert hop_idx == source_idx, FAIL + f"The first node of the path is not the source: {hop_idx} (and source is {source_idx})"
# The last node should be the destination.
if i == path_len - 1:
assert hop_idx == destination_idx, f"The first node of the path is not the destination: {hop_idx} (and destination is {destination_idx})"
assert hop_idx == destination_idx, FAIL + f"The first node of the path is not the destination: {hop_idx} (and destination is {destination_idx})"
# The file does not contain anymore bytes
assert fd.read() == b"", "The file is not empty"
assert fd.read() == b"", FAIL + "The file is not empty"
print("The file has the correct format!\nThis does not mean that it solves the shortest path problem, but at least it contains readable information...")
print(OKGREEN + "The file has the correct format!\nThis does not mean that it solves the shortest path problem, but at least it contains readable information...")
if __name__ == "__main__":
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter