Skip to content

Commit 9d6aa58

Browse files
committed
Add support for Java
1 parent 74b42c9 commit 9d6aa58

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ A command line tool to run your code against sample test cases. Without leaving
1515
+ Spoj
1616
+ Hackerrank
1717

18+
#### Supported Languages
19+
+ C
20+
+ C++
21+
+ Python
22+
+ Java
23+
1824
#### Installation
1925
##### Build from source
2026
+ `git clone https://github.com/coderick14/ACedIt`

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ Supported sites
2828
- Spoj
2929
- Hackerrank
3030

31+
Supported languages
32+
^^^^^^^^^^^^^^^^^^^
33+
34+
- C
35+
- C++
36+
- Python
37+
- Java
38+
3139
Installation
3240
^^^^^^^^^^^^
3341

acedit/util.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,17 @@ def input_file_to_string(path, num_cases):
237237
return inputs
238238

239239
@staticmethod
240-
def cleanup(num_cases):
240+
def cleanup(num_cases, basename, extension):
241241
"""
242242
Method to clean up temporarily created files
243243
"""
244244
for i in xrange(num_cases):
245245
if os.path.isfile('temp_output' + str(i)):
246246
os.remove('temp_output' + str(i))
247247

248+
if extension == 'java':
249+
os.system('rm ' + basename + '*.class')
250+
248251
@staticmethod
249252
def handle_kbd_interrupt(site, contest, problem):
250253
"""
@@ -276,6 +279,7 @@ def run_solution(args):
276279

277280
extension = problem.split('.')[-1]
278281
problem = problem.split('.')[0]
282+
basename = problem.split('/')[-1]
279283
problem_path = os.path.join(os.getcwd(), problem)
280284

281285
if not os.path.isfile(problem_path + '.' + extension):
@@ -296,7 +300,7 @@ def run_solution(args):
296300

297301
for i in xrange(num_cases):
298302
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))
300304
if status == 124:
301305
# Time Limit Exceeded
302306
results += [Utilities.colors['BOLD'] +
@@ -330,17 +334,18 @@ def run_solution(args):
330334
results += [Utilities.colors['BOLD'] +
331335
Utilities.colors['RED'] + 'RTE' + Utilities.colors['ENDC']]
332336

333-
elif extension == 'cpp' or extension == 'c':
337+
elif extension in ['c', 'cpp', 'java']:
334338

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]
336341
compile_status = os.system(
337-
compiler + ' ' + problem_path + '.cpp')
342+
compiler + ' \'' + problem_path + '.' + extension + '\'')
338343

339344
if compile_status == 0:
340345

341346
# Compiled successfully
342347
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(
344349
testcases_path, 'Input' + str(i)) + ' > temp_output' + str(i))
345350
if status == 124:
346351
# Time Limit Exceeded
@@ -382,7 +387,7 @@ def run_solution(args):
382387
sys.exit(0)
383388

384389
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.'
386391
sys.exit(0)
387392

388393
from terminaltables import AsciiTable
@@ -409,7 +414,7 @@ def run_solution(args):
409414
print table.table
410415

411416
# Clean up temporary files
412-
Utilities.cleanup(num_cases)
417+
Utilities.cleanup(num_cases, basename, extension)
413418

414419
else:
415420
print 'Test cases not found locally...'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
packages=['acedit'],
2424

25-
version='1.0.5',
25+
version='1.1.0',
2626

2727
description='Download and test against sample test cases from any competitive programming website',
2828

0 commit comments

Comments
 (0)