-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.py
114 lines (87 loc) · 3.72 KB
/
tester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import sys
import os
from colorama import Fore, Back, Style
def mostra_errados(errados):
os.system('clear')
print()
print("TESTES ERRADOS:")
for erro in errados:
print(f"teste {erro[0]}:")
print("===========================================================================")
print("=========== Resultado obtido: ================")
print(erro[1])
print("========== Resultado esperado: ===============")
print(erro[2])
print()
def teste_auto(absolute_path, submission_path, lab, num_testes):
errados = []
for i in range(1, num_testes+1):
test_path = os.path.join(absolute_path, f"{lab}/testes/{i}")
result = os.popen(f"python3 {submission_path} < {test_path}.in").read()
expected = os.popen(f"cat {test_path}.out").read()
if result == expected:
print(Fore.GREEN + f"teste {i}: Correto")
else:
errados.append((i, result, expected))
print(Fore.RED + f"teste {i}: Incorreto")
return errados
def teste_semimanual(absolute_path, submission_path, lab, num_testes):
errados = []
for i in range(1, num_testes+1):
os.system('clear')
test_path = os.path.join(absolute_path, f"{lab}/testes/{i}")
result = os.popen(f"python3 {submission_path} < {test_path}.in").read()
expected = os.popen(f"cat {test_path}.out").read()
print(f"teste {i}:")
print("=========== Resultado obtido: ================")
print(result)
print("========== Resultado esperado: ===============")
print(expected)
print()
avaliacao = input("Vc acha que ta certo(s/n)? ")[0].lower()
if avaliacao != 's':
errados.append((i, result, expected))
return errados
def teste_manual(absolute_path, submission_path, lab, num_testes):
errados = []
for i in range(1, num_testes+1):
os.system('clear')
test_path = os.path.join(absolute_path, f"{lab}/testes/{i}")
expected_input = os.popen(f"cat {test_path}.in").read()
print(f"Anote a entrada padrão desse teste (teste{i})")
print("Digite a entrada adaptada abaixo:")
print(expected_input)
result = os.popen(f"python3 {submission_path}").read()
expected = os.popen(f"cat {test_path}.out").read()
print(f"teste {i}:")
print("=========== Resultado obtido: ================")
print(result)
print("========== Resultado esperado: ===============")
print(expected)
print()
avaliacao = input("Vc acha que ta certo(s/n)? ")[0].lower()
if avaliacao != 's':
errados.append((i, result, expected))
return errados
def main():
os.system('clear')
absolute_path = os.path.dirname(__file__)
lab = sys.argv[1]
nome = sys.argv[2]
submission_path = os.path.join(absolute_path, f"{lab}/submissoes/{nome}")
num_testes = len(os.listdir(os.path.join(absolute_path, f"{lab}/testes/"))) // 2
if len(sys.argv) == 3 or sys.argv[3] == "auto":
errados = teste_auto(absolute_path, submission_path, lab, num_testes)
elif sys.argv[3] == "semi":
errados = teste_semimanual(absolute_path, submission_path, lab, num_testes)
elif sys.argv[3] == "manual":
errados = teste_manual(absolute_path, submission_path, lab, num_testes)
else:
print(Fore.RED + "Esse modo de correção não existe!")
print(Style.RESET_ALL)
sys.exit()
print(Style.RESET_ALL)
if len(errados) > 0:
mostra_errados(errados)
print(f"nota: {num_testes-len(errados)}/{num_testes}")
main()