assertsource_idx>=0andsource_idx<nb_nodes,f"The source idx does not have the correct format: {source_idx}"
assertdestination_idx>=0anddestination_idx<nb_nodes,f"The destination idx does not have the correct format: {destination_idx}"
assertsource_idx>=0andsource_idx<nb_nodes,FAIL+f"The source idx does not have the correct format: {source_idx}"
assertdestination_idx>=0anddestination_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.
assertpath_len>=1andpath_len<=nb_nodes,f"The path length is too long or nul: {path_len}"
assertpath_len>=1andpath_len<=nb_nodes,FAIL+f"The path length is too long or nul: {path_len}"
ifpath_len>0:
foriinrange(path_len):
...
...
@@ -30,20 +34,20 @@ def verify_output(file):
hop_idx,=struct.unpack(">l",data)
# Same... the node index lies within the limits.
asserthop_idx>=0andhop_idx<nb_nodes,f"A hop of the path does not have the correct format {hop_idx}"
asserthop_idx>=0andhop_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.
ifi==0:
asserthop_idx==source_idx,f"The first node of the path is not the source: {hop_idx} (and source is {source_idx})"
asserthop_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.
ifi==path_len-1:
asserthop_idx==destination_idx,f"The first node of the path is not the destination: {hop_idx} (and destination is {destination_idx})"
asserthop_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
assertfd.read()==b"","The file is not empty"
assertfd.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...")