@@ -237,14 +237,17 @@ def input_file_to_string(path, num_cases):
237
237
return inputs
238
238
239
239
@staticmethod
240
- def cleanup (num_cases ):
240
+ def cleanup (num_cases , basename , extension ):
241
241
"""
242
242
Method to clean up temporarily created files
243
243
"""
244
244
for i in xrange (num_cases ):
245
245
if os .path .isfile ('temp_output' + str (i )):
246
246
os .remove ('temp_output' + str (i ))
247
247
248
+ if extension == 'java' :
249
+ os .system ('rm ' + basename + '*.class' )
250
+
248
251
@staticmethod
249
252
def handle_kbd_interrupt (site , contest , problem ):
250
253
"""
@@ -276,6 +279,7 @@ def run_solution(args):
276
279
277
280
extension = problem .split ('.' )[- 1 ]
278
281
problem = problem .split ('.' )[0 ]
282
+ basename = problem .split ('/' )[- 1 ]
279
283
problem_path = os .path .join (os .getcwd (), problem )
280
284
281
285
if not os .path .isfile (problem_path + '.' + extension ):
@@ -296,7 +300,7 @@ def run_solution(args):
296
300
297
301
for i in xrange (num_cases ):
298
302
status = os .system ('cat ' + os .path .join (testcases_path , 'Input' + str (
299
- i )) + ' | timeout 3s python ' + problem + '.py > temp_output' + str (i ))
303
+ i )) + ' | timeout 3s python \' ' + problem_path + '.py\' > temp_output' + str (i ))
300
304
if status == 124 :
301
305
# Time Limit Exceeded
302
306
results += [Utilities .colors ['BOLD' ] +
@@ -330,17 +334,18 @@ def run_solution(args):
330
334
results += [Utilities .colors ['BOLD' ] +
331
335
Utilities .colors ['RED' ] + 'RTE' + Utilities .colors ['ENDC' ]]
332
336
333
- elif extension == ' cpp' or extension == 'c' :
337
+ elif extension in [ 'c' , ' cpp', 'java' ] :
334
338
335
- compiler = {'c' : 'gcc' , 'cpp' : 'g++' }[extension ]
339
+ compiler = {'c' : 'gcc' , 'cpp' : 'g++' , 'java' : 'javac -d .' }[extension ]
340
+ execute_command = {'c' : './a.out' , 'cpp' : './a.out' , 'java' : 'java ' + basename }[extension ]
336
341
compile_status = os .system (
337
- compiler + ' ' + problem_path + '.cpp ' )
342
+ compiler + ' \' ' + problem_path + '.' + extension + ' \' ' )
338
343
339
344
if compile_status == 0 :
340
345
341
346
# Compiled successfully
342
347
for i in xrange (num_cases ):
343
- status = os .system ('timeout 2s ./a.out < ' + os .path .join (
348
+ status = os .system ('timeout 2s ' + execute_command + ' < ' + os .path .join (
344
349
testcases_path , 'Input' + str (i )) + ' > temp_output' + str (i ))
345
350
if status == 124 :
346
351
# Time Limit Exceeded
@@ -382,7 +387,7 @@ def run_solution(args):
382
387
sys .exit (0 )
383
388
384
389
else :
385
- print 'Supports only C, C++ and Python as of now. Support for Java coming soon .'
390
+ print 'Supports only C, C++, Python and Java as of now.'
386
391
sys .exit (0 )
387
392
388
393
from terminaltables import AsciiTable
@@ -409,7 +414,7 @@ def run_solution(args):
409
414
print table .table
410
415
411
416
# Clean up temporary files
412
- Utilities .cleanup (num_cases )
417
+ Utilities .cleanup (num_cases , basename , extension )
413
418
414
419
else :
415
420
print 'Test cases not found locally...'
0 commit comments