diff --git a/verify_output.py b/verify_output.py index 57222ff4c6953bce81c0fed0bcb1467368c781ab..aeaea0a254f6f15fb36921bee51826762cf269aa 100644 --- a/verify_output.py +++ b/verify_output.py @@ -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__":