Created
December 23, 2020 15:30
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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