-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
78 lines (69 loc) · 3.17 KB
/
test.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
import operator
import os
import sys
from utils import get_exe_output, remove_space
from colorama import init, Fore
init(autoreset=True)
def get_test_names(test_set):
return os.listdir(test_set)
def unit(dir_name, test_set):
ncases = 0
npassed = 0
for test in get_test_names(test_set):
ncases += 1
testfile_name = os.path.join(test_set, test, "testfile.txt")
output_name = os.path.join(test_set, test, "output.txt")
lhs_out = get_exe_output(dir_name, testfile_name, "error.txt")
rhs_out = remove_space(open(output_name).readlines())
if lhs_out[0] == rhs_out[0]:
is_correct = True
for line in rhs_out:
# print(line)
if line not in lhs_out:
is_correct = False
if is_correct:
# correct
print(Fore.GREEN + "passed: {}".format(test))
continue
# error
print(Fore.LIGHTRED_EX + "failed: {}".format(test))
if lhs_out[0] != rhs_out[0]:
print(Fore.LIGHTRED_EX + "first line error: expected '{}' while found '{}'".format(rhs_out[0], lhs_out[0]))
continue
for line in rhs_out:
if line not in lhs_out:
print(Fore.LIGHTRED_EX + "could not find '{}'".format(line))
# .format("'{}'".format(lhs_out[i]), "'{}'".format(rhs_out[i]), i + 1))
# length = min(len(lhs_out), len(rhs_out))
# for i in range(length):
# if lhs_out[i] != rhs_out[i]:
# print(Fore.LIGHTRED_EX + "found {} while expected '{}' at line {}"
# .format("'{}'".format(lhs_out[i]), "'{}'".format(rhs_out[i]), i + 1))
# exit(-1)
# if len(lhs_out) > len(rhs_out):
# print(Fore.LIGHTRED_EX + "found {} while expected {} at line {}"
# .format("'{}'".format(lhs_out[length]), "NOTHING", length + 1))
# else:
# print(Fore.LIGHTRED_EX + "found {} while expected {} at line {}"
# .format("NOTHING", "'{}'".format(rhs_out[length]), length + 1))
# exit(-1)
# if operator.eq(lhs_out, rhs_out):
# print(Fore.GREEN + "passed: {}".format(test))
# npassed += 1
# else:
# print(Fore.LIGHTRED_EX + "failed: {}".format(test))
# length = min(len(lhs_out), len(rhs_out))
# for i in range(length):
# if lhs_out[i] != rhs_out[i]:
# print(Fore.LIGHTRED_EX + "found {} while expected '{}' at line {}"
# .format("'{}'".format(lhs_out[i]), "'{}'".format(rhs_out[i]), i+1))
# exit(-1)
# if len(lhs_out) > len(rhs_out):
# print(Fore.LIGHTRED_EX + "found {} while expected {} at line {}"
# .format("'{}'".format(lhs_out[length]), "NOTHING", length + 1))
# else:
# print(Fore.LIGHTRED_EX + "found {} while expected {} at line {}"
# .format("NOTHING", "'{}'".format(rhs_out[length]), length + 1))
# exit(-1)
if __name__ == "__main__":
unit(sys.argv[1], sys.argv[2])