This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
69 lines (50 loc) · 1.97 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
import subprocess
import os
def compile_test(test_folder_path):
print("Compiling Test: ", test_folder_path)
subprocess.check_output(['g++','-o',test_folder_path+'test',test_folder_path+'test.cpp'])
subprocess.check_call([test_folder_path+'test.exe'])
def get_tests():
tests_list = os.listdir('tests/')
return tests_list
def print_detail_difference(file_1_line, file_2_line, line_no):
if file_1_line == '':
print("@", "Line-%d" % line_no, file_1_line)
else:
print("@-", "Line-%d" % line_no, file_1_line)
if file_2_line == '':
print("#", "Line-%d" % line_no, file_2_line)
else:
print("#+", "Line-%d" % line_no, file_2_line)
def run_single_test(test_folder_path):
output_filepath = test_folder_path+'output.txt'
expected_output = test_folder_path+'expected_output.txt'
file_1 = open(output_filepath, 'r')
file_2 = open(expected_output, 'r')
file_1_line = file_1.readline()
file_2_line = file_2.readline()
line_no = 1
with open(output_filepath) as file1:
with open(expected_output) as file2:
same = set(file1).intersection(file2)
test_result = False
while file_1_line != '' or file_2_line != '':
file_1_line = file_1_line.rstrip()
file_2_line = file_2_line.rstrip()
if file_1_line != file_2_line:
print_detail_difference(file_1_line, file_2_line, line_no)
test_result = True
file_1_line = file_1.readline()
file_2_line = file_2.readline()
line_no += 1
if test_result == True:
print("Test Failed: "+test_folder_path)
file_1.close()
file_2.close()
def run_test():
tests_list = get_tests()
for test in tests_list:
test_path = 'tests/'+test+'/'
compile_test(test_path)
run_single_test(test_path)
run_test()