7
7
def usage ():
8
8
s = "Options: \n "
9
9
s += "-d : compile in Debug mode"
10
- s += "-p : test python"
10
+ s += "\n -p : test python"
11
11
print (s )
12
12
13
13
def colorCode (q ):
14
- return [ "\\ 033[1; 41m%s\\ 033[0m" , "\\ 033[1; 31m%s\\ 033[0m" , "%s" , "\\ 033[1; 32m%s\ \ 033[0m" ][q + 2 ]
14
+ return [ "\033 [41m%s\033 [0m" , "\033 [31m%s\033 [0m" , "%s" , "\033 [32m%s\033 [0m" ][q + 2 ]
15
15
16
16
def colorTestResult (r ):
17
- q = {'+' : 1 , '?' :0 }
17
+ q = {'+' : 1 , '?' :0 , False : - 1 , True : 1 }
18
18
return colorCode ( q [r ] if r in q else - 1 ) % r
19
19
20
20
def prettyStr (x ):
@@ -28,9 +28,9 @@ def prettyStr(x):
28
28
def tc_equal (expected , received ):
29
29
try :
30
30
_t = type (expected )
31
- print (_t , type (received ))
31
+ # print(_t, type(received))
32
32
received = _t (received )
33
- print (_t )
33
+ # print(_t)
34
34
if _t == list or _t == tuple :
35
35
print ("checking list or tuple" )
36
36
if len (expected ) != len (received ): return False
@@ -52,26 +52,49 @@ def tc_equal(expected, received):
52
52
except :
53
53
return False
54
54
55
-
56
- def do_test ():
57
- in_files = glob .glob ("input*" )
58
- out_files = glob .glob ("output*" )
55
+ def do_test (exc_str ):
56
+ in_files = sorted (glob .glob ("input*" ))
57
+ out_files = sorted (glob .glob ("output*" ))
59
58
print (in_files , out_files )
60
59
60
+ retlist = []
61
61
for inf , outf in zip (in_files , out_files ):
62
+ print ("" )
63
+ print ("=" * 10 )
64
+ print ("=" * 10 )
62
65
print (inf , outf )
63
66
with open (inf ) as f :
64
- p = subprocess .Popen ("python myprog.py" , stdout = subprocess .PIPE , stdin = f )
67
+ input_content = f .read ()
68
+ f .seek (0 )
69
+ p = subprocess .Popen (exc_str , stdout = subprocess .PIPE , stdin = f , shell = True )
65
70
recv = p .stdout .read ()
66
71
67
72
with open (outf ) as of :
68
- s = of .read ()
69
- print (s )
70
- print (recv )
71
- print (s == recv )
72
- print tc_equal (s , recv )
73
+ correct_answer = of .read ()
74
+ print ("Input" )
75
+ print (prettyStr (input_content .rstrip ()))
76
+ print ("Expected:" )
77
+ print (prettyStr (correct_answer .rstrip ()))
78
+ print ("-" * 10 )
79
+ print ("Received:" )
80
+ print (prettyStr (recv .rstrip ()))
81
+ ret_comp = tc_equal (correct_answer , recv )
82
+
83
+ print ("Success: " + colorTestResult (ret_comp ))
84
+ retlist .append (colorTestResult ( "+" if ret_comp else "-" ))
85
+
86
+ print ("\n \n " + "=" * 20 + "\n Summary: " )
87
+ print (" " .join (retlist ))
88
+
73
89
74
90
91
+ # print("Successful? " + colorTestResult(tc_equal(correct_answer, recv)))
92
+
93
+ def compile_cpp (DBG ):
94
+ exc_str = 'g++ -std=c++11 ' + DBG + ' -Wall A.cc -o A.exe'
95
+ print (exc_str )
96
+ subprocess .call (exc_str , shell = True )
97
+
75
98
def main ():
76
99
DBG = "" ;
77
100
use_py = False
@@ -90,10 +113,15 @@ def main():
90
113
use_py = True
91
114
92
115
print (DBG , use_py )
116
+ if (not use_py ):
117
+ compile_cpp (DBG )
118
+ exc_str = './A.exe'
119
+ else :
120
+ exc_str = "python A.py"
93
121
94
- test_python ( )
122
+ do_test ( exc_str )
95
123
96
124
97
125
if __name__ == '__main__' :
98
- # main()
99
- do_test ()
126
+ main ()
127
+ # do_test()
0 commit comments