Skip to content

Instantly share code, notes, and snippets.

@felipecustodio
Created December 23, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipecustodio/d603af8b71ec0735542f564a59f42d05 to your computer and use it in GitHub Desktop.
Save felipecustodio/d603af8b71ec0735542f564a59f42d05 to your computer and use it in GitHub Desktop.
Run all test cases for a college assignment, usually provided as .in and .out files.
import glob
import sys
import io
files = glob.glob('./*.in')
for f in files:
test_case = f.split('.in')[0].replace('.\\', '')
sys.stdin = open(f, "r")
print(f"\n*** Caso de Teste {test_case} ***\n")
stdout = sys.stdout
output = io.StringIO()
sys.stdout = output
main()
output = output.getvalue()
with open(f"{test_case}.out", "r") as fp:
expected_output = fp.read()
sys.stdout = stdout
output = output.splitlines()
expected_output = expected_output.splitlines()
for i, (output_line, expected_output_line) in enumerate(zip(output, expected_output)):
if (output_line == expected_output_line):
valid = "🟢"
else:
valid = "🔴"
print(f"Caso {i+1}\tSaída: {output_line}\tSaída Esperada: {expected_output_line}\t{valid}")
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment